> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-android-pin-save-thread.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Saved Messages

> Full-screen, private list of every message the logged-in user has saved, across all of their conversations.

<Accordion title="AI Integration Quick Reference">
  ```json theme={null}
  {
    "component": "CometChatSavedMessages",
    "package": "com.cometchat.uikit.kotlin.presentation.savedmessages (XML Views) / com.cometchat.uikit.compose.presentation.savedmessages.ui (Compose)",
    "xmlElement": "<com.cometchat.uikit.kotlin.presentation.savedmessages.CometChatSavedMessages />",
    "description": "Full-screen, private list of every message the logged-in user has saved across all conversations, with conversation-style rows, jump-to-message and long-press unsave.",
    "primaryOutput": {
      "messageClicked": {
        "method": "setOnMessageClickListener",
        "type": "(BaseMessage) -> Unit"
      }
    },
    "methods": {
      "callbacks": {
        "setOnMessageClickListener": "(BaseMessage) -> Unit — row tapped; open the source conversation at the message",
        "setOnBackClickListener": "() -> Unit — toolbar back pressed"
      }
    },
    "composeParams": {
      "onMessageClick": "(BaseMessage) -> Unit",
      "onBackClick": "() -> Unit"
    },
    "note": "User-level — no setUser/setGroup. Rows span all of the user's conversations.",
    "events": ["CometChatMessageEvent.MessageSaved", "CometChatMessageEvent.MessageUnsaved"],
    "featureFlag": "CometChatUIKit.isSaveMessageEnabled()"
  }
  ```
</Accordion>

## Where It Fits

`CometChatSavedMessages` is a full-screen component that lists every message the logged-in user has bookmarked, most recently saved first. Saved messages are **private to the user** and **span all of their conversations**, so this screen is user-level: open it from your app's chrome — a profile menu, the conversations screen's user menu, or a navigation tab — not from inside a single chat. There is no `setUser`/`setGroup`; the scope is always the logged-in user.

Messages are saved and unsaved from the [Message List](/ui-kit/android/message-list) action sheet; this screen is the read view, plus a long-press **Unsave** action on each row.

<Note>
  Saved messages require the **Save Message** feature to be enabled for your app. Gate your entry point with `CometChatUIKit.isSaveMessageEnabled()`.
</Note>

## Quick Start

<Tabs>
  <Tab title="Kotlin (XML Views)">
    Add the component to your layout XML:

    ```xml activity_saved_messages.xml lines theme={null}
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.cometchat.uikit.kotlin.presentation.savedmessages.CometChatSavedMessages
            android:id="@+id/saved_messages"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>
    ```

    Wire the callbacks:

    ```kotlin SavedMessagesActivity.kt lines theme={null}
    class SavedMessagesActivity : AppCompatActivity() {

        private lateinit var savedMessages: CometChatSavedMessages

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_saved_messages)

            savedMessages = findViewById(R.id.saved_messages)

            savedMessages.setOnMessageClickListener { message ->
                // Open the source conversation at this message. Resolve the peer from
                // the message: group -> message.receiver as Group; one-on-one -> the
                // sender if it isn't the logged-in user, otherwise the receiver.
            }

            savedMessages.setOnBackClickListener { finish() }
        }
    }
    ```
  </Tab>

  <Tab title="Jetpack Compose">
    ```kotlin lines theme={null}
    CometChatSavedMessages(
        onMessageClick = { message ->
            // Open the source conversation at this message
        },
        onBackClick = { navController.popBackStack() }
    )
    ```
  </Tab>
</Tabs>

## Actions and Events

### Callback Methods

| Method (Views) / Param (Compose)               | Description                                                                                                     |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `setOnMessageClickListener` / `onMessageClick` | Fired when a row is tapped. Receives the `BaseMessage`; open its source conversation and scroll to the message. |
| `setOnBackClickListener` / `onBackClick`       | Fired when the toolbar back button is pressed.                                                                  |

### SDK Events (Real-Time, Automatic)

The list keeps itself up to date on this device — saving or unsaving a message anywhere in the app adds or removes the row without a refetch, via the `MessageSaved` / `MessageUnsaved` events on the UI Kit event bus; see [Events](/ui-kit/android/events). Changes made on the user's other devices appear when the list is next opened or refetched (server-side real-time delivery for save events is pending rollout).

## Functionality

* **Conversation-style rows** — because saved messages come from many conversations, each row shows where the message lives: the peer's or group's avatar and name, a message preview with its type icon, and the sent date. This mirrors a conversation list row (without the unread badge).
* **Unsave** — long-press a row to get the **Unsave** action; a toast confirms the result.
* **Jump to message** — tapping a row emits the message through the click callback. Use the message's receiver type and receiver to resolve which conversation to open.
* **Empty state** — a built-in empty state ("No saved messages yet") is shown when the user has not saved anything.
* **Private and read-only** — nobody else can see a user's saved messages; the screen never marks messages as read and does not affect unread counts or receipts.

## ViewModel

The screen is backed by `CometChatSavedMessagesViewModel` (in the shared core module), which fetches via `MessagesRequestBuilder().setSaved(true)`, applies optimistic unsave with revert-on-error, and observes the event bus for live upkeep. In Compose you can inject your own instance through the `viewModel` parameter.

## Next Steps

* [Message List](/ui-kit/android/message-list) — where messages are saved and unsaved, and where the bubble saved indicator appears.
* [Pinned Messages](/ui-kit/android/pinned-messages) — the conversation-wide counterpart.
* [Save A Message (SDK)](/sdk/android/v5/save-message) — the underlying SDK APIs.
