ChatConversation class

~english The conversation class, indicating a one-to-one chat, a group chat, or a conversation chat. It contains the messages that are sent and received within the conversation.

The following code shows how to get the number of the unread messages from the conversation.

  // ConversationId can be the other party id, the group id, or the chat room id.
  ChatConversation? con = await ChatClient.getInstance.chatManager.getConversation(conversationId);
  int? unreadCount = con?.unreadCount;

~end

~chinese 会话类,用于定义单聊会话、群聊会话和聊天室会话。每类会话中包含发送和接收的消息。

以下示例代码展示如何从会话中获取未读消息数:

  // The `ConversationId` can be the other party ID, the group ID, or the chat room ID.
  ChatConversation? con = await ChatClient.getInstance.chatManager.getConversation(conversationId);
  int? unreadCount = con?.unreadCount;

~end

Constructors

ChatConversation.fromJson(Map<String, dynamic> map)
factory

Properties

ext Map<String, String>?
~english The conversation extension attribute.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
~english The conversation ID.
final
isChatThread bool
~english Is chat thread conversation. ~end
final
isPinned bool
~english Whether the conversation is pinned:
final
marks List<ConversationMarkType>?
~english The conversation remarks. ~end
final
pinnedTime int
~english The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is 0 when the conversation is not pinned. ~end
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type ChatConversationType
~english The conversation type. ~end
final

Methods

appendMessage(ChatMessage message) Future<void>
~english Inserts a message to the end of a conversation in the local database.
deleteAllMessages() Future<void>
~english Deletes all the messages of the conversation from both the memory and local database.
deleteMessage(String messageId) Future<void>
~english Deletes a message in the local database.
deleteMessageByIds(List<String> messageIds) Future<void>
~english Deletes messages with message ids.
deleteMessagesWithTs(int startTs, int endTs) Future<void>
~english Deletes messages sent or received in a certain period from the local database.
insertMessage(ChatMessage message) Future<void>
~english Inserts a message to a conversation in the local database and the SDK will automatically update the last message.
lastReceivedMessage() Future<ChatMessage?>
~english Gets the latest message from the conversation.
latestMessage() Future<ChatMessage?>
~english Gets the last message from the conversation.
loadMessage(String messageId) Future<ChatMessage?>
~english Gets the message with a specific message ID.
loadMessages({String startMsgId = '', int loadCount = 20, ChatSearchDirection direction = ChatSearchDirection.Up}) Future<List<ChatMessage>>
~english Loads multiple messages from the local database.
loadMessagesFromTime({required int startTime, required int endTime, int count = 20}) Future<List<ChatMessage>>
~english Loads messages from the local database according the following parameters: start timestamp, end timestamp, count.
loadMessagesWithKeyword(String keywords, {String? sender, int timestamp = -1, int count = 20, MessageSearchScope searchScope = MessageSearchScope.All, ChatSearchDirection direction = ChatSearchDirection.Up}) Future<List<ChatMessage>>
~english Loads messages from the local database by the following parameters: keywords, timestamp, max count, sender, search direction.
loadMessagesWithMsgType({required MessageType type, int timestamp = -1, int count = 20, String? sender, ChatSearchDirection direction = ChatSearchDirection.Up}) Future<List<ChatMessage>>
~english Retrieves messages from the database according to the following parameters: the message type, the Unix timestamp, max count, sender.
loadPinnedMessages() Future<List<ChatMessage>>
~english Get the pinned messages in the conversation
markAllMessagesAsRead() Future<void>
~english Marks all messages as read. ~end
markMessageAsRead(String messageId) Future<void>
~english Marks a message as read.
messagesCount() Future<int>
~english Message count ~end
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setExt(Map<String, String>? ext) Future<void>
~english Set the conversation extension attribute.
toString() String
A string representation of this object.
inherited
unreadCount() Future<int>
~english Gets the unread message count of the conversation.
updateMessage(ChatMessage message) Future<void>
~english Updates a message in the local database.

Operators

operator ==(Object other) bool
The equality operator.
inherited