ChatManager class
~english The chat manager class, responsible for sending and receiving messages, loading and deleting conversations, and downloading attachments.
The sample code for sending a text message:
ChatMessage msg = ChatMessage.createTxtSendMessage(
username: toChatUsername, content: content);
await ChatClient.getInstance.chatManager.sendMessage(msg);
~end
~chinese 聊天管理类,该类负责管理会话(加载,删除等)、发送消息、下载消息附件等。
比如,发送一条文本消息:
ChatMessage msg = ChatMessage.createTxtSendMessage(
targetId: toChatUsername, content: content);
await ChatClient.getInstance.chatManager.sendMessage(msg);
~end
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addEventHandler(
String identifier, ChatEventHandler handler) → void - ~english Adds the chat event handler. After calling this method, you can handle for chat event when they arrive.
-
addMessageEvent(
String identifier, ChatMessageEvent event) → void - ~english Adds a message status listener.
-
addReaction(
{required String messageId, required String reaction}) → Future< void> - ~english Adds a Reaction.
-
addRemoteAndLocalConversationsMark(
{required List< String> conversationIds, required ConversationMarkType mark}) → Future<void> - ~english This method marks conversations both locally and on the server.
-
clearEventHandlers(
) → void - ~english Clear all chat event handlers. ~end
-
clearMessageEvent(
) → void - ~english Clears all message status listeners. ~end
-
deleteAllMessageAndConversation(
{bool clearServerData = false}) → Future< void> -
~english
Clears all conversations and all messages in them.
Param
clearServerData
Whether to clear the server data. -
deleteConversation(
String conversationId, {bool deleteMessages = true}) → Future< bool> - ~english Deletes a conversation and its related messages from the local database.
-
deleteMessagesBefore(
int timestamp) → Future< void> - ~english Deletes messages with timestamp that is before the specified one.
-
deleteRemoteAndLocalConversationsMark(
{required List< String> conversationIds, required ConversationMarkType mark}) → Future<void> -
~english
This method unmarks conversations both locally and on the server.
Param
conversationIds
The list of conversation IDs to unmark. Parammark
The mark type. See ConversationMarkType. ~end -
deleteRemoteConversation(
String conversationId, {ChatConversationType conversationType = ChatConversationType.Chat, bool isDeleteMessage = true}) → Future< void> - ~english Deletes the specified conversation and the related historical messages from the server.
-
deleteRemoteMessagesBefore(
{required String conversationId, required ChatConversationType type, required int timestamp}) → Future< void> - ~english Unidirectionally removes historical message by timestamp from the server.
-
deleteRemoteMessagesWithIds(
{required String conversationId, required ChatConversationType type, required List< String> msgIds}) → Future<void> - ~english Unidirectionally removes historical message by message ID from the server.
-
downloadAttachment(
ChatMessage message) → Future< void> - ~english Downloads the attachment files from the server.
-
downloadMessageAttachmentInCombine(
ChatMessage message) → Future< void> - ~english Downloads the attachment files from the server.
-
downloadMessageThumbnailInCombine(
ChatMessage message) → Future< void> - ~english Downloads the thumbnail if the message has not been downloaded before or if the download fails.
-
downloadThumbnail(
ChatMessage message) → Future< void> - ~english Downloads the thumbnail if the message has not been downloaded before or if the download fails.
-
fetchCombineMessageDetail(
{required ChatMessage message}) → Future< List< ChatMessage> > - ~english Gets the details of a combined message.
-
fetchConversation(
{String? cursor, int pageSize = 20}) → Future< ChatCursorResult< ChatConversation> > - ~english Get the list of conversations from the server with pagination.
-
fetchConversationListFromServer(
{int pageNum = 1, int pageSize = 20}) → Future< List< ChatConversation> > - ~english Gets the list of conversations from the server.
-
fetchConversationsByOptions(
{required ConversationFetchOptions options}) → Future< ChatCursorResult< ChatConversation> > -
~english
Fetches conversations by options.
Param
options
The options for fetching conversations, see ConversationFetchOptions. Returns The list of conversations. Throws A description of the exception. See ChatError. ~end ~chinese 根据选项获取会话。 Paramoptions
获取会话的选项, 详见 ConversationFetchOptions。 Returns 会话列表。 Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。 ~end -
fetchGroupAcks(
String msgId, String groupId, {String? startAckId, int pageSize = 0}) → Future< ChatCursorResult< ChatGroupMessageAck> > - ~english Gets read receipts for group messages from the server with pagination.
-
fetchHistoryMessages(
{required String conversationId, ChatConversationType type = ChatConversationType.Chat, int pageSize = 20, ChatSearchDirection direction = ChatSearchDirection.Up, String startMsgId = ''}) → Future< ChatCursorResult< ChatMessage> > - ~english Gets historical messages of the conversation from the server with pagination.
-
fetchHistoryMessagesByOption(
String conversationId, ChatConversationType type, {FetchMessageOptions? options, String? cursor, int pageSize = 50}) → Future< ChatCursorResult< ChatMessage> > - ~english Gets historical messages of a conversation from the server according to FetchMessageOptions.
-
fetchPinnedConversations(
{String? cursor, int pageSize = 20}) → Future< ChatCursorResult< ChatConversation> > - ~english Gets the list of pinned conversations from the server with pagination.
-
fetchPinnedMessages(
{required String conversationId}) → Future< List< ChatMessage> > -
~english
Fetches pinned messages.
Param
conversationId
The conversation ID. Returns The list of pinned messages. Throws A description of the exception. See ChatError. ~end ~chinese 获取置顶消息。 ParamconversationId
会话 ID。 Returns 置顶消息列表。 Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。 ~end -
fetchReactionDetail(
{required String messageId, required String reaction, String? cursor, int pageSize = 20}) → Future< ChatCursorResult< ChatMessageReaction> > - ~english Gets the Reaction details.
-
fetchReactionList(
{required List< String> messageIds, required ChatType chatType, String? groupId}) → Future<Map< String, List< >ChatMessageReaction> > - ~english Gets the list of Reactions.
-
fetchSupportedLanguages(
) → Future< List< ChatTranslateLanguage> > - ~english Gets all languages supported by the translation service.
-
getConversation(
String conversationId, {ChatConversationType type = ChatConversationType.Chat, bool createIfNeed = true}) → Future< ChatConversation?> - ~english Gets the conversation by conversation ID and conversation type.
-
getConversationsFromServer(
) → Future< List< ChatConversation> > - ~english Gets the conversation list from the server.
-
getEventHandler(
String identifier) → ChatEventHandler? - ~english Get the chat event handler.
-
getThreadConversation(
String threadId) → Future< ChatConversation?> - ~english Gets the thread conversation by thread ID.
-
getUnreadMessageCount(
) → Future< int> - ~english Gets the count of the unread messages.
-
importMessages(
List< ChatMessage> messages) → Future<void> - ~english Imports messages to the local database.
-
loadAllConversations(
) → Future< List< ChatConversation> > - ~english Gets all conversations from the local database.
-
loadMessage(
String messageId) → Future< ChatMessage?> - ~english Loads a message from the local database by message ID.
-
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.
-
markAllConversationsAsRead(
) → Future< void> - ~english Marks all messages as read.
-
modifyMessage(
{required String messageId, required ChatTextMessageBody msgBody}) → Future< ChatMessage> - ~english Modifies a message.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pinConversation(
{required String conversationId, required bool isPinned}) → Future< void> - ~english Sets whether to pin a conversation.
-
pinMessage(
{required String messageId}) → Future< void> -
~english
Pins a message.
Param
messageId
The message ID. -
recallMessage(
String messageId) → Future< void> - ~english Recalls the sent message.
-
removeEventHandler(
String identifier) → void - ~english Remove the chat event handler.
-
removeMessageEvent(
String identifier) → void - ~english Removes a message status listener.
-
removeReaction(
{required String messageId, required String reaction}) → Future< void> - ~english Deletes a Reaction.
-
reportMessage(
{required String messageId, required String tag, required String reason}) → Future< void> - ~english Reports an inappropriate message.
-
resendMessage(
ChatMessage message) → Future< ChatMessage> - ~english Resends a message.
-
searchMsgFromDB(
String keywords, {int timestamp = -1, int maxCount = 20, String from = '', ChatSearchDirection direction = ChatSearchDirection.Up}) → Future< List< ChatMessage> > - ~english Retrieves messages from the database according to the parameters.
-
sendConversationReadAck(
String conversationId) → Future< void> - ~english Sends the conversation read receipt to the server. This method is only for one-to-one chat conversations.
-
sendGroupMessageReadAck(
String msgId, String groupId, {String? content}) → Future< void> - ~english Sends the group message receipt to the server.
-
sendMessage(
ChatMessage message) → Future< ChatMessage> - ~english Sends a message.
-
sendMessageReadAck(
ChatMessage message) → Future< bool> - ~english Sends the read receipt to the server.
-
toString(
) → String -
A string representation of this object.
inherited
-
translateMessage(
{required ChatMessage msg, required List< String> languages}) → Future<ChatMessage> - ~english Translates a text message.
-
unpinMessage(
{required String messageId}) → Future< void> -
~english
Unpins a message.
Param
messageId
The message ID. -
updateMessage(
ChatMessage message) → Future< void> - ~english Updates the local message.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited