EMConversation 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.
  EMConversation? con = await EMClient.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.
  EMConversation? con = await EMClient.getInstance.chatManager.getConversation(conversationId);
  int? unreadCount = con?.unreadCount;

~end

Available extensions

Constructors

EMConversation.new(String id, EMConversationType type, Map<String, String>? _ext, bool isChatThread, bool isPinned, int pinnedTime, List<ConversationMarkType>? marks)
EMConversation.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 Whether the conversation is a chat thread conversation.
final
isPinned bool
~english Whether the conversation is pinned:
final
marks List<ConversationMarkType>?
~english The conversation marks. ~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 EMConversationType
~english The conversation type. ~end
final

Methods

addMention() Future<void>

Available on Conversation, provided by the ConversationHelp extension

appendMessage(EMMessage 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.
deleteLocalAndServerMessages({required List<String> msgIds}) Future<void>
~english
deleteLocalAndServerMessagesByTime({required int beforeMs}) Future<void>
~english
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.
getLocalMessageCount({required int startMs, required int endMs}) Future<int>
~english Gets the local message count. The count of messages in the local database within the specified time range.
insertMessage(EMMessage 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<EMMessage?>
~english Gets the latest message from the conversation.
latestMessage() Future<EMMessage?>
~english Gets the last message from the conversation.
loadMessage(String messageId) Future<EMMessage?>
~english Gets the message with a specific message ID.
loadMessages({String startMsgId = '', int loadCount = 20, EMSearchDirection direction = EMSearchDirection.Up}) Future<List<EMMessage>>
~english Loads multiple messages from the local database.
loadMessagesFromTime({required int startTime, required int endTime, int count = 20}) Future<List<EMMessage>>
~english 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, EMSearchDirection direction = EMSearchDirection.Up}) Future<List<EMMessage>>
~english 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, EMSearchDirection direction = EMSearchDirection.Up}) Future<List<EMMessage>>
~english Retrieves messages from the database according to the following parameters: the message type, the Unix timestamp, max count, sender.
loadPinnedMessages() Future<List<EMMessage>>
~english Gets the pinned messages in a local 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
remindType() Future<ChatPushRemindType>
~english The conversation no disturb type. ChatPushRemindType
removeMention() Future<void>

Available on Conversation, provided by the ConversationHelp extension

searchMsgsByOptions(MessageSearchOptions options) Future<List<EMMessage>>
~english Loads messages with the specified keyword from the local database.
setExt(Map<String, String>? ext) Future<void>
~english Sets 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(EMMessage message) Future<void>
~english Updates a message in the local database.

Operators

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