Add remaining timeline methods & document them

This commit is contained in:
Roj Serbest 2021-10-26 11:51:14 +03:00
parent ee736c633c
commit b5ffe12984
2 changed files with 116 additions and 4 deletions

View File

@ -42,8 +42,8 @@
## Timeline
- [ ] compose
- [ ] delete
- [x] compose
- [x] delete
- [ ] get_likes
- [ ] get_post
- [ ] get_quotes

View File

@ -1,10 +1,11 @@
import { Request } from "../request.ts";
import { Document, Post } from "../types.ts";
import { Document, Peer, Post } from "../types.ts";
import { MethodBase } from "./method_base.ts";
export class Timeline extends MethodBase {
/**
* Composes a new post to push to the timeline
* Composes a new post to push to the timeline.
*
* @param text The text contents of the post that is to be composed.
* @param attachments An array of Document ID or instances to be attached to the post.
*/
@ -25,4 +26,115 @@ export class Timeline extends MethodBase {
true,
);
}
/**
* Deletes an existing post from the timeline.
*
* @param post The ID or instance of the post to be deleted.
*/
delete(post: string | Post): Promise<Post> {
return this.client.invokeRequest(
new Request("timeline.delete", { post: typeof post === "string" ? post : post.id }),
true,
);
}
/**
* Returns the peers that liked the requested post.
*
* @param post The post ID or instance to get likes from.
* @param page The requested page number, by default the value is 1.
*/
getLikes(post: string | Post, page?: number): Promise<Peer[]> {
return this.client.invokeRequest(
new Request("timeline.get_likes", {
post: typeof post === "string" ? post : post.id,
page,
}),
true,
);
}
/**
* Retrieves an existing post from the timeline.
*
* @param post The Post ID to retrieve from the timeline.
*/
getPost(post: string): Promise<Post> {
return this.client.invokeRequest(
new Request("timeline.get_post", {
post,
}),
true,
);
}
/**
* Returns an array of post quotes for the selected post.
*
* @param post The Post ID or instance to retrieve quotes from.
* @param page The requested page number, by default the value is 1.
*/
getQuotes(post: string | Post, page?: number): Promise<Post[]> {
return this.client.invokeRequest(
new Request("timeline.get_quotes", {
post: typeof post === "string" ? post : post.id,
page,
}),
true,
);
}
/**
* Returns an array of posts that replied to the selected post.
*
* @param post The Post ID or instance to retrieve replies from.
* @param page The requested page number, by default the value is 1.
*/
getReplies(post: string | Post, page?: number): Promise<Post[]> {
return this.client.invokeRequest(
new Request("timeline.get_replies", {
post: typeof post === "string" ? post : post.id,
page,
}),
true,
);
}
/**
* Returns an array of peers that reposted the selected post.
*
* @param post The post ID or instance to get reposts from.
* @param page The requested page number, by default the value is 1.
*/
getRepostedPeers(post: string | Post, page?: number): Promise<Peer[]> {
return this.client.invokeRequest(
new Request("timeline.get_reposted_peers", {
post: typeof post === "string" ? post : post.id,
page,
}),
true,
);
}
/**
* Likes an existing post on the timeline.
*
* @param post The ID or instance of the post to like.
*/
like(post: string | Post): Promise<Post> {
return this.client.invokeRequest(
new Request("timeline.like", { post: typeof post === "string" ? post : post.id }),
true,
);
}
/**
* Returns an array of posts from the users timeline.
*
* @param page The requested page number, by default the value is 1.
*/
retrieveFeed(page?: number): Promise<Post[]> {
return this.client.invokeRequest(new Request("timeline.retrieve_feed", { page }), true);
}
}