mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
Notifications: Block muted channels from push notifs.
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Language } from "../../context/Locale";
|
||||
import { SyncUpdateAction } from "./sync";
|
||||
import type { SyncUpdateAction } from "./sync";
|
||||
|
||||
export type LocaleAction =
|
||||
| { type: undefined }
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MessageObject } from "../../context/revoltjs/util";
|
||||
import type { MessageObject } from "../../context/revoltjs/util";
|
||||
|
||||
export enum QueueStatus {
|
||||
SENDING = "sending",
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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">>;
|
||||
|
||||
Reference in New Issue
Block a user