Skip to main content

Browsing Threads

Inbox threads are stored in paginated body accounts. The current (live) body is at inbox.Inbox.index; older bodies are archives at lower indices. Each body holds a fixed number of thread IDs, and new bodies are created as the old ones fill up.

The simple case — latest threads

For a standard inbox list screen, load the current page and get the last N threads:

const inbox = await client.inbox(inboxAddress);

const threads = await inbox.loadThreads({
limit: 20,
includeLastMessage: true, // also fetch each thread's last message
});

This hits the live body page and returns threads in recency order (newest first).

Paginating across pages

If the current page doesn't have enough threads (it was recently created and is partially full), use loadThreadsAcrossBodies to walk backwards through pages until the limit is met:

const threads = await inbox.loadThreadsAcrossBodies({
limit: 50,
includeLastMessage: true,
maxPages: 10, // stop after this many pages regardless
});
FieldTypeDefaultDescription
limitnumberTarget number of threads to collect
includeLastMessagebooleanfalsePre-load each thread's latest message
maxPagesnumber5Hard cap on page fetches

This is the right method for "load more" pagination and full inbox views.

Manual page walking

For custom pagination (e.g. implementing infinite scroll with a cursor), you can work with pages directly:

// Load a specific page
const page = await inbox.loadBody(new BN(2));

// Load the page before a known index
const previous = await inbox.loadPreviousBody(new BN(3)); // loads page 2

Each page is an InboxBodyPageClient. To get threads from it:

const threads = await page.loadThreads({
limit: 20,
includeLastMessage: true,
});

Loading multiple pages in one call

// Load 3 pages starting from the current index and walking back
const pages = await inbox.loadBodies({ limit: 3 });
FieldTypeDescription
fromIndexBNStart page (defaults to current index)
limitnumberNumber of pages to load

loadThreads options

All loadThreads calls (on InboxClient, InboxBodyPageClient, ActivityClient) accept the same options:

FieldTypeDefaultDescription
offsetnumber0Start from this position within the segment (0 = newest)
limitnumberallMax threads to return
loadbooleantrueActually fetch thread accounts
includeLastMessagebooleanfalseAlso load the last message for each thread
concurrentFetchLimitnumberMax parallel thread fetches
concurrentMessageFetchLimitnumberMax parallel message fetches

Refreshing inbox state

When new threads arrive, the inbox's index and len change. Call refresh() to update:

await inbox.refresh();
// or clear the page cache too (forces all bodies to re-fetch):
await inbox.refresh({ clearPages: true });