Notifications: Block muted channels from push notifs.

This commit is contained in:
Paul
2021-06-25 12:37:59 +01:00
parent 21859e4c55
commit 994ef65200
10 changed files with 53 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import { Auth } from "revolt.js/dist/api/objects";
import type { Auth } from "revolt.js/dist/api/objects";
export interface AuthState {
accounts: {

View File

@@ -1,5 +1,5 @@
import { Language } from "../../context/Locale";
import { SyncUpdateAction } from "./sync";
import type { SyncUpdateAction } from "./sync";
export type LocaleAction =
| { type: undefined }

View File

@@ -1,4 +1,5 @@
import { Channel } from "revolt.js";
import type { Channel, Message } from "revolt.js";
import type { SyncUpdateAction } from "./sync";
export type NotificationState = 'all' | 'mention' | 'none' | 'muted';
@@ -18,6 +19,18 @@ export function getNotificationState(notifications: Notifications, channel: Chan
return notifications[channel._id] ?? DEFAULT_STATES[channel.channel_type];
}
export function shouldNotify(state: NotificationState, message: Message, user_id: string) {
switch (state) {
case 'muted':
case 'none': return false;
case 'mention': {
if (!message.mentions?.includes(user_id)) return false;
}
}
return true;
}
export type NotificationsAction =
| { type: undefined }
| {
@@ -29,6 +42,7 @@ export type NotificationsAction =
type: "NOTIFICATIONS_REMOVE";
key: string;
}
| SyncUpdateAction
| {
type: "RESET";
};
@@ -48,6 +62,8 @@ export function notifications(
const { [action.key]: _, ...newState } = state;
return newState;
}
case "SYNC_UPDATE":
return action.update.notifications?.[1] ?? state;
case "RESET":
return {};
default:

View File

@@ -1,4 +1,4 @@
import { MessageObject } from "../../context/revoltjs/util";
import type { MessageObject } from "../../context/revoltjs/util";
export enum QueueStatus {
SENDING = "sending",

View File

@@ -1,4 +1,4 @@
import { Core } from "revolt.js/dist/api/objects";
import type { Core } from "revolt.js/dist/api/objects";
export type ConfigAction =
| { type: undefined }

View File

@@ -1,7 +1,7 @@
import { filter } from ".";
import { SyncUpdateAction } from "./sync";
import { Sounds } from "../../assets/sounds/Audio";
import { Theme, ThemeOptions } from "../../context/Theme";
import type { SyncUpdateAction } from "./sync";
import type { Sounds } from "../../assets/sounds/Audio";
import type { Theme, ThemeOptions } from "../../context/Theme";
import { setEmojiPack } from "../../components/common/Emoji";
export type SoundOptions = {

View File

@@ -1,7 +1,7 @@
import { AppearanceOptions } from "./settings";
import { Language } from "../../context/Locale";
import { ThemeOptions } from "../../context/Theme";
import { Notifications } from "./notifications";
import type { AppearanceOptions } from "./settings";
import type { Language } from "../../context/Locale";
import type { ThemeOptions } from "../../context/Theme";
import type { Notifications } from "./notifications";
export type SyncKeys = "theme" | "appearance" | "locale" | "notifications";

View File

@@ -1,4 +1,4 @@
import { Sync } from "revolt.js/dist/api/objects";
import type { Sync } from "revolt.js/dist/api/objects";
export interface Unreads {
[key: string]: Partial<Omit<Sync.ChannelUnread, "_id">>;