Conversation

Conversation

new Conversation()

Source:
无法直接实例化,请使用 IMClient#createConversation 创建新的对话

Extends

Members

attributes :Object

Source:
Deprecated:
对话额外属性,对应 _Conversation 表中的 attr
Type:
  • Object

createdAt :Date

Source:
对话创建时间
Type:
  • Date

creator :String

Source:
对话创建者
Type:
  • String

id :String

Source:
对话 id,对应 _Conversation 表中的 objectId
Type:
  • String

(nullable) lastDeliveredAt :Date

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

(nullable) lastMessage :Message

Source:
最后一条消息
Type:

(nullable) lastMessageAt :Date

Source:
最后一条消息时间
Type:
  • Date

(nullable) lastReadAt :Date

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

members :Array.<String>

Source:
参与该对话的用户列表
Type:
  • Array.<String>

muted :Boolean

Source:
当前用户静音该对话标记
Type:
  • Boolean

(nullable) mutedMembers :Array.<String>

Source:
对该对话设置了静音的用户列表
Type:
  • Array.<String>

name :String

Source:
对话名字,对应 _Conversation 表中的 name
Type:
  • String

system :Boolean

Source:
Since:
  • 3.3
系统对话标记
Type:
  • Boolean

transient :Boolean

Source:
暂态对话标记
Type:
  • Boolean

unreadMessagesCount :Number

Source:
当前用户在该对话的未读消息数
Type:
  • Number

updatedAt :Date

Source:
对话更新时间
Type:
  • Date

Methods

add(clientIds) → {Promise.<Conversation>}

Source:
增加成员
Parameters:
Name Type Description
clientIds String | Array.<String> 新增成员 client id
Returns:
self
Type
Promise.<Conversation>

count() → {Promise.<Number>}

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

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

Source:
获取消息翻页迭代器
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 }
});
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:
AsyncIterator,调用其 next 方法返回获取下一页消息的 Promise
Type
AsyncIterater.<Promise.<IteratorResult.<Array.<Message>>>>

emit(event) → {Boolean}

Source:
Inherited From:
依次调用 event 事件的监听器列表中的 listener。
Parameters:
Name Type Attributes Description
event String | Symbol The event name.
...arg Mixed <optional>
payloads
Returns:
`true` if the event had listeners, else `false`.
Type
Boolean

fetch() → {Promise.<Conversation>}

Source:
从服务器更新对话的属性
Returns:
self
Type
Promise.<Conversation>

fetchReceiptTimestamps() → {Promise.<Conversation>}

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

get(key) → {Any}

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

join() → {Promise.<Conversation>}

Source:
(当前用户)加入该对话
Returns:
self
Type
Promise.<Conversation>

markAsRead() → {Promise.<Conversation>}

Source:
Deprecated:
将该会话标记为已读
Returns:
self
Type
Promise.<Conversation>

mute() → {Promise.<Conversation>}

Source:
静音,客户端拒绝收到服务器端的离线推送通知
Returns:
self
Type
Promise.<Conversation>

off(event, listeneropt, contextopt, onceopt) → {EventEmitter}

Source:
Inherited From:
移除 event 事件的监听器列表中的 listener。
Parameters:
Name Type Attributes Description
event String | Symbol The event name.
listener function <optional>
Only remove the listeners that match this function.
context Mixed <optional>
Only remove the listeners that have this context.
once Boolean <optional>
Only remove one-time listeners.
Returns:
self.
Type
EventEmitter

on(event, listener, contextopt) → {EventEmitter}

Source:
Inherited From:
给指定的 event 添加监听器,并将该监听器置于监听器列表的末位。该方法不会检查是否已经添加过该监听器。重复添加相同的 event 和 listener 会导致该事件和监听器被重复触发。
Parameters:
Name Type Attributes Default Description
event String | Symbol The event name.
listener function The listener function.
context Mixed <optional>
this The context to invoke the listener with.
Returns:
self.
Type
EventEmitter

once(event, listener, contextopt) → {EventEmitter}

Source:
Inherited From:
为 event 事件添加一个一次性的监听器,该事件第一次触发之后就会被注销。
Parameters:
Name Type Attributes Default Description
event String | Symbol The event name.
listener function The listener function.
context Mixed <optional>
this The context to invoke the listener with.
Returns:
self.
Type
EventEmitter

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

Source:
查询消息记录 如果仅需实现消息记录翻页查询需求,建议使用 Conversation#createMessagesIterator
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
beforeTime Date <optional>
限制查询结果为小于这个该时间之前的消息,不传则为当前时间
beforeMessageId String <optional>
限制查询结果为该消息之前的消息,需要与 beforeTime 同时使用,为防止某时刻有重复消息
afterTime Date <optional>
限制查询结果为大于这个该时间之前的消息
afterMessageId String <optional>
限制查询结果为该消息之后的消息,需要与 afterTime 同时使用,为防止某时刻有重复消息
limit Number <optional>
限制查询结果的数量,目前服务端默认为 20
Returns:
消息列表
Type
Promise.<Array.<Message>>

quit() → {Promise.<Conversation>}

Source:
(当前用户)退出该对话
Returns:
self
Type
Promise.<Conversation>

read() → {Promise.<Conversation>}

Source:
将该会话标记为已读
Returns:
self
Type
Promise.<Conversation>

recall(message)

Source:
撤回已发送的消息
Parameters:
Name Type Description
message AVMessage 要撤回的消息,该消息必须是由当前用户发送的。也可以提供一个包含消息 {id, timestamp} 的对象

remove(clientIds) → {Promise.<Conversation>}

Source:
剔除成员
Parameters:
Name Type Description
clientIds String | Array.<String> 成员 client id
Returns:
self
Type
Promise.<Conversation>

save() → {Promise.<Conversation>}

Source:
保存当前对话的属性至服务器
Returns:
self
Type
Promise.<Conversation>

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

Source:
发送消息
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:
发送的消息
Type
Promise.<Message>

set(key, value) → {Conversation}

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

setAttribute(key, value) → {Conversation}

Source:
Deprecated:
设置对话额外属性
Parameters:
Name Type Description
key String
value Any
Returns:
self
Type
Conversation

setAttributes(map, assignopt) → {Conversation}

Source:
Deprecated:
设置对话额外属性
Parameters:
Name Type Attributes Default Description
map Object key-value 对
assign Boolean <optional>
false 使用 Object.assign 更新属性,而不是替换整个 attributes
Returns:
self
Type
Conversation

setName(value) → {Conversation}

Source:
Deprecated:
设置对话名字
Parameters:
Name Type Description
value String
Returns:
self
Type
Conversation

unmute() → {Promise.<Conversation>}

Source:
取消静音
Returns:
self
Type
Promise.<Conversation>

update(message, newMessage)

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

Events

invited

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

kicked

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

lastdeliveredatupdate

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

lastreadatupdate

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

membersjoined

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

membersleft

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

message

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

messagerecall

Source:
消息被撤回
Parameters:
Name Type Description
message AVMessage 被撤回的消息

messageupdate

Source:
消息被修改
Parameters:
Name Type Description
message AVMessage 被修改的消息

receipt

Source:
Since:
  • 3.2.0
Deprecated:
消息已送达。只有在发送时设置了需要回执的情况下才会收到送达回执,该回执并不代表用户已读。
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
message Message 送达的消息