Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add options object to specify custom params for feed.items() #1264

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/core/feed.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,23 @@ export class FeedFactory {
return new BlockedUsersFeed(this.client);
}

public directInbox(): DirectInboxFeed {
return new DirectInboxFeed(this.client);
public directInbox(options: { limit?: number; thread_message_limit?: number } = {}): DirectInboxFeed {
return plainToClassFromExist(new DirectInboxFeed(this.client), options);
}

public directPending(): DirectPendingInboxFeed {
return new DirectPendingInboxFeed(this.client);
public directPending(options: { limit?: number; thread_message_limit?: number } = {}): DirectPendingInboxFeed {
return plainToClassFromExist(new DirectPendingInboxFeed(this.client), options);
}

public directThread(
options: Pick<DirectInboxFeedResponseThreadsItem, 'thread_id' | 'oldest_cursor'>,
options: Pick<DirectInboxFeedResponseThreadsItem, 'thread_id' | 'oldest_cursor'> & { limit: number },
seqId?: number,
): DirectThreadFeed {
const feed = new DirectThreadFeed(this.client);
feed.id = options.thread_id;
feed.cursor = options.oldest_cursor;
feed.seqId = seqId;
feed.limit = options.limit;
return feed;
}

Expand Down
6 changes: 4 additions & 2 deletions src/feeds/direct-inbox.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class DirectInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFe
@Expose()
private seqId: number;

public limit?: number;
public thread_message_limit?: number;
set state(body: DirectInboxFeedResponse) {
this.moreAvailable = body.inbox.has_older;
this.seqId = body.seq_id;
Expand All @@ -23,9 +25,9 @@ export class DirectInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFe
cursor: this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
thread_message_limit: 10,
thread_message_limit: this.thread_message_limit ?? 10,
persistentBadging: true,
limit: 20,
limit: this.limit ?? 20,
},
});
this.state = body;
Expand Down
6 changes: 4 additions & 2 deletions src/feeds/direct-pending.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class DirectPendingInboxFeed extends Feed<DirectInboxFeedResponse, Direct
@Expose()
private seqId: number;

public limit?: number;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the default values here instead of using ?? operator below

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same for another feeds

public thread_message_limit?: number;
set state(body: DirectInboxFeedResponse) {
this.moreAvailable = body.inbox.has_older;
this.seqId = body.seq_id;
Expand All @@ -23,9 +25,9 @@ export class DirectPendingInboxFeed extends Feed<DirectInboxFeedResponse, Direct
cursor: this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
thread_message_limit: 10,
thread_message_limit: this.thread_message_limit ?? 10,
persistentBadging: true,
limit: 20,
limit: this.limit ?? 20,
},
});
this.state = body;
Expand Down
3 changes: 2 additions & 1 deletion src/feeds/direct-thread.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThrea
public seqId: number;
@Expose()
public cursor: string;
public limit?: number;
set state(body: DirectThreadFeedResponse) {
this.cursor = body.thread.oldest_cursor;
this.moreAvailable = body.thread.has_older;
Expand All @@ -19,7 +20,7 @@ export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThrea
cursor: this.cursor,
direction: 'older',
seq_id: this.seqId,
limit: 10,
limit: this.limit ?? 10,
},
});
this.state = body;
Expand Down