Feature: Basic notification options implementation

This commit is contained in:
Paul
2021-06-24 23:59:46 +01:00
parent 51ac1f599c
commit 21859e4c55
10 changed files with 173 additions and 25 deletions

View File

@@ -13,6 +13,7 @@ import { Settings } from "./reducers/settings";
import { QueuedMessage } from "./reducers/queue";
import { ExperimentOptions } from "./reducers/experiments";
import { LastOpened } from "./reducers/last_opened";
import { Notifications } from "./reducers/notifications";
export type State = {
config: Core.RevoltNodeConfiguration,
@@ -26,6 +27,7 @@ export type State = {
sync: SyncOptions;
experiments: ExperimentOptions;
lastOpened: LastOpened;
notifications: Notifications;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -53,7 +55,8 @@ store.subscribe(() => {
drafts,
sync,
experiments,
lastOpened
lastOpened,
notifications
} = store.getState() as State;
localForage.setItem("state", {
@@ -66,6 +69,7 @@ store.subscribe(() => {
drafts,
sync,
experiments,
lastOpened
lastOpened,
notifications
});
});

View File

@@ -12,6 +12,7 @@ import { drafts, DraftAction } from "./drafts";
import { sync, SyncAction } from "./sync";
import { experiments, ExperimentsAction } from "./experiments";
import { lastOpened, LastOpenedAction } from "./last_opened";
import { notifications, NotificationsAction } from "./notifications";
export default combineReducers({
config,
@@ -24,7 +25,8 @@ export default combineReducers({
drafts,
sync,
experiments,
lastOpened
lastOpened,
notifications
});
export type Action =
@@ -39,6 +41,7 @@ export type Action =
| SyncAction
| ExperimentsAction
| LastOpenedAction
| NotificationsAction
| { type: "__INIT"; state: State };
export type WithDispatcher = { dispatcher: (action: Action) => void };

View File

@@ -0,0 +1,56 @@
import { Channel } from "revolt.js";
export type NotificationState = 'all' | 'mention' | 'none' | 'muted';
export type Notifications = {
[key: string]: NotificationState
}
export const DEFAULT_STATES: { [key in Channel['channel_type']]: NotificationState } = {
'SavedMessages': 'all',
'DirectMessage': 'all',
'Group': 'all',
'TextChannel': 'mention',
'VoiceChannel': 'mention'
};
export function getNotificationState(notifications: Notifications, channel: Channel) {
return notifications[channel._id] ?? DEFAULT_STATES[channel.channel_type];
}
export type NotificationsAction =
| { type: undefined }
| {
type: "NOTIFICATIONS_SET";
key: string;
state: NotificationState;
}
| {
type: "NOTIFICATIONS_REMOVE";
key: string;
}
| {
type: "RESET";
};
export function notifications(
state = {} as Notifications,
action: NotificationsAction
): Notifications {
switch (action.type) {
case "NOTIFICATIONS_SET":
return {
...state,
[action.key]: action.state
};
case "NOTIFICATIONS_REMOVE":
{
const { [action.key]: _, ...newState } = state;
return newState;
}
case "RESET":
return {};
default:
return state;
}
}

View File

@@ -1,19 +1,22 @@
import { AppearanceOptions } from "./settings";
import { Language } from "../../context/Locale";
import { ThemeOptions } from "../../context/Theme";
import { Notifications } from "./notifications";
export type SyncKeys = "theme" | "appearance" | "locale";
export type SyncKeys = "theme" | "appearance" | "locale" | "notifications";
export interface SyncData {
locale?: Language;
theme?: ThemeOptions;
appearance?: AppearanceOptions;
notifications?: Notifications;
}
export const DEFAULT_ENABLED_SYNC: SyncKeys[] = [
"theme",
"appearance",
"locale",
"notifications"
];
export interface SyncOptions {
disabled?: SyncKeys[];