world.loadMore()
Adds older messages at the start of messages and resolves to the number of messages it added.
loadMore(): Promise<number>
js
const added = await world.loadMore();Parameters
None.
Returns
A Promise that resolves to the number of messages added (at most 50 per call) or to 0 when no older messages are left.
The messages themselves reach your subscribe listener. They sit at the start of messages and keep the usual order from the oldest to the newest.
Usage
A "Load older messages" button
js
const older = document.createElement('button');
older.textContent = 'Load older messages';
older.onclick = async () => {
const added = await world.loadMore();
if (added === 0) older.remove(); // nothing older: hide the button
};
list.before(older);Keep the person's place
Because messages added at the top push the list down, the handler records the distance from the bottom before the call and restores it after the next render:
js
older.onclick = async () => {
const fromBottom = list.scrollHeight - list.scrollTop;
await world.loadMore();
requestAnimationFrame(() => {
list.scrollTop = list.scrollHeight - fromBottom;
});
};Caveats
- There may be none. Not every conversation keeps its older messages and a fake world never has any. The current version of the webapp keeps none for your view either and
loadMorealways resolves0in it. - Render the messages from
subscribeand use the number only to decide whether to offer the button again. - It sends nothing on behalf of the person. It only adds older messages to
messages.
Troubleshooting
| Code | Why | What to do |
|---|---|---|
'failed' | The webapp could not run the call (rare). | Keep the button for another attempt. |
See also
messages: the conversation from the oldest message to the newest.- The recipe Load older messages.