Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
// 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 messagelet mentionedUsers = message.mentionedUsers // Returns [User]// Check if logged-in user was mentionedlet wasMentioned = message.mentionedMe // Returns Bool// Fetch messages with mention tag infolet 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.
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>.
Swift (User)
Swift (Group)
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)")}
let messageText = "Hey <@uid:cometchat-uid-2>, check this out!"let textMessage = TextMessage(receiverUid: "cometchat-guid-1", text: messageText, receiverType: .group)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.
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.
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)")}
let messagesRequest = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder() .set(guid: "cometchat-guid-1") .set(limit: 50) .mentionsWithTagInfo(true))messagesRequest.fetchNext { messages in for message in messages ?? [] { for user in message.mentionedUsers { print("User tags: \(user.tags)") } }} onError: { error in print("Error: \(error?.errorDescription)")}
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)")}