Setting and Using Conversation Tags
- The SDK supports conversation tags starting from version 5.1.1, with related interfaces provided exclusively in the
RCCoreClientclass.- Starting from SDK version 5.3.0, it's recommended to use interfaces with asynchronous results, while the original synchronous interfaces are deprecated.
- Before setting tags for conversations, ensure you've created tag information. See [Managing Tag Information Data] for details.
- This feature is not applicable to chatrooms or ultra groups.
Each user can create up to 20 tags, with each tag containing a maximum of 1,000 conversations. If a tag already contains 1,000 conversations, adding more conversations to it will still succeed but will result in the earliest tagged conversation being removed from the tag.
Use Case Description
Conversation tags typically fulfill the need for app users to group conversations. After creating tag information ([RCTagInfo]), app users can assign one or more tags to conversations.
Once tags are set, you can leverage conversation tag data to implement features like grouped retrieval, display, and deletion of conversations. You can also obtain the unread message count for all conversations under a specific tag or pin a conversation within a particular tag.
- Use Case 1: Tagging each conversation in the conversation list, similar to external groups, department groups, and personal group tags in WeCom's conversation list.
- Use Case 2: Grouping contacts by tags, similar to family, friends, and colleagues groupings in QQ's contact list.
- Use Case 3: A combination of the first two use cases, grouping conversation lists by tags, similar to Telegram's conversation list grouping.
Using Tags to Mark Conversations
After creating tag information ([RCTagInfo]), app users can use tags to mark conversations. The SDK treats the act of tagging a conversation as adding the conversation to a tag.
Supported operations include:
- Tagging conversations (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 IMLib SDK treats 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 [RCTagInfo] needs to be specified when tagging.
Method Prototype
- (void)addConversationsToTag:(NSString *)tagId
conversationIdentifiers:(NSArray<RCConversationIdentifier *> *)conversationIdentifiers
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode errorCode))errorBlock;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| tagId | NSString | Tag ID. |
| conversationIdentifiers | NSArray | Conversation list, with array elements being [RCConversationIdentifier]. |
| successBlock | Block | Success callback. |
| errorBlock | Block | Failure callback. The errorCode parameter returns an [RCErrorCode]. |
Example Code
RCConversationIdentifier *iden = [[RCConversationIdentifier alloc] initWithConversationIdentifier:ConversationType_PRIVATE targetId:@"targetId"];
[[RCCoreClient sharedCoreClient] addConversationsToTag:@"tagId" conversationIdentifiers:@[iden] success:^{
} error:^(RCErrorCode errorCode) {
}];
Removing Conversations from a Specified Tag
You may need to remove one or more conversations from all conversations tagged with a specified tag. For example, removing a private chat with Tom from all conversations tagged as Training Class. The IMLib SDK treats this operation as removing conversations from a specified tag. After successful removal, the conversation still exists but no longer carries the tag.
Interface Prototype
- (void)removeConversationsFromTag:(NSString *)tagId
conversationIdentifiers:(NSArray<RCConversationIdentifier *> *)conversationIdentifiers
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode errorCode))errorBlock;