chore: lay groundwork for masquerades

This commit is contained in:
Ed L 2022-09-10 20:25:44 +01:00 committed by Paul Makles
parent bfeefb4c73
commit b64c316dc9

View file

@ -5,15 +5,22 @@ import { mapToRecord } from "../../lib/conversion";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface DraftObject {
content?: string;
masquerade?: {
avatar: string;
name: string;
};
}
export interface Data {
drafts: Record<string, string>;
drafts: Record<string, DraftObject>;
}
/**
* Handles storing draft (currently being written) messages.
*/
export default class Draft implements Store, Persistent<Data> {
private drafts: ObservableMap<string, string>;
private drafts: ObservableMap<string, DraftObject>;
/**
* Construct new Draft store.
@ -52,7 +59,10 @@ export default class Draft implements Store, Persistent<Data> {
* @param channel Channel ID
*/
@computed has(channel: string) {
return this.drafts.has(channel) && this.drafts.get(channel)!.length > 0;
return (
this.drafts.has(channel) &&
this.drafts.get(channel)!.content!.length > 0
);
}
/**
@ -60,7 +70,7 @@ export default class Draft implements Store, Persistent<Data> {
* @param channel Channel ID
* @param content Draft content
*/
@action set(channel: string, content?: string) {
@action set(channel: string, content?: DraftObject) {
if (typeof content === "undefined") {
return this.clear(channel);
}