ChatRoom

聊天室。 无法直接实例化,请使用 IMClient#createChatRoom 创建新的聊天室。

Constructor

new ChatRoom()

Since:
  • 4.0.0

Extends

Members

createdAt :Date

对话创建时间
Inherited From:

creator :String

对话创建者
Inherited From:

id :String

对话 id,对应 _Conversation 表中的 objectId
Inherited From:

nullable lastDeliveredAt :Date

最后消息送达时间,常用来实现消息的「已送达」标记,可通过 Conversation#fetchReceiptTimestamps 获取或更新该属性
Since:
  • 3.4.0
Inherited From:

nullable lastMessage :Message

最后一条消息
Inherited From:

nullable lastMessageAt :Date

最后一条消息时间
Inherited From:

nullable lastReadAt :Date

最后消息被阅读时间,常用来实现发送消息的「已读」标记,可通过 Conversation#fetchReceiptTimestamps 获取或更新该属性
Since:
  • 3.4.0
Inherited From:

members :Array.<String>

参与该对话的用户列表
Inherited From:

muted :Boolean

当前用户静音该对话标记
Inherited From:

nullable mutedMembers :Array.<String>

对该对话设置了静音的用户列表
Inherited From:

name :String

对话名字,对应 _Conversation 表中的 name
Inherited From:

system :Boolean

系统对话标记
Since:
  • 3.3.0
Inherited From:

transient :Boolean

暂态对话标记
Inherited From:

unreadMessagesCount :Number

当前用户在该对话的未读消息数
Inherited From:

unreadMessagesMentioned :Boolean

当前用户是否在该对话的未读消息中被提及
Since:
  • 4.0.0
Inherited From:

updatedAt :Date

对话更新时间
Inherited From:

Methods

add(clientIds) → {Promise.<PartiallySuccess>} [async]

增加成员
Parameters:
Name Type Description
clientIds String | Array.<String> 新增成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

blockMembers(clientIds) → {Promise.<PartiallySuccess>} [async]

将用户加入该对话黑名单
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

count() → {Promise.<Number>} [async]

获取对话人数,或暂态对话的在线人数
Returns:
Promise.<Number>
Inherited From:

createMessagesIterator(optionsopt) → {AsyncIterater.<Promise.<IteratorResult.<Array.<Message>>>>}

获取消息翻页迭代器
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
beforeTime Date <optional>
限制起始查询结果为小于该时间之前的消息,不传则为当前时间
beforeMessageId String <optional>
限制起始查询结果为该消息之前的消息,需要与 beforeTime 同时使用,为防止某时刻有重复消息
limit Number <optional>
限制每页查询结果的数量,目前服务端默认为 20
Returns:
AsyncIterater.<Promise.<IteratorResult.<Array.<Message>>>> - AsyncIterator,调用其 next 方法返回获取下一页消息的 Promise
Inherited From:
Example
var messageIterator = conversation.createMessagesIterator({ limit: 10 });
messageIterator.next().then(function(result) {
  // result: {
  //   value: [message1, ..., message10],
  //   done: false,
  // }
});
messageIterator.next().then(function(result) {
  // result: {
  //   value: [message11, ..., message20],
  //   done: false,
  // }
});
messageIterator.next().then(function(result) {
  // No more messages
  // result: { value: [], done: true }
});

fetch() → {Promise.<this>} [async]

从服务器更新对话的属性
Returns:
Promise.<this> - self
Inherited From:

fetchReceiptTimestamps() → {Promise.<this>} [async]

更新对话的最新回执时间戳(lastDeliveredAt、lastReadAt)
Returns:
Promise.<this> - this
Since:
  • 3.4.0
Inherited From:

get(key) → {Any}

获取对话的自定义属性
Parameters:
Name Type Description
key String key 属性的键名,'x' 对应 Conversation 表中的 x 列
Returns:
Any - 属性的值
Since:
  • 3.2.0
Inherited From:

join() → {Promise.<this>} [async]

(当前用户)加入该对话
Returns:
Promise.<this> - self
Inherited From:

mute() → {Promise.<this>} [async]

静音,客户端拒绝收到服务器端的离线推送通知
Returns:
Promise.<this> - self
Inherited From:

muteMembers(clientIds) → {Promise.<PartiallySuccess>} [async]

在该对话中禁言成员
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

queryBlockedMembers(optionsopt) → {PagedResults.<string>} [async]

查询该对话黑名单
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
limit Number <optional>
返回的成员数量,服务器默认值 10
next String <optional>
从指定 next 开始查询,与 limit 一起使用可以完成翻页
Returns:
PagedResults.<string> - 查询结果。其中的 cureser 存在表示还有更多结果。
Inherited From:

queryMessages(optionsopt) → {Promise.<Array.<Message>>} [async]

查询消息记录 如果仅需实现消息向前记录翻页查询需求,建议使用 Conversation#createMessagesIterator。 不论何种方向,获得的消息都是按照时间升序排列的。 startClosed 与 endClosed 用于指定查询区间的开闭。
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
limit Number <optional>
限制查询结果的数量,目前服务端默认为 20
type Number <optional>
指定查询的富媒体消息类型,不指定则查询所有消息。
direction MessageQueryDirection <optional>
查询的方向。 在不指定的情况下如果 startTime 大于 endTime,则为从新到旧查询,可以实现加载聊天记录等场景。 如果 startTime 小于 endTime,则为从旧到新查询,可以实现弹幕等场景。
startTime Date <optional>
从该时间开始查询,不传则从当前时间开始查询
startMessageId String <optional>
从该消息之前开始查询,需要与 startTime 同时使用,为防止某时刻有重复消息
startClosed Boolean <optional>
指定查询范围是否包括开始的时间点,默认不包括
endTime Date <optional>
查询到该时间为止,不传则查询最早消息为止
endMessageId String <optional>
查询到该消息为止,需要与 endTime 同时使用,为防止某时刻有重复消息
endClosed Boolean <optional>
指定查询范围是否包括结束的时间点,默认不包括
beforeTime Date <optional>
DEPRECATED: 使用 startTime 代替。限制查询结果为小于该时间之前的消息,不传则为当前时间
beforeMessageId String <optional>
DEPRECATED: 使用 startMessageId 代替。 限制查询结果为该消息之前的消息,需要与 beforeTime 同时使用,为防止某时刻有重复消息
afterTime Date <optional>
DEPRECATED: 使用 endTime 代替。限制查询结果为大于该时间之前的消息
afterMessageId String <optional>
DEPRECATED: 使用 endMessageId 代替。 限制查询结果为该消息之后的消息,需要与 afterTime 同时使用,为防止某时刻有重复消息
Returns:
Promise.<Array.<Message>> - 消息列表
Inherited From:

queryMutedMembers(optionsopt) → {PagedResults.<string>} [async]

查询该对话禁言成员列表
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
limit Number <optional>
返回的成员数量,服务器默认值 10
next String <optional>
从指定 next 开始查询,与 limit 一起使用可以完成翻页。
Returns:
PagedResults.<string> - 查询结果。其中的 cureser 存在表示还有更多结果。
Inherited From:

quit() → {Promise.<this>} [async]

(当前用户)退出该对话
Returns:
Promise.<this> - self
Inherited From:

read() → {Promise.<this>} [async]

将该会话标记为已读
Returns:
Promise.<this> - self
Inherited From:

recall(message) → {Promise.<RecalledMessage>} [async]

撤回已发送的消息
Parameters:
Name Type Description
message AVMessage 要撤回的消息,该消息必须是由当前用户发送的。也可以提供一个包含消息 {id, timestamp} 的对象
Returns:
Promise.<RecalledMessage> - 一条已撤回的消息
Inherited From:

remove(clientIds) → {Promise.<PartiallySuccess>} [async]

剔除成员
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

save() → {Promise.<this>} [async]

保存当前对话的属性至服务器
Returns:
Promise.<this> - self
Inherited From:

send(message, optionsopt) → {Promise.<Message>} [async]

发送消息
Parameters:
Name Type Attributes Description
message Message 消息,Message 及其子类的实例
options Object <optional>
since v3.3.0,发送选项
Properties
Name Type Attributes Description
transient Boolean <optional>
since v3.3.1,是否作为暂态消息发送
receipt Boolean <optional>
是否需要回执,仅在普通对话中有效
will Boolean <optional>
since v3.4.0,是否指定该消息作为「掉线消息」发送, 「掉线消息」会延迟到当前用户掉线后发送,常用来实现「下线通知」功能
priority MessagePriority <optional>
消息优先级,仅在暂态对话中有效, see: MessagePriority
pushData Object <optional>
消息对应的离线推送内容,如果消息接收方不在线,会推送指定的内容。其结构说明参见: 推送消息内容
Returns:
Promise.<Message> - 发送的消息
Inherited From:

set(key, value) → {this}

设置对话的自定义属性
Parameters:
Name Type Description
key String 属性的键名,'x' 对应 Conversation 表中的 x 列,支持使用 'x.y.z' 来修改对象的部分字段。
value Any 属性的值
Returns:
this - self
Since:
  • 3.2.0
Inherited From:
Example
// 设置对话的 color 属性
conversation.set('color', {
  text: '#000',
  background: '#DDD',
});
// 设置对话的 color.text 属性
conversation.set('color.text', '#333');

toFullJSON() → {Object}

返回 JSON 格式的对话,与 toJSON 不同的是,该对象包含了完整的信息,可以通过 IMClient#parseConversation 反序列化。
Returns:
Object - 返回值是一个 plain Object
Since:
  • 4.0.0
Inherited From:

toJSON() → {Object}

返回 JSON 格式的对话
Returns:
Object - 返回值是一个 plain Object
Since:
  • 4.0.0
Inherited From:

unblockMembers(clientIds) → {Promise.<PartiallySuccess>} [async]

将用户移出该对话黑名单
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

unmute() → {Promise.<this>} [async]

取消静音
Returns:
Promise.<this> - self
Inherited From:

unmuteMembers(clientIds) → {Promise.<PartiallySuccess>} [async]

在该对话中解除成员禁言
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
Promise.<PartiallySuccess> - 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
Inherited From:

update(message, newMessage) → {Promise.<AVMessage>} [async]

修改已发送的消息
Parameters:
Name Type Description
message AVMessage 要修改的消息,该消息必须是由当前用户发送的。也可以提供一个包含消息 {id, timestamp} 的对象
newMessage AVMessage 新的消息
Returns:
Promise.<AVMessage> - 更新后的消息
Inherited From:

Events

BLOCKED

当前用户被加入当前对话的黑名单
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
blockedBy String 该操作的发起者 id
Inherited From:

INFO_UPDATED

有对话信息被更新
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
attributes Object 被更新的属性
updatedBy String 该操作的发起者 id
Inherited From:

INVITED

当前用户被添加至当前对话
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
invitedBy String 该移除操作的发起者 id
Inherited From:

KICKED

当前用户被从当前对话中移除
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
kickedBy String 该移除操作的发起者 id
Inherited From:

LAST_DELIVERED_AT_UPDATE

最后消息送达时间更新
Since:
  • 3.4.0
Inherited From:

LAST_READ_AT_UPDATE

最后消息被阅读时间更新
Since:
  • 3.4.0
Inherited From:

MEMBER_INFO_UPDATED

有成员的对话信息被更新
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
member String 被更新对话信息的成员 id
memberInfo ConversationMumberInfo 被更新的成员对话信息
updatedBy String 该操作的发起者 id
Inherited From:

MEMBERS_BLOCKED

有成员被加入当前对话的黑名单
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 成员 id 列表
blockedBy String 该操作的发起者 id
Inherited From:

MEMBERS_JOINED

有成员被添加至当前对话
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 被添加的成员 id 列表
invitedBy String 邀请者 id
Inherited From:

MEMBERS_LEFT

有成员被从当前对话中移除
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 被移除的成员 id 列表
kickedBy String 该移除操作的发起者 id
Inherited From:

MEMBERS_MUTED

有成员在当前对话中被禁言
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 成员 id 列表
mutedBy String 该操作的发起者 id
Inherited From:

MEMBERS_UNBLOCKED

有成员被移出当前对话的黑名单
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 成员 id 列表
unblockedBy String 该操作的发起者 id
Inherited From:

MEMBERS_UNMUTED

有成员在当前对话中被解除禁言
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 成员 id 列表
unmutedBy String 该操作的发起者 id
Inherited From:

MESSAGE

当前对话收到消息
Parameters:
Name Type Description
message Message
Inherited From:

MESSAGE_RECALL

消息被撤回
Parameters:
Name Type Attributes Description
message AVMessage 被撤回的消息
reason PatchReason <optional>
撤回的原因,不存在代表是发送者主动撤回
Inherited From:

MESSAGE_UPDATE

消息被修改
Parameters:
Name Type Attributes Description
message AVMessage 被修改的消息
reason PatchReason <optional>
修改的原因,不存在代表是发送者主动修改
Inherited From:

MUTED

有成员在当前对话中被禁言
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
mutedBy String 该操作的发起者 id
Inherited From:

UNBLOCKED

当前用户被移出当前对话的黑名单
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
unblockedBy String 该操作的发起者 id
Inherited From:

UNMUTED

有成员在当前对话中被解除禁言
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
unmutedBy String 该操作的发起者 id
Inherited From: