Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
feat(notes): support for crossbell note pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 26, 2022
1 parent eb5dd8a commit 5c8ff6f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/notes/crossbell-note.ts
Expand Up @@ -69,8 +69,20 @@ class CrossbellNote extends Base {
}
}

const total = events.length;
let hasMore;

events = events.reverse();
if (options.cursor) {
events = events.slice(options.cursor);
}
if (options.limit) {
hasMore = events.length > options.limit;
events = events.slice(0, options.limit);
}

const list = await Promise.all(
events.reverse().map(async (event: any) => {
events.map(async (event: any) => {
const profileId = event.args.profileId.toString();
const nodeId = event.args.noteId.toString();
const note = (await this.contract.getNote(profileId, nodeId, 'AnyUri')).data;
Expand Down Expand Up @@ -131,7 +143,9 @@ class CrossbellNote extends Base {
);

return {
total: list.length,
total,
...(hasMore && { cursor: (options.cursor || 0) + options.limit }),

list: list,
};
}
Expand Down

0 comments on commit 5c8ff6f

Please sign in to comment.