> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-audit-content-webhooks.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mentions

> Send, receive, and inspect CometChat mentioned messages in Flutter apps using user UIDs in one-on-one and group conversations.

Mentions are a powerful tool for enhancing communication in messaging platforms. They streamline interaction by allowing users to easily engage and collaborate with particular individuals, especially in group conversations.

Mentions in messages enable users to refer to specific individuals within a conversation.

## Send Mentioned Messages

Every User object has a String unique identifier associated with them which can be found in a property called uid. To mention a user in a message, the message text should contain the uid in following format: `<@uid:UID_OF_THE_USER>`. For example, to mention the user with UID cometchat-uid-1 in a text message, your text should be "`<@uid:cometchat-uid-1>`"

<Tabs>
  <Tab title="Flutter (User)">
    ```dart theme={null}
    String receiverID = "UID";
    User sender = User(name: "Sender", uid: "senderUID");
    String messageText = "Hello, <@uid:cometchat-uid-1>";
    String receiverType = CometChatReceiverType.user;

    TextMessage textMessage = TextMessage(
          text: messageText,
          sender: sender,
          receiverUid: receiverID,
          receiverType: receiverType,
    			category: CometChatMessageCategory.message,
          type: CometChatMessageType.text);

    CometChat.sendMessage(textMessage, onSuccess:(TextMessage textMessage) {
          print("Message sent successfully: ${textMessage.text}, mentioned users: ${textMessage.mentionedUsers}");
      },
       onError:(CometChatException e) {
          print("Message sending failed with exception: $e");
      }
    );
    ```
  </Tab>

  <Tab title="Flutter (Group)">
    ```dart theme={null}
    String receiverID = "GUID";
    User sender = User(name: "Sender", uid: "senderUID");
    String messageText = "Hello, <@uid:cometchat-uid-1>";
    String receiverType = CometChatReceiverType.group;

    TextMessage textMessage = TextMessage(
          text: messageText,
          sender: sender,
          receiverUid: receiverID,
          receiverType: receiverType,
    			category: CometChatMessageCategory.message,
          type: CometChatMessageType.text);

    CometChat.sendMessage(textMessage, onSuccess:(TextMessage textMessage) {
          print("Message sent successfully: ${textMessage.text}, mentioned users: ${textMessage.mentionedUsers}");
      },
       onError:(CometChatException e) {
          print("Message sending failed with exception: $e");
      }
    );
    ```
  </Tab>
</Tabs>

<Note>
  You can mention user in text message and media messages captions
</Note>

## 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.

| Setting                               | Description                                                                                                                                         | Default Value |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `mentionsWithTagInfo(bool 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.                    | false         |
| `mentionsWithBlockedInfo(bool 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. | false         |

## Mentions With Tag Info

To get a list of messages in a conversation where users are mentioned along with the tags of the mentioned users.

<Tabs>
  <Tab title="Flutter (User)">
    ```dart theme={null}
    String UID = "cometchat-uid-1";

    MessagesRequest messagesRequest = (MessagesRequestBuilder()
    ..limit=50
    ..uid=UID
    ..mentionsWithTagInfo(true))
    .build();

    messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
        for (BaseMessage message in messages){
          for (User user in message.mentionedUsers){
            print("mentioned user tags: ${user.tags}");
          }
        }
      },
    		onError: (CometChatException e) {
        print("error: $e");
      }
    );
    ```
  </Tab>

  <Tab title="Flutter (Group)">
    ```dart theme={null}
    String GUID = "cometchat-guid-1";

    MessagesRequest messagesRequest = (MessagesRequestBuilder()
    ..limit=50
    ..guid=GUID
    ..mentionsWithTagInfo(true))
    .build();

    messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
        for (BaseMessage message in messages){
          for (User user in message.mentionedUsers){
            print("mentioned user tags: ${user.tags}");
          }
        }
      },
    		onError: (CometChatException e) {
        print("error: $e");
      }
    );
    ```
  </Tab>
</Tabs>

## 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.

<Tabs>
  <Tab title="Flutter (User)">
    ```dart theme={null}
    String UID = "cometchat-uid-1";

    MessagesRequest messagesRequest = (MessagesRequestBuilder()
    ..limit=50
    ..uid=UID
    ..mentionsWithBlockedInfo(true))
    .build();

    messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
        for (BaseMessage message in messages){
          for (User user in message.mentionedUsers){
            print("mentioned user has blocked me? ${user.hasBlockedMe}");
            print("mentioned user is blocked by me? ${user.blockedByMe}");
          }
        }
      },
    		onError: (CometChatException e) {
        print("error: $e");
      }
    );
    ```
  </Tab>

  <Tab title="Flutter (Group)">
    ```dart theme={null}
    String GUID = "cometchat-guid-1";

    MessagesRequest messagesRequest = (MessagesRequestBuilder()
    ..limit=50
    ..guid=GUID
    ..mentionsWithBlockedInfo(true))
    .build();

    messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
        for (BaseMessage message in messages){
          for (User user in message.mentionedUsers){
            print("mentioned user has blocked me? ${user.hasBlockedMe}");
            print("mentioned user is blocked by me? ${user.blockedByMe}");
          }
        }
      },
    		onError: (CometChatException e) {
        print("error: $e");
      }
    );
    ```
  </Tab>
</Tabs>

## Get Users Mentioned In a Particular Message

To retrieve the list of users mentioned in the particular message, you can use the `mentionedUsers` property on any `BaseMessage`. This property will return an array containing User objects of the mentioned users, or an empty array if no users were mentioned in the message.

<Tabs>
  <Tab title="Syntax">
    ```dart theme={null}
    message.mentionedUsers
    ```
  </Tab>
</Tabs>

## 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` property on any `BaseMessage`. This property will return a boolean value, true if the logged-in user has been mentioned, otherwise `false`.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    message.hasMentionedMe
    ```
  </Tab>
</Tabs>
