Flutter
Feature Description
In some cases, you may need to mark a conversation, for example, as "favorite", "collapsed", "hidden", or "unread", which can be implemented through the following API.
Note:
To use this feature, you need to purchase the Ultimate edition.
This feature is available only in v4.0.8 or later.
Conversation Mark
Marking a conversation
Caution:
When a user marks a conversation, the SDK records only the mark value and will not change the underlying logic of the conversation. For example, if a conversation is marked as
V2TIM_CONVERSATION_MARK_TYPE_UNREAD
, the unread count at the underlying layer will not change.Parameters of the API for marking a conversation are as described below:
Attribute | Definition | Description |
conversationIDList | List of conversation IDs | Up to 100 conversations can be marked at a time. |
markType | Mark type | A conversation can be marked as a favorite, unread, collapsed, or hidden. |
enableMark | Mark/Unmark | A conversation can be marked/unmarked. |
Note:
The SDK provides four default marks ("favorite", "collapsed", "hidden", and "unread"). If they cannot meet your requirements, you can customize extended marks, which must meet the following conditions:
1. The value of an extended mark cannot be the same as that of an existing one.
2. The value of an extended mark must be 0x1LL << displacement value of n (
32 ≤ n < 64
indicates that n
must be equal to or greater than 32 and less than 64). For example, 0x1LL << 32
indicates "Online on an iPhone".Sample code:
// Mark a conversationV2TimValueCallback<List<V2TimConversationOperationResult>>markConversationRes = await TencentImSDKPlugin.v2TIMManager.getConversationManager().markConversation(markType: 0,// Mark typeenableMark: true,// Whether to support the marking featureconversationIDList: []);// List of IDs of the conversations to be markedif (markConversationRes.code == 0) {// Marked successfullymarkConversationRes.data?.forEach((element) {element.conversationID; // ID of the conversation markedelement.resultCode; // Operation result error code of the conversationelement.resultInfo; // Operation result description of the conversation});}
Listening for the notification of a conversation mark change
After a conversation is marked or unmarked, the
markList
field (dart) in V2TimConversation
of the conversation will change. You can call the addConversationListener
(dart) API to listen for such a change notification.Sample code:
// Set the conversation listenerV2TimConversationListener listener = V2TimConversationListener(onConversationChanged: (List<V2TimConversation> conversationList) => {// If the key information of some conversations changes (for example, the unread count changes, or the last message is updated), use "lastMessage -> timestamp" to sort the conversation list again.// conversationList: List of conversations that have changes});// Add a conversation listenerTencentImSDKPlugin.v2TIMManager.getConversationManager().addConversationListener(listener: listener); // Conversation listener to add
Pulling a specified marked conversation
Sample code:
// Get the conversation listV2TimConversationListFilter filter = V2TimConversationListFilter(conversationType: 0, // Conversation typenextSeq: 0,// Pull cursorcount: 10,// Pull countmarkType: 0,// Conversation mark typegroupName: "groupName");// Name of the pulled group// Advanced API for getting the conversation listV2TimValueCallback<V2TimConversationResult> getConversationListByFilterRes =await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationListByFilter(filter: filter);// Conversation list filterif (getConversationListByFilterRes.code == 0) {// Pulled successfullybool? isFinished =getConversationListByFilterRes.data?.isFinished; //Whether the list is fully pulledString? nextSeq =getConversationListByFilterRes.data?.nextSeq; // Cursor for the subsequent paged pullList<V2TimConversation?>? conversationList =getConversationListByFilterRes.data?.conversationList; // List of conversations pulled this time// If more conversations need to be pulled, use the returned `nextSeq` to continue pulling until `isFinished` is `true`.if (!isFinished!) {V2TimConversationListFilter nextFilter = V2TimConversationListFilter(conversationType: 0,nextSeq: int.parse(nextSeq!),// Use the returned `nextSeq` to continue pulling until `isFinished` is `true`.count: 10,markType: 0,groupName: "groupName");V2TimValueCallback<V2TimConversationResult> nextConversationListRes =await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationListByFilter(filter: nextFilter);}getConversationListByFilterRes.data?.conversationList?.forEach((element) {element?.conversationID; // Unique conversation ID. It is in the format of `c2c_userID` for a one-to-one chat or `group_groupID` for a group chat.element?.draftText; // Draft messageelement?.draftTimestamp; // Draft editing time. It is automatically generated when a draft is set.element?.faceUrl; // Displayed conversation profile photo. It is the group profile photo for a group chat or the profile photo of the message receiver for a one-to-one chat.element?.groupAtInfoList; // List of @ information in the group conversation. Generally, it is used to display the notifications of "someone@me" and "@all".element?.groupID; // ID of the current group. If the conversation type is group chat, `groupID` is the ID of the current group. Otherwise, it is `null`.element?.groupType; // Type of the current group. If the conversation type is group chat, `groupType` is the type of the current group. Otherwise, it is `null`.element?.isPinned; // Whether the conversation is pinned to the topelement?.lastMessage; // Last message in the conversationelement?.orderkey; // Field for sorting conversationselement?.recvOpt; // Message receiving optionelement?.showName; // Displayed conversation name. The name of a group chat is displayed in the following order of priority: group name > group ID. The name of a one-to-one chat is displayed in the following order of priority: friend remarks of the message receiver > nickname of the message receiver > `userID` of the message receiver.element?.type; // Conversation type, which can be `C2C` (one-to-one chat) or `Group` (group chat).element?.unreadCount; // Unread message count of the conversation. It is invalid and defaults to `0` for an audio-video group (AVChatRoom).element?.userID; // User ID of the message receiver. If the conversation type is one-to-one chat, `userID` is the user ID of the message receiver. Otherwise, it is `null`.});}