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
});
| Field | Type | Default | Description |
|---|---|---|---|
limit | number | — | Target number of threads to collect |
includeLastMessage | boolean | false | Pre-load each thread's latest message |
maxPages | number | 5 | Hard 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 });
| Field | Type | Description |
|---|---|---|
fromIndex | BN | Start page (defaults to current index) |
limit | number | Number of pages to load |
loadThreads options
All loadThreads calls (on InboxClient, InboxBodyPageClient, ActivityClient) accept the same options:
| Field | Type | Default | Description |
|---|---|---|---|
offset | number | 0 | Start from this position within the segment (0 = newest) |
limit | number | all | Max threads to return |
load | boolean | true | Actually fetch thread accounts |
includeLastMessage | boolean | false | Also load the last message for each thread |
concurrentFetchLimit | number | — | Max parallel thread fetches |
concurrentMessageFetchLimit | number | — | Max 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 });