feat(mobx): start working on notif options, create blank files

This commit is contained in:
Paul Makles 2021-12-10 17:00:34 +00:00
parent 185f76d850
commit 89748d7044
5 changed files with 79 additions and 0 deletions

View file

@ -6,6 +6,14 @@ import { useContext } from "preact/hooks";
import Auth from "./stores/Auth"; import Auth from "./stores/Auth";
import Draft from "./stores/Draft"; import Draft from "./stores/Draft";
interface StoreDefinition {
id: string;
instance: Record<string, unknown>;
persistent: boolean;
synced: boolean;
global: boolean;
}
/** /**
* Handles global application state. * Handles global application state.
*/ */

View file

View file

@ -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<string, string>;
channel?: Record<string, string>;
}
/**
* Manages the user's notification preferences.
*/
export default class NotificationOptions implements Persistent<Data> {
private server: ObservableMap<string, string>;
private channel: ObservableMap<string, string>;
/**
* 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
}

View file

View file