-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathReactionPaginator.ts
More file actions
74 lines (64 loc) · 1.52 KB
/
ReactionPaginator.ts
File metadata and controls
74 lines (64 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
BasePaginator,
type PaginationQueryParams,
type PaginatorOptions,
type ReactionFilters,
type ReactionResponse,
type ReactionSort,
type StreamChat,
} from 'stream-chat';
export class ReactionPaginator extends BasePaginator<ReactionResponse> {
private client: StreamChat;
private messageId: string;
private _filters: ReactionFilters;
private _sort: ReactionSort;
protected usesCursorPagination = true;
get filters(): ReactionFilters | undefined {
return this._filters;
}
get sort(): ReactionSort | undefined {
return this._sort;
}
set filters(filters: ReactionFilters) {
this._filters = filters;
this.invalidate();
}
set sort(sort: ReactionSort) {
this._sort = sort;
this.invalidate();
}
constructor({
client,
messageId,
options,
}: {
client: StreamChat;
messageId: string;
options?: PaginatorOptions;
}) {
super(options);
this.client = client;
this.messageId = messageId;
this._filters = {};
this._sort = { created_at: -1 };
}
async query(params: PaginationQueryParams) {
const direction = params.direction;
const response = await this.client.queryReactions(
this.messageId,
this._filters,
this._sort,
{
[direction]: direction === 'next' ? params.next : params.prev,
limit: this.pageSize,
},
);
return {
items: response.reactions,
next: response.next,
};
}
public filterQueryResults(items: ReactionResponse[]) {
return items;
}
}