The conversation class, which defines one-to-one conversations, group conversations, and chat room conversations.

Each type of conversation involves messages that are sent and received.

You can get the conversation name by conversation type:

Constructors

Properties

convId: string

The conversation ID.

The conversation type.

ext?: any

The conversation extension.

isChatThread: boolean

Whether the current conversation is a thread conversation.

  • true: Yes.
  • false: No.

Note

This parameter is valid only for group chat.

isPinned?: boolean

Whether the conversation is pinned:

  • true: Yes.
  • (Default) false: No.

The conversation marks.

pinnedTime?: number

The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is 0 when the conversation is not pinned.

Methods

  • Deletes all the messages of the conversation.

    This method deletes all the messages of the conversation from both the memory and local database.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes a message from the local database.

    Parameters

    • msgId: string

      The ID of message to delete.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes messages sent or received in a certain period from the local database.

    Parameters

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

    Returns Promise<void>

    params

    • startTs: The starting UNIX timestamp for message deletion. The unit is millisecond.
    • endTs: The end UNIX timestamp for message deletion. The unit is millisecond.

    A description of the exception. See ChatError.

  • Gets the pinned messages in the conversation from the server.

    Returns Promise<ChatMessage[]>

    The list of pinned messages. If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the latest message from the conversation.

    Returns Promise<undefined | ChatMessage>

    The message instance. The SDK returns undefined if the message does not exist.

    A description of the exception. See ChatError.

  • Gets the latest message received in the conversation.

    Returns Promise<undefined | ChatMessage>

    The message instance. The SDK returns undefined if the message does not exist.

    A description of the exception. See ChatError.

  • Gets the count of messages in the conversation.

    Returns Promise<number>

    The count of messages.

    A description of the exception. See ChatError.

  • Gets messages of a certain quantity in a conversation from the local database.

    Note

    The obtained messages will also join the existing messages of the conversation stored in the memory.

    Parameters

    • startMsgId: string

      The starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set an empty string, the SDK retrieves messages according to the message search direction while ignoring this parameter. - If direction is set as ChatSearchDirection.UP, the SDK retrieves messages, starting from the latest one, in the descending order of the Unix timestamp (ChatOptions.sortMessageByServerTime) included in them. - If direction is set as ChatSearchDirection.DOWN, the SDK retrieves messages, starting from the oldest one, in the ascending order of the Unix timestamp (ChatOptions.sortMessageByServerTime) included in them.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

    • loadCount: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    Returns Promise<ChatMessage[]>

    The message list (excluding the ones with the starting or ending timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2024-04-17 This method is deprecated. Use getMsgs instead.

  • Gets messages with keywords in a conversation in the local database.

    Parameters

    • keywords: string

      The keywords for query.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

    • timestamp: number = -1

      The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the the Unix timestamp (ChatOptions.sortMessageByServerTime) included in them.

    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • Optionalsender: string

      The user ID or group ID for retrieval. Usually, it is the conversation ID.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2024-04-17 This method is deprecated. Use getMsgsWithKeyword instead.

  • Gets messages of a certain type that a specified user sends in a conversation.

    Parameters

    • msgType: ChatMessageType

      The message type. See ChatMessageType.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

    • timestamp: number = -1

      The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.

    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    • Optionalsender: string

      The user ID or group ID for retrieval. Usually, it is the conversation ID.

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2024-04-17 This method is deprecated. Use getMsgsWithMsgType instead.

  • Gets messages that are sent and received in a certain period in a conversation in the local database.

    Parameters

    • startTime: number

      The starting Unix timestamp for search. The unit is millisecond.

    • endTime: number

      The ending Unix timestamp for search. The unit is millisecond.

    • direction: ChatSearchDirection = ChatSearchDirection.UP

      The message search direction. See ChatSearchDirection.

    • count: number = 20

      The maximum number of messages to retrieve each time. The value range is [1,400].

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the ones with the starting or ending timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

    2024-04-17 This method is deprecated. Use getMsgWithTimestamp instead.

  • Gets messages of a specified quantity in a conversation from the local database.

    The retrieved messages will also be put in the conversation in the memory according to the timestamp included in them.

    note If the conversation object does not exist, this method will create it.

    Parameters

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

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets messages that the specified user sends in a conversation in a certain period.

    This method gets data from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    • keywords The keywords for query.
    • direction The message search direction. See ChatSearchDirection.
    • (Default) ChatSearchDirection.UP: Messages are retrieved in the descending order of the Unix timestamp included in them.
    • ChatSearchDirection.DOWN: Messages are retrieved in the ascending order of the Unix timestamp included in them.
    • timestamp The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction.
    • searchScope The message search scope. See ChatMessageSearchScope. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.
    • count The maximum number of messages to retrieve each time. The value range is [1,400].
    • sender The user ID or group ID for retrieval. Usually, it is the conversation ID.

    A description of the exception. See ChatError.

  • Gets messages of a certain type in the conversation from the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets messages that are sent and received in a certain period in a conversation in the local database.

    note If the conversation object does not exist, this method will create it.

    Parameters

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

    Returns Promise<ChatMessage[]>

    The list of retrieved messages (excluding with the ones with the starting or ending timestamp). If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the pinned messages in the conversation from the local database.

    Returns Promise<ChatMessage[]>

    The list of pinned messages. If no message is obtained, an empty list is returned.

    A description of the exception. See ChatError.

  • Gets the count of unread messages in the conversation.

    Returns Promise<number>

    The count of unread messages.

    A description of the exception. See ChatError.

  • Marks all messages as read.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Marks a message as read.

    Parameters

    • msgId: string

      The message ID.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Gets the conversation ID.

    Returns Promise<undefined | string>

    The conversation ID.

  • Deletes messages from the conversation (from both local storage and server).

    Parameters

    • msgIds: string[]

      The IDs of messages to delete from the current conversation.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Deletes messages from the conversation (from both local storage and server).

    Parameters

    • timestamp: number

      The message timestamp in millisecond. The messages with the timestamp smaller than the specified one will be deleted.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Sets the extension information of the conversation.

    Parameters

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

      The extension information of the conversation. This parameter must be in the key-value format.

      • [key: string]: string | number

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Updates a message in the local database.

    After you modify a message, the message ID remains unchanged and the SDK automatically updates attributes of the conversation, like latestMessage.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.