mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 15:10:57 -05:00
feat(mobx): start working on notif options, create blank files
This commit is contained in:
parent
185f76d850
commit
89748d7044
5 changed files with 79 additions and 0 deletions
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
0
src/mobx/stores/MessageQueue.ts
Normal file
0
src/mobx/stores/MessageQueue.ts
Normal file
71
src/mobx/stores/NotificationOptions.ts
Normal file
71
src/mobx/stores/NotificationOptions.ts
Normal 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
|
||||||
|
}
|
0
src/mobx/stores/SectionToggle.ts
Normal file
0
src/mobx/stores/SectionToggle.ts
Normal file
0
src/mobx/stores/ServerConfig.ts
Normal file
0
src/mobx/stores/ServerConfig.ts
Normal file
Loading…
Reference in a new issue