Skip to content

Commit

Permalink
Add undo methods and get friendship status method (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlafl authored Jul 11, 2023
1 parent 9e9c5cf commit 8dc08c0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ In the parameters, pass the user id (supported as string and number) of the user
```js
await client.users.fetch(1)
```
### client.users.show
In the parameters, pass the user id (supported as string and number) of the user whose friendship status information you want to get.
```js
await client.users.show(1)
```
### client.users.follow
Pass the user id (supported as string and number) of the user you want to subscribe to in the parameters
```js
await client.users.follow(1)
```
### client.users.unfollow
Pass the user id (supported as string and number) of the user you want to unsubscribe from in the parameters
```js
await client.users.unfollow(1)
```
### client.users.search
Pass the query as the first parameter, and the number of objects in the response as the second parameter (by default - 30)
```js
Expand Down Expand Up @@ -130,8 +140,18 @@ The method is used to like a thread. Pass the post id as the first parameter, an
```js
await client.posts.like("aAaAAAaaa", 1)
```
### client.posts.unlike
The method is used to unlike a thread. Pass the post id as the first parameter, and the user id (supported as string and number) as the second
```js
await client.posts.unlike("aAaAAAaaa", 1)
```
### client.posts.repost
The method is used to repost a thread. Pass the post id as the only parameter
```js
await client.posts.repost("aAaAAAaaa")
```
### client.posts.unrepost
The method is used to un-repost a thread. Pass the post id as the only parameter
```js
await client.posts.unrepost("aAaAAAaaa")
```
13 changes: 13 additions & 0 deletions src/managers/PostManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,26 @@ class PostManager extends RESTManager {
});
}

async unlike(post, user) {
return await this.request(`/api/v1/media/${post}_${String(user)}/unlike/`, {
method: "POST",
});
}

async repost(post) {
return await this.request(`/api/v1/repost/create_repost/`, {
method: 'POST',
body: 'media_id=' + post
});
}

async unrepost(post) {
return await this.request(`/api/v1/repost/delete_text_app_repost/`, {
method: 'POST',
body: 'original_media_id=' + post
});
}

async embed(url) {
return await this.request(
`/api/v1/text_feed/link_preview/?url=${encodeURIComponent(url)}`
Expand Down
12 changes: 12 additions & 0 deletions src/managers/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ class UserManager extends RESTManager {
return await this.request(`/api/v1/users/${String(user)}/info`);
}

async show(user) {
return await this.request(`/api/v1/friendships/show/${String(user)}/`, {
method: 'POST',
});
}

async follow(user) {
return await this.request(`/api/v1/friendships/create/${String(user)}/`, {
method: 'POST',
});
}

async unfollow(user) {
return await this.request(`/api/v1/friendships/destroy/${String(user)}/`, {
method: 'POST',
});
}

async search(query, count) {
return await this.request(`/api/v1/users/search/?q=${query}&count=${count ?? 30}`);
}
Expand Down
4 changes: 4 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ declare module "@threadsjs/threads.js/src/managers/PostManager.js" {
quote(contents: string, user: string | number, post: string): Promise<any>;
delete(post: string, user: string | number): Promise<any>;
like(post: string, user: string | number) : Promise<any>;
unlike(post: string, user: string | number) : Promise<any>;
repost(post: string) : Promise<any>;
unrepost(post: string) : Promise<any>;
embed(url: string) : Promise<any>;
}
}
Expand All @@ -46,7 +48,9 @@ declare module "@threadsjs/threads.js/src/managers/UserManager.js" {
import { User, FriendshipStatus } from "@threadsjs/threads.js";
export default class UserManager extends RESTManager {
fetch(user: string | number): Promise<User>;
show(user: string | number): Promise<FriendshipStatus>;
follow(user: string | number): Promise<FriendshipStatus>;
unfollow(user: string | number): Promise<FriendshipStatus>;
search(query: string, count?: number | string): Promise<any>;
followers(user: string | number): Promise<any>;
following(user: string | number): Promise<any>;
Expand Down

0 comments on commit 8dc08c0

Please sign in to comment.