会话类,用于定义单聊会话、群聊会话和聊天室会话。

每类会话中包含发送和接收的消息。

关于会话名称,请根据会话类型获取: 单聊:详见 ChatUserInfoManager.fetchUserInfoById; 群聊:详见 ChatGroup.getGroupWithId; 聊天室:详见 ChatRoom.fetchChatRoomInfoFromServer。

Hierarchy

  • ChatConversation

Constructors

Properties

convId: string

会话 ID。

会话类型。

ext?: any

会话扩展信息。

isChatThread: boolean

是否是子区会话。

  • true: 是;
  • false: 否。

注意

该参数仅对群聊有效。

isPinned?: boolean

会话是否置顶:

  • true:会话置顶。
  • (默认) false:会话不置顶。
pinnedTime?: number

会话置顶 UNIX 时间戳,单位为毫秒,值 0 表示会话未置顶。

Methods

  • 删除会话的所有消息。

    该方法将缓存和数据库的消息全部删除。

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 删除本地数据库中的指定消息。

    Parameters

    • msgId: string

      要删除的消息 ID。

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 删除消息。

    Parameters

    • params: {
          endTs: number;
          startTs: number;
      }
      • endTs: number
      • startTs: number

    Returns Promise<void>

    Params

    参数组。

    • startTs: 开始的时间戳
    • endTs: 结束的时间戳

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 根据消息拉取参数配置从服务器分页获取指定会话的历史消息。

    Parameters

    Returns Promise<ChatCursorResult<ChatMessage>>

    查询到的消息列表和下次查询的 cursor。

    Params

    参数组。

    • options: 查询历史消息的参数配置类, 详见 ChatFetchMessageOptions.
    • cursor: 查询的起始游标位置。
    • pageSize: 每页期望获取的消息条数。取值范围为 [1,50]。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 获取指定会话的最新消息。

    Returns Promise<undefined | ChatMessage>

    消息实例。如果不存在返回 undefined

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 获取指定会话中最近接收到的消息。

    Returns Promise<undefined | ChatMessage>

    消息实例。如果不存在返回 undefined

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 获取会话的消息数目。

    Returns Promise<number>

    消息的数目。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 从本地数据库获取指定会话在一段时间内的消息。

    Parameters

    • startTime: number

      搜索起始时间戳。单位为毫秒。

    • endTime: number

      搜索结束时间戳。单位为毫秒。

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      消息查询方向,详见 ChatSearchDirection

      • (默认)ChatSearchDirection.Up:按消息中的时间戳 (sortMessageByServerTime) 的倒序加载。
      • ChatSearchDirection.Down:按消息中的时间戳 (sortMessageByServerTime) 的顺序加载。
    • count: number = 20

      获取的最大消息数量。取值范围为 [1,400]。

    Returns Promise<ChatMessage[]>

    消息列表。若未获取到消息,返回空列表。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 从本地数据库获取指定会话中一定数量的消息。

    获取到的消息也会放入到内存中。

    Parameters

    • startMsgId: string

      开始消息 ID。若该参数设为空或 null,SDK 按服务器接收消息时间的倒序加载消息。

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      消息查询方向,详见 ChatSearchDirection

      • (默认)ChatSearchDirection.Up:按消息中的时间戳 (SortMessageByServerTime) 的倒序加载。
      • ChatSearchDirection.Down:按消息中的时间戳 (SortMessageByServerTime) 的顺序加载。
    • loadCount: number = 20

      获取的最大消息数量。取值范围为 [1,50]。

    Returns Promise<ChatMessage[]>

    消息列表。若未获取到消息,返回空列表。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 从本地数据库获取会话中的指定用户发送的一定数量的特定消息。

    Parameters

    • keywords: string

      查询的关键字。

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      消息查询方向,详见 ChatSearchDirection

      • (默认)ChatSearchDirection.Up:按消息中的时间戳 (SortMessageByServerTime) 的倒序加载。
      • ChatSearchDirection.Down:按消息中的时间戳 (SortMessageByServerTime) 的顺序加载。
    • timestamp: number = -1

      搜索的开始时间戳。单位为毫秒。

    • count: number = 20

      获取的最大消息数量。取值范围为 [1,50]。

    • Optional sender: string

      消息发送者,该参数也可以在搜索群组消息和聊天室消息时使用。

    Returns Promise<ChatMessage[]>

    消息列表。若未获取到消息,返回空列表。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 从本地数据库获取会话中的指定用户发送的某些类型的消息。

    Parameters

    • msgType: ChatMessageType

      消息类型。详见 ChatMessageType

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      消息加载方向。默认按消息中的时间戳(SortMessageByServerTime)的倒序加载,详见 ChatSearchDirection

    • timestamp: number = -1

      搜索的起始时间戳。单位为毫秒。

    • count: number = 20

      获取的最大消息数量。

    • Optional sender: string

      消息发送方。该参数也可以在搜索群组消息或聊天室消息时使用。

    Returns Promise<ChatMessage[]>

    消息列表。若未获取到,返回空列表。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 获取会话的未读消息数量。

    Returns Promise<number>

    会话的未读消息数量。

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 标记所有消息为已读。

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 标记指定消息为已读。

    Parameters

    • msgId: string

      消息 ID。

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 是否设置会话置顶。

    Parameters

    • isPinned: boolean

    Returns Promise<void>

    Throws

    如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError

  • 根据消息 ID 单向删除漫游消息

    Parameters

    • msgIds: string[]

      将要删除的消息ID列表。

    Returns Promise<void>

    Throws

    如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError

  • 根据消息 时间戳 单向删除漫游消息

    Parameters

    • timestamp: number

      UNIX 时间戳,单位为毫秒。若消息的 UNIX 时间戳小于设置的值,则会被删除。

    Returns Promise<void>

    Throws

    如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError

  • 设置指定会话的自定义扩展信息。

    Parameters

    • ext: {
          [key: string]: string | number;
      }

      会话扩展信息。

      • [key: string]: string | number

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

  • 更新本地数据库的指定消息。

    消息更新时,消息 ID 不会修改。

    消息更新后,SDK 会自动更新会话的 latestMessage 等属性。

    Parameters

    Returns Promise<void>

    Throws

    如果有方法调用的异常会在这里抛出,可以看到具体错误原因。参见 ChatError

Generated using TypeDoc