Saving a message with the SDK requires the Save Message feature to be enabled for your app. You can check its availability at runtime using the feature flag.
Save a Message
To save a message, use thesaveMessage method and pass the ID of the message. On success, the callback returns the updated BaseMessage with its savedAt attribute set.
- Java
- Kotlin
Unlike pinning, saving has no role restrictions — every user can save any message they have access to. Deleted messages cannot be saved.
Unsave a Message
To remove a message from the user’s saved list, use theunsaveMessage method. On success, the callback returns the updated BaseMessage with its savedAt attribute cleared.
- Java
- Kotlin
Fetch Saved Messages
To fetch all messages the logged-in user has saved, create aMessagesRequest with the setSaved(true) filter of the MessagesRequestBuilder. Because saved messages are user-level and span conversations, you must not set a UID or GUID. The returned list is sorted by the time of saving, most recently saved first.
- Java
- Kotlin
If the user loses access to a conversation (for example, they are removed from a group), messages saved from it are cleaned up and no longer returned.
Check if a Message is Saved
Every fetched message carries the logged-in user’s save state on theBaseMessage itself. These values are per-user: the same message shows different values to different users.
- Java
- Kotlin
Real-time Save Events
Because saving is private, save events are never delivered to other participants. Register aMessageListener and override the save callbacks; each event delivers the full updated BaseMessage.
Today these callbacks fire on the acting device when a save or unsave succeeds. Delivery to the user’s other devices activates once server-side real-time delivery for save events is rolled out — until then, other sessions pick up save changes on their next fetch.
- Java
- Kotlin
CometChat.removeMessageListener(listenerID).
Feature Availability
Check whether the Save Message feature is enabled for your app before showing save actions in your UI. The method is synchronous and safe to call from the UI layer.- Java
- Kotlin