AI Integration Quick Reference
AI Integration Quick Reference
Pinning a message with the SDK requires the Pin Message feature to be enabled for your app. You can check its availability at runtime using the feature flag.
Pin a Message
To pin a message, use thepinMessage method and pass the ID of the message to be pinned. On success, the callback returns the updated BaseMessage with its pin attributes set.
- Java
- Kotlin
getPinnedBy() and getPinnedAt() to the most recent pinner rather than failing.
Pinning is a moderation action and the server is the authority: a user without pin permission is rejected with
ERR_PERMISSION_DENIED. There is no client-side role gate — the CometChat UI Kits show the Pin/Unpin option to every participant and surface a “you don’t have permission” toast on that error, so build your own UI the same way rather than trying to predict the verdict. Every participant can see pinned messages. Deleted messages cannot be pinned; deleting a pinned message automatically unpins it.Unpin a Message
To unpin a message, use theunpinMessage method. Any participant with pin permission can unpin a message — not just the user who originally pinned it. On success, the callback returns the updated BaseMessage with its pin attributes cleared.
- Java
- Kotlin
Fetch Pinned Messages
To fetch all pinned messages of a conversation, create aMessagesRequest with the setPinned(true) filter of the MessagesRequestBuilder. Setting a UID (for a one-on-one conversation) or a GUID (for a group) is mandatory — exactly one of the two. The returned list is sorted by the time of pinning, most recently pinned first.
- Java (User)
- Java (Group)
- Kotlin (User)
- Kotlin (Group)
fetchNext() until a call returns an empty list; the cursor rides on pinnedAt instead of sentAt, and the SDK swaps it for you.
Check if a Message is Pinned
Every fetched or received message carries its pin state on theBaseMessage itself.
- Java
- Kotlin
Editing a message preserves its pin. A message stores only its most recent pinner in
getPinnedBy().Real-time Pin Events
Register aMessageListener and override the pin callbacks. Each event delivers the full updated BaseMessage, so you can directly replace the message in your list.
Today these callbacks fire on the acting user’s device when a pin or unpin succeeds. Delivery to other participants activates once server-side real-time delivery for pin events is rolled out — until then, other clients pick up pin changes on their next message fetch.
- Java
- Kotlin
CometChat.removeMessageListener(listenerID).
Pin Limit
A conversation holds a capped number of pins, configurable per app. Read the cap rather than hard-coding it — it is tenant-overridable and will drift.- Java
- Kotlin
Settings.LIMIT_UNSPECIFIED (-1) when the app settings carry no value or when they are called before init() completes — show generic copy in that case rather than guessing a number. getSystemPinMessageLimit() is the separate cap for admin/global pins: system pins do not consume a user’s allowance, so the two budgets are enforced independently.
When the limit is breached, the SDK surfaces the server error through onError, and the applicable limit is carried in the exception’s errorParams so you can tell the user the actual number without a second call.
- Java
- Kotlin
Error Handling
Feature Availability
Check whether the Pin Message feature is enabled for your app before showing pin actions in your UI. The method is synchronous and safe to call from the UI layer.- Java
- Kotlin
Next Steps
Save A Message
Bookmark a message privately, across conversations
Pin A Conversation
Pin a conversation to the top of the list
All Real Time Listeners
Every listener the SDK exposes, in one place
Additional Message Filtering
Filter messages by pinned, saved, type, tags and more