Skip to content

Commit

Permalink
feat: add a helper function for crossposting
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Apr 8, 2021
1 parent 808c1ce commit 19b7fc5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/controls/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { PostData } from "../objects/post";
import type Client from "../client";
import { camelCaseKeys } from "../helper/util";
import { fakeListingAfter } from "../listings/util";
import { LinkPostOptions } from "./subreddit";
import CommentListing from "../listings/comment";
import Listing from "../listings/listing";
import Post from "../objects/post";
Expand Down Expand Up @@ -110,6 +111,25 @@ export default class PostControls extends VoteableControls {
await this.client.post("api/distinguish", body);
}

/**
* Crosspost a post.
*
* @param id The ID of the post to crosspost.
* @param subreddit The name of the subreddit to crosspost to.
* @param title The title of the crosspost.
* @param opts Any extra options.
*
* * @returns A promise that resolves to the ID of the newly created post.
*/
async crosspostTo(
id: string,
subreddit: string,
title: string,
opts: LinkPostOptions = {}
): Promise<string> {
return this.client.subreddits.postCrosspost(subreddit, title, id, opts);
}

/**
* Turn contest mode on/off.
*
Expand Down
18 changes: 18 additions & 0 deletions src/objects/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { VoteableData } from "./voteable";
// import type { VoteableData, RichTextFlair } from "./voteable";
import { LinkPostOptions } from "../controls/subreddit";
import Listing from "../listings/listing";
import PostControls from "../controls/post";
import Voteable from "./voteable";
Expand Down Expand Up @@ -382,6 +383,23 @@ export default class Post extends Voteable implements PostData {
return this.controls.undistinguish(this.id);
}

/**
* Crosspost this post.
*
* @param subreddit The name of the subreddit to crosspost to.
* @param title The title of the crosspost.
* @param opts Any extra options.
*
* @returns A promise that resolves to the ID of the newly created post.
*/
async crosspostTo(
subreddit: string,
title: string,
opts: LinkPostOptions = {}
): Promise<string> {
return this.controls.crosspostTo(this.id, subreddit, title, opts);
}

/**
* Turn contest mode on/off.
*
Expand Down

0 comments on commit 19b7fc5

Please sign in to comment.