From 498a8d5cb83181c53209a7c60de1c45b36358114 Mon Sep 17 00:00:00 2001 From: Eric Gustavsson Date: Sat, 15 May 2021 02:29:30 +0200 Subject: [PATCH] feat: get flair selections for subreddit (#317) Subreddit#getLinkFlairTemplates does now have ability to get all flair templates if no `linkId` was given --- src/objects/Subreddit.d.ts | 2 +- src/objects/Subreddit.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/objects/Subreddit.d.ts b/src/objects/Subreddit.d.ts index bbb0b945..c4618fd3 100644 --- a/src/objects/Subreddit.d.ts +++ b/src/objects/Subreddit.d.ts @@ -114,7 +114,7 @@ export default class Subreddit extends RedditContent { getControversial(options?: ListingOptions & { time?: string }): Promise>; getEdited(options?: ListingOptions & { only?: 'links' | 'comments' }): Promise>; getHot(options?: ListingOptions): Promise>; - getLinkFlairTemplates(linkId: string): Promise; + getLinkFlairTemplates(linkId?: string): Promise; getModerationLog(opts?: ListingOptions & { mods?: string[]; type?: ModActionType}): Promise>; getModerators(options?: ListingOptions & { name?: string }): RedditUser[]; getModmail(options?: ListingOptions): Promise>; diff --git a/src/objects/Subreddit.js b/src/objects/Subreddit.js index 817d1c95..ffc879cd 100644 --- a/src/objects/Subreddit.js +++ b/src/objects/Subreddit.js @@ -93,12 +93,12 @@ const Subreddit = class Subreddit extends RedditContent { createLinkFlairTemplate (options) { return this._createFlairTemplate({...options, flair_type: 'LINK_FLAIR'}); } - _getFlairOptions ({name, link} = {}) { // TODO: Add shortcuts for this on RedditUser and Submission - return this._post({uri: `r/${this.display_name}/api/flairselector`, form: {name, link}}); + _getFlairOptions ({name, link, is_newlink} = {}) { // TODO: Add shortcuts for this on RedditUser and Submission + return this._post({uri: `r/${this.display_name}/api/flairselector`, form: {name, link, is_newlink}}); } /** - * @summary Gets the flair templates for a given link. - * @param {string} linkId The link's base36 ID + * @summary Gets the flair templates for the subreddit or a given link. + * @param {string} [linkId] The link's base36 ID * @returns {Promise} An Array of flair template options * @example * @@ -116,8 +116,9 @@ const Subreddit = class Subreddit extends RedditContent { // ... // ] */ - getLinkFlairTemplates (linkId) { - return this._getFlairOptions({link: linkId}).get('choices'); + getLinkFlairTemplates (linkId = null) { + const options = linkId ? {link: linkId} : {is_newlink: true}; + return this._getFlairOptions(options).get('choices'); } /** * @summary Gets the list of user flair templates on this subreddit.