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

Add pagination for all feeds #52

Merged
merged 4 commits into from
Jul 11, 2023
Merged
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: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ await client.feeds.fetch()
await client.feeds.fetch("aAaAAAaaa")
```
### client.feeds.fetchThreads
In the parameters, pass the user id (supported as string and number) of the user whose threads you want to get.
In the parameters, pass the user id (supported as string and number) of the user whose threads you want to get, and an optional max_id of the previous response's next_max_id.
```js
await client.feeds.fetchThreads(1)
await client.feeds.fetchThreads(1),
await client.feeds.fetchThreads(1, "aAaAAAaaa")
```
### client.feeds.fetchReplies
In the parameters, pass the user id (supported as string and number) of the user whose replies you want to get.
In the parameters, pass the user id (supported as string and number) of the user whose replies you want to get, and an optional max_id of the previous response's next_max_id.
```js
await client.feeds.fetchReplies(1)
await client.feeds.fetchReplies(1, "aAaAAAaaa")
```
### client.feeds.recommended
Getting a list of recommendations.
Getting a list of recommendations. In the parameters, pass the optional paging_token of the previous response.
```js
await client.feeds.recommended()
await client.feeds.recommended(15)
```

<br />
Expand Down
12 changes: 6 additions & 6 deletions src/managers/FeedManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class FeedManager extends RESTManager {
})
}

async fetchThreads(user) {
return await this.request(`/api/v1/text_feed/${String(user)}/profile`);
async fetchThreads(user, max_id) {
return await this.request(`/api/v1/text_feed/${String(user)}/profile/` + (max_id ? '?max_id=' + encodeURIComponent(max_id) : ''));
}

async fetchReplies(user) {
return await this.request(`/api/v1/text_feed/${String(user)}/profile/replies`);
async fetchReplies(user, max_id) {
return await this.request(`/api/v1/text_feed/${String(user)}/profile/replies/` + (max_id ? '?max_id=' + encodeURIComponent(max_id) : ''));
}

async recommended() {
return await this.request('/api/v1/text_feed/recommended_users/');
async recommended(paging_token) {
return await this.request('/api/v1/text_feed/recommended_users/' + (paging_token ? '?paging_token=' + paging_token : ''));
}
}

Expand Down
8 changes: 4 additions & 4 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ declare module "@threadsjs/threads.js/src/managers/RESTManager.js" {
declare module "@threadsjs/threads.js/src/managers/FeedManager.js" {
import RESTManager from "@threadsjs/threads.js/src/managers/RESTManager.js";
export default class FeedManager extends RESTManager {
fetch(): Promise<any>;
fetchThreads(user: string | number): Promise<any>;
fetchReplies(user: string | number): Promise<any>;
recommended(): Promise<any>;
fetch(max_id?: string): Promise<any>;
fetchThreads(user: string | number, max_id?: string): Promise<any>;
fetchReplies(user: string | number, max_id?: string): Promise<any>;
recommended(paging_token?: number): Promise<any>;
}
}

Expand Down