Skip to main content

Overview

Fetches the authenticated user’s conversation list with cursor-based pagination. Conversations are sorted by most recent activity. The hook also exposes a createGroup function to create new group conversations.
Requires ChatProvider in the component tree.

Usage Example

Props

ConversationType[]
Only conversations of these types: any of "direct", "group", "space". If omitted, all types are returned.

Returns

ConversationPreview[]
The loaded conversations sorted by most recent activity. Each item is a Conversation extended with unreadCount, a truncated lastMessage, and otherMembers — up to 5 active members other than the current user (public fields id, name, username, avatar), populated for direct/group conversations so a DM/group row can render the counterparty’s name and avatar. Capped at 5 (use memberCount for the group total); empty for space conversations.
boolean
true while a fetch is in progress.
SublayError | null
The last load failure, or null. Cleared when the next load starts; loadMore() retries it. Shared by every mounted hook showing the inbox. A SublayError.
boolean
true while loadMore() has something to fetch: a next page, or a load that failed.
() => Promise<void>
Fetches the next page of conversations and appends it, or retries the load that failed (a failed first page is retried as the first page). Does nothing while a page is loading or when there is nothing more. Never rejects: a failure lands in error.
() => Promise<void>
Reloads the first page of conversations. The loaded conversations stay until the new first page replaces them. Never rejects: a failure lands in error.
(params: { name?: string; description?: string; metadata?: Record<string, unknown>; memberIds?: string[]; avatarFile?: { file: UploadFileInput; options: UploadImageOptions } }) => Promise<Conversation>
Creates a new group conversation and resolves to the created Conversation. The group’s inbox row (its ConversationPreview) is then fetched and added to conversations; if that fetch fails, the group is still created and the next refetch lists it. name is up to 200 characters and description up to 1000. Pass memberIds to add initial members in the same request — the server creates their member rows in one transaction. The creator is added as admin automatically and is de-duplicated if also present in memberIds. Pass avatarFile (a browser File or Blob, or a React Native { uri, name, type }, plus its processing options with a mode; see Image Processing Modes) to give the group its avatar in the same request: it is then sent as multipart/form-data, and needs the files-images bundle.

Notes

  • The initial fetch runs on mount. Re-runs automatically when the authenticated project changes, and the first page reloads by itself after the chat socket reconnects.
  • New messages received via socket update the lastMessage and lastMessageAt of the relevant conversation in the list automatically — no refetch needed.
  • For integration guidance, see Chat: Conversations.