Setting and Using Conversation Tags
- SDK version 5.6.11 and above supports the conversation tag feature.
- Before setting tags for conversations, ensure that tag information has been created. For details, see Managing Tag Information Data.
- This feature is not applicable to chatrooms and ultra groups.
Each user can create up to 20 tags, with each tag containing a maximum of 1,000 conversations. If a tag already has 1,000 conversations, adding more conversations to the tag will still succeed, but the earliest tagged conversation will be removed from the tag.
Scenario Description
Conversation tags are often used to meet the need for grouping conversations in an app. After creating tag information (RCIMIWTagInfo
), app users can set one or more tags for a conversation.
Once tags are set, the tag data can be used to implement features such as grouping, displaying, and deleting conversations. It is also possible to retrieve the unread message count for all conversations under a specific tag or pin a conversation within a particular tag.
- Scenario 1: Tagging each conversation in the conversation list, similar to external groups, department groups, and personal groups in the conversation list of Enterprise WeChat.
- Scenario 2: Grouping contacts in the address book based on tags, similar to family, friends, and colleagues in the QQ contact list.
- Scenario 3: Combining the first two scenarios, grouping the conversation list by tags, similar to the conversation list grouping in Telegram.
Using Tags to Mark Conversations
After creating tag information (RCIMIWTagInfo
), app users can use tags to mark conversations. The SDK considers the act of tagging a conversation as adding the conversation to a tag.
The following operations are supported:
- Tagging conversations, i.e., adding one or more conversations to a specified tag.
- Removing one or more conversations from a tag.
- Removing one or more tags from a specified conversation.
Adding One or More Conversations to a Specified Tag
The SDK considers the act of tagging a conversation as adding the conversation to a tag. You can add multiple conversations to a single tag. Only the tagId
from RCIMIWTagInfo
needs to be passed when specifying the tag.
Method
Future<int> addConversationToTag(String tagId, RCIMIWConversationType type, String targetId, {IRCIMIWAddConversationToTagCallback? callback});
Parameter Description
Parameter | Type | Description |
---|---|---|
tagId | String | The unique identifier of the tag, a string of no more than 10 characters. |
type | RCIMIWConversationType | The type of conversation. |
targetId | String | The conversation ID. |
callback | IRCIMIWAddConversationToTagCallback | The event callback. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates that the current operation failed, and the callback will not be triggered. Refer to the error codes for detailed errors. |
Code Example
IRCIMIWAddConversationToTagCallback? callback = IRCIMIWAddConversationToTagCallback(onConversationToTagAdded: (int? code) {
//...
});
int? ret = await engine?.addConversationToTag(tagId, type, targetId, callback:callback);
Removing Conversations from a Specified Tag
App users may need to remove one or more conversations from all conversations tagged with a specific tag. For example, removing the private chat with "Tom" from all conversations tagged with "Training Class." The SDK considers this operation as removing the conversation from the specified tag. After successful removal, the conversation still exists but no longer carries the tag.
Method
Future<int> removeConversationFromTag(String tagId, RCIMIWConversationType type, String targetId, {IRCIMIWRemoveConversationFromTagCallback? callback});
Parameter Description
Parameter | Type | Description |
---|---|---|
tagId | String | The unique identifier of the tag, a string of no more than 10 characters. |
type | RCIMIWConversationType | The type of conversation. |
targetId | String | The conversation ID. |
callback | IRCIMIWRemoveConversationFromTagCallback | The event callback. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates that the current operation failed, and the callback will not be triggered. Refer to the error codes for detailed errors. |
Code Example
IRCIMIWRemoveConversationFromTagCallback? callback = IRCIMIWRemoveConversationFromTagCallback(onConversationFromTagRemoved: (int? code) {
//...
});
int? ret = await engine?.removeConversationFromTag(tagId, type, targetId, callback:callback);
Removing Tags from a Specified Conversation
App users may have added multiple tags to a specific conversation. The SDK supports removing one or more tags at a time. When removing, pass a list of tagId
s from all RCIMIWTagInfo
s to be removed.
Method
Future<int> removeTagsFromConversation(RCIMIWConversationType type, String targetId, List<String> tagIds, {IRCIMIWRemoveTagsFromConversationCallback? callback});
Parameter Description
Parameter | Type | Description |
---|---|---|
type | RCIMIWConversationType | The type of conversation. |
targetId | String | The conversation ID. |
tagIds | List<String> | The collection of tags. |
callback | IRCIMIWRemoveTagsFromConversationCallback | The event callback. |
Return Value
Return Value | Description |
---|---|
Future<int> | The status code of the current operation. 0 indicates success, and the specific result needs to be implemented in the callback; non-zero indicates that the current operation failed, and the callback will not be triggered. Refer to the error codes for detailed errors. |
Code Example
IRCIMIWRemoveTagsFromConversationCallback? callback = IRCIMIWRemoveTagsFromConversationCallback(onTagsFromConversationRemoved: (int? code) {
//...
});
int? ret = await engine?.removeTagsFromConversation(type, targetId, tagIds, callback:callback);
Retrieving All Tags for a Specified Conversation
Retrieve all tags associated with a specified conversation. Upon success, the callback returns a list of RCConversationTagInfo
. Each RCConversationTagInfo
contains the corresponding tag information RCIMIWTagInfo
and the pin status (whether the conversation is pinned among all conversations carrying the tag information).
Method
Future<int> getTagsFromConversation(RCIMIWConversationType type, String targetId, {IRCIMIWGetTagsFromConversationCallback? callback});