UIKit Android v3
UIKit Android
UIKit
Android
Home
/
UIKit
/
Android
This is the new Docs for UIKit v3 for Android. To see the previous Docs, click here.

Mention

Mention is a feature that allows users to call out each other in a message within a group channel. Users can mention other members in the group channel to get their attention and directly notify that they've been mentioned in a message.


Limitations

The mention feature currently has the following limitations:

  • Mention is available for group channels only.
  • User is the only mention type that Sendbird UIKit provides.
  • Users can only mention other users in the same channel.
  • Users can have up to 10 mentions in a single message.

How to use

To turn on the feature, refer to the code below:

public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        // Turn on mention.
        SendbirdUIKit.setUseUserMention(true);
    }
}

Configure mention settings

The mention feature has basic settings that you can customize when implementing it in your client app. The following setter methods must be configured before using the feature.

List of setter methods

MethodDescription

setUseUserMention

Determines whether to turn on the mention feature. (Default: false)

setMaxMentionCount

Sets the maximum number of times a user can mention another user in a single message. (Default: 10)

setMaxSuggestionCount

Sets the maximum number of users shown in a suggested mention list. (Default: 15)

The maximum number of mentions you can have for a single user or multiple users in one message is 10 and the maximum number of users shown in a suggested mention list is set to 15 by default. These numbers are customizable through setMentionConfig, which contains setMaxMentionCount() and setMaxSuggestionCount() methods.

public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        SendbirdUIKit.setMentionConfig(new UserMentionConfig.Builder()
            .setMaxMentionCount(10)
            .setMaxSuggestionCount(15)
            .build());
    }
}

Configure MentionEditText

The MentionEditText widget allows you to set how the mention feature is displayed in the MessageListComponent of ChannelModule. After detecting @ as the trigger keyword for the mention feature, it shows a list of suggested users to mention in the channel. See the code below on how to configure the widget.

<com.sendbird.uikit.widgets.MentionEditText
    android:id="@+id/etInputText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    …>
</com.sendbird.uikit.widgets.MentionEditText>

Mention a user

Users can mention other users in the same channel by either searching for the channel member or typing in the user's nickname. When a user types @ in the MessageInputComponent of ChannelModule, a suggested mention list view appears in the MessageListComponent of the group channel screen. The suggested mention list contains a scrollable list of all channel members by their nickname or user ID. The list also appears while the user types the nickname of a channel member. As the nickname is being typed, the list sorts the nicknames alphabetically in real-time.

Suggested mention list

The suggested mention list shows an alphabetical list of all channel members that you can mention in a message. The list creates a RecyclerView in the MessageListComponent. To create the view of each mention list item, you need to use SuggestedMentionListAdapter and bind channel member data to the view. For each member in the list, the profile image and nickname are shown. You can choose to display either just the nickname or both nickname and user ID. The suggested mention list disappears once a user has been successfully mentioned in a message or when there's no matching nickname found in the list. If there's a typo while typing in a user's nickname or if the user's not a member of the current group channel, the mention list also disappears.

See the code below on how to show both the user ID and nickname of a user in the suggested mention list.

ChannelListFragment fragment = new ChannelListFragment.Builder()
    .setSuggestedMentionListAdapter(new SuggestedMentionListAdapter(true))
    .build();

You can customize SuggestedMentionListAdapter if you wish to update or change an item in the suggested mention list. After customizing the SuggestedMentionList class, you can apply it to the CustomChannelFragment. To learn how to customize SuggestedMentionListAdapter, see the update or change an item in a list page.

Mention input

When you type @ and a user nickname in the MessageInputComponent of ChannelModule, the suggested mention list appears. While the list can display both nickname and user ID, you can only type nicknames in the message input field to mention a user. The same user can be mentioned up to 10 times per message by default and the text of each user mention is bolded.


Receive a mention

When a user is mentioned in a message, the unread message count in the ChannelListComponent of ChannelListModule increases by the number of unread mentioned messages. The unreadMentionCount property specifies the number of unread mentioned messages in a channel and gets added to the total unread message count. A mention badge also appears to the left of the unread message count number to indicate that the user has been mentioned in the unread message. Regardless of the number of unread mentioned messages, if there's at least one unread mentioned message in a channel, the mention badge appears in the channel list.

Once the user taps on the channel with the unread mentioned message, they can see all the messages in the MessageListComponent of ChannelModule where the highlighted user's nickname appears. The nickname is highlighted only in messages that mention the current user.

User profile

Users can tap on each mentioned nickname in a message to see the user profile of the mentioned channel member. The user profile includes a profile image, nickname, and user ID.


Push notifications for mentions

The option to turn on notifications for mentions only has been added to the ChannelPushSettingComponent of ChannelPushSettingModule. If you turn on push notifications for the channel using the toggle button, two options will appear below: all new messages and mentions only. All new messages include notifications for both non-mentioned messages and mentioned messages, whereas mentions only refer to notifications for just mentioned messages.


Customize the UI

You can customize the UI for mention in the messageInputComponent of ChannelModule, the ChannelListComponent of ChannelListModule, and the ChannelPushSettingComponent of ChannelPushSettingModule through the style resource, string resource, and icon resource.

Style resource

To customize the style of mention items, you have to change the UIKit-defined style values in the res/values/styles.xml file as shown below. To learn how to customize the style, refer to style resource.

<style name="Module.ChannelPushSetting">
</style>
<style name="Component.Header.ChannelPushSetting">
</style>
<style name="Component.ChannelPushSetting">
</style>
<style name="Widget.Sendbird.SuggestedMentionPreview">
</style>
<style name="Widget.Sendbird.Snackbar">
</style>

String resource

The texts in the message input field and the channel notification settings view can be customized through the string resource. The string resource is a set of strings used to compose a view. It's a res/strings.xml file containing UIKit-defined string values.

<resources>
    <string name="sb_text_channel_settings_notification">Notifications</string>
    <string name="sb_text_exceed_mention_limit_count">"You can have up to %d mentions per message."</string>
    <string name="sb_text_push_setting_on">On</string>
    <string name="sb_text_push_setting_off">Off</string>
    <string name="sb_text_push_setting_mentions_only">Mentions only</string>
    <string name="sb_text_push_setting_option_all">All new messages</string>
    <string name="sb_text_push_setting_description">Turn on to receive notifications when messages are delivered to this channel.</string>
</resources>

Icon resource

The following table shows customizable mention icons.

IconImageDescription

icon_info

An icon used to indicate that the user has reached the maximum mention count in a single message.

icon_radio_button_on

An icon used to indicate that either All new messages or Mentions only is turned on for receiving push notifications.

icon_radio_button_off

An icon used to indicate that either All new messages or Mentions only is turned off for receiving push notifications.