Skip to content

Commit

Permalink
feat: add controls to managing muted users in a subreddit
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Mar 27, 2022
1 parent 85831df commit d057dc0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/reddit/subreddit/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,42 @@ export class SubredditControls extends BaseControls {
return this.getAboutListingUsers(subreddit, "banned");
}

/**
* Mute a user in a subreddit.
*
* This prevents the user from sending modmail to the subreddit for 72 hours.
*
* @param subreddit The name of the subreddit to mute the user in.
* @param username The username of the user to mute.
*/
async muteUser(subreddit: string, username: string): Promise<void> {
await this.friend(subreddit, username, "muted");
}

/**
* Unmute a user in a subreddit.
*
* @param subreddit The name of the subreddit to unmute the user in.
* @param username The username of the user to unmute.
*/
async unmuteUser(subreddit: string, username: string): Promise<void> {
await this.unfriend(subreddit, username, "muted");
}

/**
* Get the list of muted users for a subreddit.
*
* @note Due to the way Reddit implements Listings, this will only contain the
* first 1000 muted users.
*
* @param subreddit The name of the subreddit to get muted users for.
*
* @returns A listing of muted users.
*/
getMutedUsers(subreddit: string): Listing<User> {
return this.getAboutListingUsers(subreddit, "muted");
}

/** @internal */
protected getSortedPosts(
subreddit: string | undefined,
Expand Down
32 changes: 32 additions & 0 deletions src/reddit/subreddit/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,38 @@ export class Subreddit extends Content implements SubredditData {
return this.controls.getWikiContributors(this.displayName);
}

/**
* Mute a user in this subreddit.
*
* This prevents the user from sending modmail to this subreddit for 72 hours.
*
* @param username The username of the user to mute.
*/
async muteUser(username: string): Promise<void> {
return this.controls.muteUser(this.displayName, username);
}

/**
* Unmute a user in this subreddit.
*
* @param username The username of the user to unmute.
*/
async unmuteUser(username: string): Promise<void> {
return this.controls.unmuteUser(this.displayName, username);
}

/**
* Get the list of muted users for this subreddit.
*
* @note Due to the way Reddit implements Listings, this will only contain the
* first 1000 muted users.
*
* @returns A listing of muted users.
*/
getMutedUsers(): Listing<User> {
return this.controls.getMutedUsers(this.displayName);
}

/**
* Ban a user from this subreddit.
*
Expand Down

0 comments on commit d057dc0

Please sign in to comment.