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 2 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
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
22 changes: 16 additions & 6 deletions src/feeds/direct-inbox.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,47 @@ import { Feed } from '../core/feed';
import { DirectInboxFeedResponse, DirectInboxFeedResponseThreadsItem } from '../responses';
import { DirectThreadEntity } from '../entities';

interface DirectInboxFeedItemsOptions {
cursor?: string;
thread_message_limit?: number;
limit?: number;
}

export class DirectInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFeedResponseThreadsItem> {
@Expose()
private cursor: string;
@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;
this.cursor = body.inbox.oldest_cursor;
}

async request() {
async request(opts?: DirectInboxFeedItemsOptions) {
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
const { body } = await this.client.request.send<DirectInboxFeedResponse>({
url: `/api/v1/direct_v2/inbox/`,
qs: {
visual_message_return_type: 'unseen',
cursor: this.cursor,
cursor: opts.cursor ?? this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
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: 20,
limit: opts.limit ?? this.limit,
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
},
});
this.state = body;
return body;
}

async items() {
const response = await this.request();
async items(opts?: DirectInboxFeedItemsOptions) {
const response = await this.request(opts);
return response.inbox.threads;
}

Expand Down
22 changes: 16 additions & 6 deletions src/feeds/direct-pending.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,47 @@ import { Feed } from '../core/feed';
import { DirectInboxFeedResponse, DirectInboxFeedResponseThreadsItem } from '../responses';
import { DirectThreadEntity } from '../entities';

interface DirectPendingInboxFeedItemsOptions {
cursor?: string;
thread_message_limit?: number;
limit?: number;
}

export class DirectPendingInboxFeed extends Feed<DirectInboxFeedResponse, DirectInboxFeedResponseThreadsItem> {
@Expose()
private cursor: string;
@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;
this.cursor = body.inbox.oldest_cursor;
}

async request() {
async request(opts?: DirectPendingInboxFeedItemsOptions) {
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
const { body } = await this.client.request.send<DirectInboxFeedResponse>({
url: `/api/v1/direct_v2/pending_inbox/`,
qs: {
visual_message_return_type: 'unseen',
cursor: this.cursor,
cursor: this.cursor ?? this.cursor,
direction: this.cursor ? 'older' : void 0,
seq_id: this.seqId,
thread_message_limit: 10,
thread_message_limit: this.thread_message_limit ?? this.defaultThreadMessageLimit,
persistentBadging: true,
limit: 20,
limit: this.limit ?? this.defaultLimit,
},
});
this.state = body;
return body;
}

async items() {
const response = await this.request();
async items(opts?: DirectPendingInboxFeedItemsOptions) {
const response = await this.request(opts);
return response.inbox.threads;
}

Expand Down
17 changes: 12 additions & 5 deletions src/feeds/direct-thread.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@ import { Expose } from 'class-transformer';
import { Feed } from '../core/feed';
import { DirectThreadFeedResponse, DirectThreadFeedResponseItemsItem } from '../responses';

interface DirectThreadFeedItemsOptions {
cursor?: string;
limit?: number;
}

export class DirectThreadFeed extends Feed<DirectThreadFeedResponse, DirectThreadFeedResponseItemsItem> {
public id: string;
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;
}
async request() {
async request(opts?: DirectThreadFeedItemsOptions) {
Androz2091 marked this conversation as resolved.
Show resolved Hide resolved
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,
cursor: this.cursor ?? this.cursor,
direction: 'older',
seq_id: this.seqId,
limit: 10,
limit: this.limit ?? this.defaultLimit,
},
});
this.state = body;
return body;
}

async items() {
const response = await this.request();
async items(opts?: DirectThreadFeedItemsOptions) {
const response = await this.request(opts);
return response.thread.items;
}
}