forked from thislooksfun/snoots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow locking and unlocking comments
- Loading branch information
1 parent
774866d
commit 766726b
Showing
7 changed files
with
84 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { VoteableControls } from "../voteable/controls"; | ||
|
||
/** The base controls for all content that can be locked. */ | ||
export abstract class LockableControls extends VoteableControls { | ||
/** | ||
* Lock an item, preventing non-moderators from being able to post replies. | ||
* | ||
* @param id The ID of the item to lock. | ||
* | ||
* @returns A promise that resolves when the item has been locked. | ||
*/ | ||
async lock(id: string): Promise<void> { | ||
await this.gateway.post("api/lock", { id: this.namespace(id) }); | ||
} | ||
|
||
/** | ||
* Unlock an item, allowing non-moderators to post replies. | ||
* | ||
* @param id The ID of the item to unlock. | ||
* | ||
* @returns A promise that resolves when the item has been unlocked. | ||
*/ | ||
async unlock(id: string): Promise<void> { | ||
await this.gateway.post("api/unlock", { id: this.namespace(id) }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { VoteableData } from "../voteable/object"; | ||
import type { LockableControls } from "./controls"; | ||
|
||
import { Voteable } from "../voteable/object"; | ||
|
||
/** The base for all content that can be locked. */ | ||
export interface LockableData extends VoteableData { | ||
/** Whether or not this item is locked. */ | ||
locked: boolean; | ||
} | ||
|
||
/** The base for all content that can be locked. */ | ||
export abstract class Lockable extends Voteable implements LockableData { | ||
locked: boolean; | ||
|
||
protected controls: LockableControls; | ||
|
||
/** @internal */ | ||
constructor(controls: LockableControls, data: LockableData) { | ||
super(controls, data); | ||
this.controls = controls; | ||
|
||
this.locked = data.locked; | ||
} | ||
|
||
/** | ||
* Lock this item, preventing non-moderators from being able to post replies. | ||
* | ||
* @returns A promise that resolves when this item has been locked. | ||
*/ | ||
async lock(): Promise<void> { | ||
await this.controls.lock(this.id); | ||
} | ||
|
||
/** | ||
* Unlock this item, allowing non-moderators to post replies. | ||
* | ||
* @returns A promise that resolves when this item has been unlocked. | ||
*/ | ||
async unlock(): Promise<void> { | ||
await this.controls.unlock(this.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters