TemporaryConversation

临时对话

Constructor

new TemporaryConversation()

无法直接实例化,请使用 IMClient#createTemporaryConversation 创建新的临时对话。
Since:
  • 4.0.0

Extends

Members

expired :Boolean

对话是否已失效

expiredAt :Date

对话失效时间

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:

unreadMessagesCount :Number

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

unreadMessagesMentioned :Boolean

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

Methods

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 }
});

emit(event) → {Boolean}

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

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

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

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

移除 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:
this - self.
Inherited From:

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

给指定的 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:
this - self.
Inherited From:

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

为 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:
this - self.
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:

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:

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> - 发送的消息
Overrides:

toFullJSON() → {Object}

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

toJSON() → {Object}

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

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 Array.<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 Description
message AVMessage 被撤回的消息
Inherited From:

MESSAGE_UPDATE

消息被修改
Parameters:
Name Type Description
message AVMessage 被修改的消息
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: