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

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

关于会话名称,请根据会话类型获取: 单聊:详见 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

  • 从服务器获取会话中顶置的消息。

    Returns Promise<ChatMessage[]>

    顶置消息列表。 如果没有获取到消息,则返回空列表。

    Throws

    异常的描述。 请参阅ChatError

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

    Returns Promise<undefined | ChatMessage>

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

    Throws

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

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

    Returns Promise<undefined | ChatMessage>

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

    Throws

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

  • 获取会话的消息数目。

    Returns Promise<number>

    消息的数目。

    Throws

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

  • 获取本地数据库中某个会话在一定时间内发送和接收的消息。

    Parameters

    • startTime: number

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

    • endTime: number

      搜索的结束 Unix 时间戳。 单位是毫秒。

    • direction: ChatSearchDirection = ChatSearchDirection.UP
    • count: number = 20

      每次检索的最大消息数。 取值范围为[1,400]。

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有开始或结束时间戳的消息)。 如果没有获取到消息,则返回空列表。

    Throws

    异常的描述。 请参阅ChatError

    Deprecated

    2024-04-17 此方法已弃用。 请改用 getMsgWithTimestamp

  • 从本地数据库中检索会话中一定数量的消息。

    注意

    获取的消息也会加入到内存中存储的会话的现有消息中。

    Parameters

    • startMsgId: string

      查询的起始消息ID。 设置该参数后,SDK按照消息搜索方向,从指定的消息开始检索消息。 如果该参数设置为空字符串,则SDK按照消息搜索方向检索消息,而忽略该参数。

      • 如果“direction”设置为“ChatSearchDirection.UP”,则 SDK 会按照消息中包含的 Unix 时间戳 (ChatOptions.sortMessageByServerTime) 的降序顺序从最新消息开始检索消息。
      • 如果“direction”设置为“ChatSearchDirection.DOWN”,则 SDK 会按照消息中包含的 Unix 时间戳 (ChatOptions.sortMessageByServerTime) 的升序从最旧的消息开始检索消息。
    • direction: ChatSearchDirection = ChatSearchDirection.UP
    • loadCount: number = 20

      每次检索的最大消息数。 取值范围为[1,400]。

    Returns Promise<ChatMessage[]>

    消息列表(不包括具有开始或结束时间戳的消息列表)。 如果没有获取到消息,则返回空列表。

    Throws

    异常的描述。 请参阅ChatError

    Deprecated

    2024-04-17 此方法已弃用。 请改用 getMsgs

  • 检索本地数据库中会话中带有关键字的消息。

    Parameters

    • keywords: string

      查询的关键字。

    • direction: ChatSearchDirection = ChatSearchDirection.UP
    • timestamp: number = -1

      用于查询的消息中的起始 Unix 时间戳。 单位是毫秒。 设置该参数后,SDK按照消息搜索方向,从指定的消息开始检索消息。 如果将此参数设置为负值,则 SDK 从当前时间开始,按照消息中包含的 Unix 时间戳 (ChatOptions.sortMessageByServerTime) 的降序顺序检索消息。

    • count: number = 20

      每次检索的最大消息数。取值范围为[1,400]。

    • Optional sender: string

      用于检索的用户 ID 或组 ID。

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有起始时间戳的消息)。如果没有获取到消息,则返回空列表。

    Throws

    异常的描述。请参阅ChatError

    Deprecated

    2024-04-17 此方法已弃用。 请改用 getMsgsWithKeyword

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

    Parameters

    • msgType: ChatMessageType

      消息类型。详见 ChatMessageType

    • direction: ChatSearchDirection = ChatSearchDirection.UP

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

    • timestamp: number = -1

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

    • count: number = 20

      获取的最大消息数量。

    • Optional sender: string

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

    Returns Promise<ChatMessage[]>

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

    Throws

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

  • 检索本地数据库中某个会话在一定时间内发送和接收的消息。

    注意 如果会话对象不存在,此方法将创建它。

    Parameters

    • params: {
          count?: number;
          direction?: ChatSearchDirection;
          endTime: number;
          startTime: number;
      }
      • Optional count?: number
      • Optional direction?: ChatSearchDirection
      • endTime: number
      • startTime: number

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有开始或结束时间戳的消息)。 如果没有获取到消息,则返回空列表。

    Params

    Throws

    异常的描述。 请参阅ChatError

  • 从本地数据库中检索会话中指定数量的消息。

    检索到的消息也会根据其中包含的时间戳放入内存中的会话中。

    注意 如果会话对象不存在,此方法将创建它。

    Parameters

    • params: {
          direction?: ChatSearchDirection;
          loadCount?: number;
          startMsgId: string;
      }

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有起始时间戳的消息)。 如果没有获取到消息,则返回空列表。

    Params

    Throws

    异常的描述。 请参阅ChatError

  • 获取指定用户在一定时间段内在会话中发送的消息。

    该方法搜索本地数据库中的消息。

    注意 如果会话对象不存在,此方法将创建它。

    Parameters

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有起始时间戳的消息)。 如果没有获取到消息,则返回空列表。

    Params

    • keywords 查询的关键字。
    • direction 消息搜索方向。请参阅 ChatSearchDirection
    • (Default) ChatSearchDirection.UP:按照消息中包含的 Unix 时间戳 (ChatOptions.sortMessageByServerTime) 的降序顺序检索消息。
    • ChatSearchDirection.DOWN: 按照消息中包含的 Unix 时间戳 (ChatOptions.sortMessageByServerTime) 的升序检索消息。
    • timestamp 用于查询的消息中的起始 Unix 时间戳。 单位是毫秒。 设置该参数后,SDK按照消息搜索方向,从指定的消息开始检索消息。
    • searchScope 搜索范围,请参阅 ChatMessageSearchScope
    • count 每次检索的最大消息数。 取值范围为[1,400]。
    • sender 用于检索的用户 ID 或组 ID。

    Throws

    异常的描述。请参阅 ChatError

  • 从本地数据库中检索会话中某种类型的消息。

    注意 如果会话对象不存在,此方法将创建它。

    Parameters

    Returns Promise<ChatMessage[]>

    检索到的消息列表(不包括具有起始时间戳的消息)。 如果没有获取到消息,则返回空列表。

    Params

    Throws

    异常的描述。 请参阅ChatError

  • 从本地获取会话中的置顶消息。

    Returns Promise<ChatMessage[]>

    置顶消息列表。如果没有获取到消息,则返回空列表。

    Throws

    异常的描述。 请参阅ChatError

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

    Returns Promise<number>

    会话的未读消息数量。

    Throws

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

  • 标记所有消息为已读。

    Returns Promise<void>

    Throws

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

  • 标记指定消息为已读。

    Parameters

    • msgId: string

      消息 ID。

    Returns Promise<void>

    Throws

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

  • 获取会话 ID。

    Returns Promise<undefined | string>

    会话 ID。

  • 从会话中删除消息(从本地存储和服务器)。

    Parameters

    • msgIds: string[]

      要从当前会话中删除的消息的 ID。

    Returns Promise<void>

    Throws

    异常的描述。 请参阅ChatError

  • 从会话中删除消息(从本地存储和服务器)。

    Parameters

    • timestamp: number

      消息时间戳(以毫秒为单位)。 时间戳小于指定时间戳的消息将被删除。

    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