Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Mentions let users refer to specific individuals in a conversation using the <@uid:UID> format. They’re especially useful in group chats for directing messages at particular participants.

Send Mentioned Messages

To mention a user, embed <@uid:UID> in your message text. For example: "Hello <@uid:cometchat-uid-1>". The sendMessage() method returns a TextMessage object on success.
private val receiverID = "UID"
private val messageText = "Hello <@uid:cometchat-uid-1>"
private val receiverType = CometChatConstants.RECEIVER_TYPE_USER

val textMessage = TextMessage(receiverID, messageText, receiverType)
CometChat.sendMessage(textMessage, object : CallbackListener<TextMessage>() {
  override fun onSuccess(textMessage: TextMessage) {
      Log.d(TAG, "Message sent successfully: $textMessage")
  }

  override fun onError(e: CometChatException) {
      Log.d(TAG, "Message sending failed with exception: " + e.message)
  }
})
You can mention user in text message and media messages captions

Mentioned Messages

By default, the SDK will fetch all the messages irrespective of the fact that the logged-in user is mentioned or not in the message. The SDK has other optional filters such as tag info and blocked info. For more filtering options, see Additional Message Filtering.
SettingDescription
mentionsWithTagInfo(boolean value)If set to true, SDK will fetch a list of messages where users are mentioned & will also fetch the tags of the mentioned users. Default value = false.
mentionsWithBlockedInfo(boolean value)If set to true, SDK will fetch a list of messages where users are mentioned & will also fetch their blocked relationship with the logged-in user. Default value = false.

Mentions With Tag Info

To get a list of messages in a conversation where users are mentioned along with the user tags of the mentioned users.
val UID = "cometchat-uid-1"

val messagesRequest = MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .mentionsWithTagInfo(true)
  .build()

messagesRequest.fetchPrevious(object : CometChat.CallbackListener<List<BaseMessage>>() {
  override fun onSuccess(messages: List<BaseMessage>) {
      for (messageObj in messages) {
          for (user in messageObj.mentionedUsers) {
              Log.e(TAG, "tag: ${user.tags}")
          }
      }
  }

  override fun onError(e: CometChatException) {
      Log.e(TAG, "onError: " + e)
  }
})

Mentions With Blocked Info

To get a list of messages in a conversation where users are mentioned along with the blocked relationship of the mentioned users with the logged-in user.
val UID = "cometchat-uid-1"

val messagesRequest = MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .mentionsWithBlockedInfo(true)
  .build()

messagesRequest.fetchPrevious(object : CometChat.CallbackListener<List<BaseMessage>>() {
  override fun onSuccess(messages: List<BaseMessage>) {
      for (messageObj in messages) {
          for (user in messageObj.mentionedUsers) {
              Log.e(TAG, "isBlockedByMe: ${user.isBlockedByMe}")
              Log.e(TAG, "isHasBlockedMe: ${user.isHasBlockedMe}")
          }
      }
  }

  override fun onError(e: CometChatException) {
      Log.e(TAG, "onError: " + e)
  }
})

Get Mentioned Users from a Message

Use getMentionedUsers() on any message object to retrieve the list of User objects mentioned in it. Returns an empty list if no users were mentioned.
message.getMentionedUsers()

Check if Logged-in user has been mentioned

To check if the logged-in user has been mentioned in a particular message we can use the hasMentionedMe() method on any BaseMessage. This method will return a boolean value, true if the logged-in user has been mentioned, otherwise false.
message.hasMentionedMe

Next Steps

Send Messages

Learn how to send text, media, and custom messages

Receive Messages

Handle incoming messages with real-time listeners

Interactive Messages

Create messages with embedded forms and interactive elements

Retrieve Users

Fetch user lists to enable mention autocomplete