diff --git a/src/mobx/State.ts b/src/mobx/State.ts index ca112b37..5023062a 100644 --- a/src/mobx/State.ts +++ b/src/mobx/State.ts @@ -6,6 +6,14 @@ import { useContext } from "preact/hooks"; import Auth from "./stores/Auth"; import Draft from "./stores/Draft"; +interface StoreDefinition { + id: string; + instance: Record; + persistent: boolean; + synced: boolean; + global: boolean; +} + /** * Handles global application state. */ diff --git a/src/mobx/stores/MessageQueue.ts b/src/mobx/stores/MessageQueue.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/mobx/stores/NotificationOptions.ts b/src/mobx/stores/NotificationOptions.ts new file mode 100644 index 00000000..c79e7a79 --- /dev/null +++ b/src/mobx/stores/NotificationOptions.ts @@ -0,0 +1,71 @@ +import { action, computed, makeAutoObservable, ObservableMap } from "mobx"; +import { Channel } from "revolt-api/types/Channels"; + +import Persistent from "../Persistent"; + +/** + * Possible notification states. + * TODO: make "muted" gray out the channel + * TODO: add server defaults + */ +export type NotificationState = "all" | "mention" | "none" | "muted"; + +/** + * Default notification states for various types of channels. + */ +export const DEFAULT_STATES: { + [key in Channel["channel_type"]]: NotificationState; +} = { + SavedMessages: "all", + DirectMessage: "all", + Group: "all", + TextChannel: "mention", + VoiceChannel: "mention", +}; + +interface Data { + server?: Record; + channel?: Record; +} + +/** + * Manages the user's notification preferences. + */ +export default class NotificationOptions implements Persistent { + private server: ObservableMap; + private channel: ObservableMap; + + /** + * Construct new Experiments store. + */ + constructor() { + this.server = new ObservableMap(); + this.channel = new ObservableMap(); + makeAutoObservable(this); + } + + // eslint-disable-next-line require-jsdoc + toJSON() { + return { + server: this.server, + channel: this.channel, + }; + } + + // eslint-disable-next-line require-jsdoc + @action hydrate(data: Data) { + if (data.server) { + Object.keys(data.server).forEach((key) => + this.server.set(key, data.server![key]), + ); + } + + if (data.channel) { + Object.keys(data.channel).forEach((key) => + this.channel.set(key, data.channel![key]), + ); + } + } + + // TODO: implement +} diff --git a/src/mobx/stores/SectionToggle.ts b/src/mobx/stores/SectionToggle.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/mobx/stores/ServerConfig.ts b/src/mobx/stores/ServerConfig.ts new file mode 100644 index 00000000..e69de29b