-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdirect-thread.feed.ts
33 lines (31 loc) · 982 Bytes
/
direct-thread.feed.ts
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
import { Expose } from 'class-transformer';
import { Feed } from '../core/feed';
import { DirectThreadFeedResponse, DirectThreadFeedResponseItemsItem } from '../responses';
export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThreadFeedResponseItemsItem> {
public id: string;
public seqId: number;
@Expose()
public cursor: string;
set state(body: DirectThreadFeedResponse) {
this.cursor = body.thread.oldest_cursor;
this.moreAvailable = body.thread.has_older;
}
async request() {
const { body } = await this.client.request.send<DirectThreadFeedResponse>({
url: `/api/v1/direct_v2/threads/${this.id}/`,
qs: {
visual_message_return_type: 'unseen',
cursor: this.cursor,
direction: 'older',
seq_id: this.seqId,
limit: 10,
},
});
this.state = body;
return body;
}
async items() {
const response = await this.request();
return response.thread.items;
}
}