mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-01-15 00:18:06 -05:00
* Normalize (depopulate from snoowrap) mod note raw data so it can be constructed agnostic of source (cache or api) * Implement cache GET for modnotes with default TTL of 60 seconds * Refactor mod note action and implement cache PUT when new notes are added
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import {Comment, PrivateMessage, RedditUser, Submission} from "snoowrap/dist/objects";
|
|
import {ModUserNoteLabel} from "../../Common/Infrastructure/Atomic";
|
|
//import {ExtendedSnoowrap} from "../../Utils/SnoowrapClients";
|
|
import {generateSnoowrapEntityFromRedditThing, parseRedditFullname} from "../../util";
|
|
import Snoowrap from "snoowrap";
|
|
|
|
export interface ModUserNoteRaw {
|
|
note?: string | null
|
|
reddit_id?: string | null
|
|
label?: string | null
|
|
}
|
|
|
|
export class ModUserNote {
|
|
note?: string
|
|
actedOn?: RedditUser | Submission | Comment | PrivateMessage
|
|
label?: ModUserNoteLabel
|
|
|
|
constructor(data: ModUserNoteRaw | undefined, client: Snoowrap) {
|
|
const {
|
|
note,
|
|
reddit_id,
|
|
label
|
|
} = data || {};
|
|
this.note = note !== null ? note : undefined;
|
|
this.label = label !== null ? label as ModUserNoteLabel : undefined;
|
|
|
|
if (reddit_id !== null && reddit_id !== undefined) {
|
|
const thing = parseRedditFullname(reddit_id);
|
|
if (thing !== undefined) {
|
|
this.actedOn = generateSnoowrapEntityFromRedditThing(thing, client) as RedditUser | Submission | Comment;
|
|
}
|
|
}
|
|
}
|
|
|
|
toRaw(): ModUserNoteRaw {
|
|
return {
|
|
note: this.note,
|
|
reddit_id: this.actedOn !== undefined ? this.actedOn.id : undefined,
|
|
label: this.label
|
|
}
|
|
}
|
|
|
|
toJSON() {
|
|
return this.toRaw();
|
|
}
|
|
}
|
|
|
|
export default ModUserNote;
|