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.

// Send a message with a mention (use <@uid:UID> format)
let msg = TextMessage(receiverUid: "UID", text: "Hello <@uid:cometchat-uid-1>", receiverType: .user)
CometChat.sendTextMessage(message: msg) { message in } onError: { error in }

// Get mentioned users from a message
let mentionedUsers = message.mentionedUsers  // Returns [User]

// Check if logged-in user was mentioned
let wasMentioned = message.mentionedMe  // Returns Bool

// Fetch messages with mention tag info
let request = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder()
    .set(uid: "UID").set(limit: 30).mentionsWithTagInfo(true))
request.fetchPrevious { messages in } onError: { error in }
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.

Mention Format

FormatExample
<@uid:USER_UID><@uid:cometchat-uid-1>
Example message text with mention:
"Hello <@uid:cometchat-uid-1>, how are you?"

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>.
let messageText = "Hello <@uid:cometchat-uid-1>, how are you?"
let textMessage = TextMessage(receiverUid: "cometchat-uid-2", text: messageText, receiverType: .user)

CometChat.sendTextMessage(message: textMessage) { message in
    print("Mentioned users: \(message.mentionedUsers)")
} onError: { error in
    print("Error: \(error?.errorDescription)")
}
You can mention users in text messages and media message captions.

Fetch Mentioned Messages

By default, the SDK will fetch all messages irrespective of whether the logged-in user is mentioned or not. The SDK allows you to fetch messages with additional mention information.
SettingDescription
mentionsWithTagInfo(true)Fetch messages with mentioned users’ tags
mentionsWithBlockedInfo(true)Fetch messages with blocked relationship info

Mentions With Tag Info

let messagesRequest = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder()
    .set(uid: "cometchat-uid-2")
    .set(limit: 50)
    .mentionsWithTagInfo(true))

messagesRequest.fetchPrevious { messages in
    for message in messages ?? [] {
        for user in message.mentionedUsers {
            print("User tags: \(user.tags)")
        }
    }
} onError: { error in
    print("Error: \(error?.errorDescription)")
}

Mentions With Blocked Info

let messagesRequest = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder()
    .set(uid: "cometchat-uid-2")
    .set(limit: 50)
    .mentionsWithBlockedInfo(true))

messagesRequest.fetchPrevious { messages in
    for message in messages ?? [] {
        for user in message.mentionedUsers {
            print("Has blocked me: \(user.hasBlockedMe)")
            print("Blocked by me: \(user.blockedByMe)")
        }
    }
} onError: { error in
    print("Error: \(error?.errorDescription)")
}

Get Users Mentioned In a Message

To retrieve the list of users mentioned in a particular message. Returns an array of User objects:
let mentionedUsers = message.mentionedUsers  // Returns [User]
Mentioned Users Array:
IndexUIDName
0"cometchat-uid-1""John Doe"
1"cometchat-uid-3""Jane Smith"

Check if Logged-in User Was Mentioned

To check if the logged-in user has been mentioned in a particular message:
let wasMentioned = message.mentionedMe  // Returns Bool
PropertyTypeDescription
mentionedMeBooltrue if logged-in user was mentioned

Mentioned User Properties

PropertyTypeDescription
uidStringUnique user identifier
nameStringUser’s display name
avatarString?User’s avatar URL
tags[String]User’s tags (with mentionsWithTagInfo)
hasBlockedMeBoolHas user blocked logged-in user (with mentionsWithBlockedInfo)
blockedByMeBoolIs user blocked by logged-in user (with mentionsWithBlockedInfo)

Next Steps

Send Messages

Send text, media, and custom messages

Receive Messages

Listen for incoming messages in real time

Reactions

Add emoji reactions to messages

Threaded Messages

Organize conversations with message threads