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 1 commit
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
17 changes: 12 additions & 5 deletions src/core/feed.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,29 @@ 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 {
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
const feed = new DirectInboxFeed(this.client);
feed.limit = options.limit;
feed.thread_message_limit = options?.thread_message_limit;
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
return feed;
}

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

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
8 changes: 6 additions & 2 deletions src/feeds/direct-inbox.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class DirectInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFe
@Expose()
private seqId: number;

public limit: number;
public defaultLimit = 20;
public thread_message_limit: number;
public defaultThreadMessageLimit: number;
set state(body: DirectInboxFeedResponse) {
this.moreAvailable = body.inbox.has_older;
this.seqId = body.seq_id;
Expand All @@ -29,9 +33,9 @@ export class DirectInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFe
cursor: opts.cursor ?? this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
thread_message_limit: opts.thread_message_limit ?? 10,
thread_message_limit: this.thread_message_limit ?? this.defaultThreadMessageLimit,
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
persistentBadging: true,
limit: opts.limit ?? 20,
limit: opts.limit ?? this.limit,
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
},
});
this.state = body;
Expand Down
10 changes: 7 additions & 3 deletions src/feeds/direct-pending.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class DirectPendingInboxFeed extends Feed<DirectInboxFeedResponse, Direct
@Expose()
private seqId: number;

public limit: number;
public defaultLimit = 20;
public thread_message_limit: number;
public defaultThreadMessageLimit: number;
set state(body: DirectInboxFeedResponse) {
this.moreAvailable = body.inbox.has_older;
this.seqId = body.seq_id;
Expand All @@ -26,12 +30,12 @@ export class DirectPendingInboxFeed extends Feed<DirectInboxFeedResponse, Direct
url: `/api/v1/direct_v2/pending_inbox/`,
qs: {
visual_message_return_type: 'unseen',
cursor: opts.cursor ?? this.cursor,
cursor: this.cursor ?? this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
thread_message_limit: opts.thread_message_limit ?? 10,
thread_message_limit: this.thread_message_limit ?? this.defaultThreadMessageLimit,
persistentBadging: true,
limit: opts.limit ?? 20,
limit: this.limit ?? this.defaultLimit,
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
},
});
this.state = body;
Expand Down
6 changes: 4 additions & 2 deletions src/feeds/direct-thread.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThrea
public seqId: number;
@Expose()
public cursor: string;
public limit?: number;
public defaultLimit = 10;
set state(body: DirectThreadFeedResponse) {
this.cursor = body.thread.oldest_cursor;
this.moreAvailable = body.thread.has_older;
Expand All @@ -21,10 +23,10 @@ export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThrea
url: `/api/v1/direct_v2/threads/${this.id}/`,
qs: {
visual_message_return_type: 'unseen',
cursor: opts.cursor ?? this.cursor,
cursor: this.cursor ?? this.cursor,
direction: 'older',
seq_id: this.seqId,
limit: opts.limit ?? 10,
limit: this.limit ?? this.defaultLimit,
},
});
this.state = body;
Expand Down