ChatConversation class

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;

Constructors

ChatConversation.new(String id, ChatConversationType type, Map<String, String>? _ext, bool isChatThread, bool isPinned, int pinnedTime, List<ConversationMarkType>? marks)
ChatConversation.fromJson(Map<String, dynamic> map)
factory

Properties

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

Methods

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

Operators

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