@ Messages
Mentions (@) are a common feature in group chat conversations, allowing you to mention specific users or all group members to enhance message notifications. When using the @ feature, the message content will additionally carry an RCMentionedInfo object. IMKit enables the @ feature by default.
IMKit does not implement the @everyone feature. The "@所有人" (mention everyone) in the diagram is for design reference only. The data for the contact selection page must be provided by the application; otherwise, an empty list will be displayed.
Limitations
- Only supported in group chat conversations.
- IMKit only implements the @ feature for sending text messages and quoted messages by default.
- IMKit does not implement the @everyone feature.
- @ messages can be forwarded, but only as plain text without the @ functionality.
Usage
If the User Profile Hosting feature is not enabled, you must implement the RCIMGroupMemberDataSource
protocol and set the group member list delegate for IMKit before using the @ feature. For details, see User Information.
IMKit enables the @ feature by default in its configuration. The usage is as follows:
- Long-press a user's avatar in the conversation UI to trigger message editing and mention (@) that user.
- After entering the @ symbol in the conversation UI, IMKit will navigate to the member selection page:
- If the User Profile Hosting feature is enabled, the SDK will display member information by default.
- If User Profile Hosting is not enabled, you must set the group member list delegate. IMKit will retrieve group member data through the
getAllMembersOfGroup
method of theRCIMGroupMemberDataSource
protocol and display it in the list page. Otherwise, the page will show an empty list.
Customization
Custom Member Selection UI
If you want to replace the member selection UI, you can override the showChooseUserViewController:
method in the RCConversationViewController
subclass to present your custom selection UI. After selecting members, call the selectedBlock
to pass the selected user list.
- (void)showChooseUserViewController:(void (^)(RCUserInfo *selectedUserInfo))selectedBlock
cancel:(void (^)(void))cancelBlock;
You can refer to the implementation in RongCloud's SealTalk app. For details, see the showChooseUserViewController
method in RCDChatViewController.m.
Implementing @everyone
IMKit does not implement the UI logic for the @everyone feature. You can implement it yourself by constructing an RCMentionedInfo object with the type
property set to RC_Mentioned_All
and embedding it in the message content. After constructing the RCMessage
, send it to the conversation using the sendMessage
(for regular messages) or sendMediaMessage
method.
Sample Code
RCTextMessage *txtMsg = [RCTextMessage messageWithContent:@"Test text message"];
RCMentionedInfo *mentionedInfo = [[RCMentionedInfo alloc] initWithMentionedType:RC_Mentioned_All userIdList:nil mentionedContent:nil];
txtMsg.mentionedInfo = mentionedInfo;
RCMessage *message = [[RCMessage alloc]
initWithType:ConversationType_PRIVATE
targetId:@"targetId"
direction:MessageDirection_SEND
content:txtMsg];
[[RCIM sharedRCIM] sendMessage:message
pushContent:nil
pushData:nil
successBlock:^(RCMessage *successMessage) {
// Success
} errorBlock:^(RCErrorCode nErrorCode, RCMessage *errorMessage) {
// Failure
}];
You can refer to the implementation in RongCloud's SealTalk app. For details, see RCDChooseUserController.m.
Disabling the @ Feature
IMKit enables the @ feature by default. You can disable it globally by modifying the configuration.
RCKitConfigCenter.message.enableMessageMentioned = NO;