Skip to main content

@ Messages

Mention (@) is a common feature in group chat conversations that allows users to notify specific members or all participants, enhancing message visibility. When using this feature, the message content carries an additional MentionedInfo object. IMKit enables the @ feature by default.

tip

IMKit does not natively support @all functionality. The "@所有人" shown in the demo images is for design reference only. The contact selection page requires data provided by your application—otherwise it displays an empty list. Before using @ functionality, implement the Group Member Provider.

Limitations

  • Only supported in group chats.
  • IMKit natively supports @ functionality only for text messages and quoted messages.
  • IMKit does not implement @all functionality.
  • @ messages can be forwarded, but only as plain text without @ functionality.

Usage

tip

Before using @ functionality, implement the Group Member Provider.

IMKit enables @ functionality by default in its configuration. Usage:

  • Long-press a user's avatar in the chat UI to trigger message editing and mention (@) that user.
  • After typing the @ symbol in the chat UI, IMKit navigates to the member selection page. If your app hasn't implemented the group member provider (IGroupMembersProvider), this page shows an empty list. Once implemented, IMKit retrieves member data via the getGroupMembers method of IGroupMembersProvider and displays it in the selection list.

Customization

Custom Member Selection Interface

When @ functionality is enabled, typing the @ character triggers the member selection page (MentionMemberSelectActivity), which you can replace:

  1. Set up a listener for @ character input using RongMentionManager:

    RongMentionManager.getInstance().setMentionedInputListener(new IMentionedInputListener() {
    /**
    * Set up listener
    * @param conversationType Conversation type. Must be a group chat type.
    * @param targetId Conversation ID. Group ID.
    */
    @Override
    public boolean onMentionedInput(Conversation.ConversationType conversationType, String targetId) {
    // Redirect to your custom member selection interface or perform other actions here.
    // Return true to intercept the event.
    return true;
    }
    });
  2. In the listener callback onMentionedInput(), redirect to your custom member selection interface and return true.

  3. After selecting members in your custom interface, call mentionMember to return selected member info as UserInfo.

    If returning UserInfo, IMKit displays the mentioned member's name in the input field according to the nickname in UserInfo.

    RongMentionManager.getInstance().mentionMember(userInfo);

    Alternatively, use this method. IMKit retrieves the display name from your implemented group member user info provider (UserDataProvider.GroupUserInfoProvider) using the userId.

    String targetId = "Group ID";
    String userId = "User ID of mentioned member";

    RongMentionManager.getInstance().mentionMember(ConversationType.GROUP, targetId, userId);

Implement @all Functionality

IMKit doesn't natively implement the @all feature's page logic—you need to build it yourself:

  1. Create a MentionedInfo object with MentionedType set to MentionedType.ALL.

    String targetId = "Group ID";
    MentionedInfo mentionedInfo = new MentionedInfo(MentionedInfo.MentionedType.ALL, null, null);
  2. Set the MentionedInfo object in the MessageContent.

    TextMessage messageContent = TextMessage.obtain(content);
    messageContent.setMentionedInfo(mentionedInfo);
    Message message = Message.obtain(targetId, ConversationType.GROUP, textMessage);
  3. Send the message using the IMCenter core class:

    IMCenter.getInstance().sendMessage(message, null , null, new IRongCallback.ISendMessageCallback(){
    @Override
    public void onAttached(Message message) {

    }

    @Override
    public void onSuccess(Message message) {

    }

    @Override
    public void onError(Message message, RongIMClient.ErrorCode errorCode) {

    }
    });

Disable @ Functionality

IMKit enables @ functionality by default. You can disable it globally via configuration:

RongConfigCenter.conversationConfig().rc_enable_mentioned_message = false;

To modify IMKit's default configuration via XML resources, create an rc_config.xml file in your app's res/values directory and add:

<bool name="rc_enable_mentioned_message">false</bool>