useThreads
List a built-app user's private message threads, with unread counts and consent control.
import { useThreads } from 'flowstack-sdk'Lists the authenticated user's private DM threads from the server-owned, ACL'd DM store — the backend only ever returns threads the caller participates in. Each thread carries the counterpart's user key, the last message, and an unread count.
Private messaging is a built-app capability: it requires an appScope on the FlowstackProvider config. In a Casino personal session the backend returns 403 and this hook surfaces an error. Treat the type signatures in packages/flowstack-sdk/src/hooks/useThreads.ts as the source of truth.
Signature
const { threads, isLoading, error, refresh, openThread } = useThreads(options?)Parameters
| Param | Type | Notes | Description |
|---|---|---|---|
options.refreshInterval | number | since 0.2.2 | Auto-poll interval in ms. No polling by default. |
options.enabled | boolean | default true, since 0.2.2 | Set false to skip the initial fetch. |
Returns
| Field | Type | Description |
|---|---|---|
threads | DmThread[] | The caller's threads — each { pair_key, with_user_key, status, last_message, unread_count, updated_at }. |
isLoading | boolean | True while a fetch is in flight. |
error | string | null | Error message, e.g. a 403 when used outside a built-app (no appScope). |
refresh | () => Promise<void> | Refetch the thread list. |
openThread | (withUserKey: string) => Promise<'pending' | 'open' | null> | Record the caller's consent to open a thread. The thread becomes sendable only once BOTH parties consent. Idempotent per caller; refetches on success. |
Examples
const { threads, isLoading, openThread } = useThreads({ refreshInterval: 5000 });
threads.map((t) => (
<ThreadRow key={t.pair_key} counterpart={t.with_user_key} unread={t.unread_count} />
));
// Consent to open a new conversation
const status = await openThread(otherUserKey); // 'pending' | 'open' | nullappScope. Outside a built app the backend returns 403 and error is set.See also
useMessages · listThreads · openThread · DmThread
Source: README.md#private-messaging-dms · Also available in llms-full.txt and registry.json.