Extends
Members
attributes :Object
- Source:
- Deprecated:
- Use conversation.get('attr'), conversation.set('attr', value) instead
对话额外属性,对应 _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
|
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:
- in favor of Conversation#read
将该会话标记为已读
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
|
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
|
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:
- Use conversation.set('attr.key', value) instead
设置对话额外属性
Parameters:
Name | Type | Description |
---|---|---|
key |
String | |
value |
Any |
Returns:
self
- Type
- Conversation
setAttributes(map, assignopt) → {Conversation}
- Source:
- Deprecated:
- Use Conversation#set instead. See https://url.leanapp.cn/DeprecateAttributes for more details.
设置对话额外属性
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:
- Use conversation.set('name', value) instead
设置对话名字
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
|
kicked
- Source:
当前用户被从当前对话中移除
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
payload |
Object |
Properties
|
lastdeliveredatupdate
- Source:
- Since:
- 3.4.0
最后消息送达时间更新
lastreadatupdate
- Source:
- Since:
- 3.4.0
最后消息被阅读时间更新
membersjoined
- Source:
有成员被添加至当前对话
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
payload |
Object |
Properties
|
membersleft
- Source:
有成员被从当前对话中移除
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
payload |
Object |
Properties
|
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
|