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
In a group conversation, the CometChat UI Kits show the Pin/Unpin option only to participants with the Admin or Moderator scope, or the group owner. This gate is applied client-side — the SDK does not currently enforce roles on the server, so apply your own role check if you build custom pin UI. Every participant can see pinned messages. In a one-on-one conversation, both participants can pin and unpin. 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)
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 can hold a limited number of pinned messages (100 by default). When the limit is exceeded, the SDK surfaces the server error throughonError, and the applicable limit can be read programmatically from the exception — never hard-code it.
- Java
- Kotlin
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