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 to posts fetch #58

Merged
merged 1 commit into from
Jul 12, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ await client.feeds.notificationseen()
<br />

### client.posts.fetch
In the parameters pass the id of the post you want to get information about
In the parameters pass the id of the post you want to get information about, and an optional pagination token from the previous request.
```js
await client.posts.fetch("aAaAAAaaa")
await client.posts.fetch("aAaAAAaaa", "aAaAAAaaa")
```
### client.posts.likers
In the parameters pass the id of the post whose likes you want to get
Expand Down
4 changes: 2 additions & 2 deletions src/managers/PostManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const RESTManager = require("./RESTManager");

class PostManager extends RESTManager {
async fetch(post) {
return await this.request(`/api/v1/text_feed/${post}/replies`);
async fetch(post, paging_token) {
return await this.request(`/api/v1/text_feed/${post}/replies/` + (paging_token ? `?paging_token=${encodeURIComponent(paging_token)}` : ""));
}

async likers(post, user) {
Expand Down
4 changes: 2 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare module "@threadsjs/threads.js/src/managers/RESTManager.js" {
import { Client } from "@threadsjs/threads.js";
export default class RESTManager {
public constructor(client: Client);
request(url: string, options: object): Promise<any>;
request(url: string, options?: object): Promise<any>;
}
}

Expand Down Expand Up @@ -31,7 +31,7 @@ declare module "@threadsjs/threads.js/src/managers/PostManager.js" {
}

export default class PostManager extends RESTManager {
fetch(post: string) : Promise<any>;
fetch(post: string, paging_token?: string) : Promise<any>;
likers(post: string, user: string | number) : Promise<any>;
create(contents: string, user: string | number) : Promise<any>;
reply(contents: string, user: string | number, post: string): Promise<any>;
Expand Down