Cache notifications settings by peer type

This commit is contained in:
Eduard Kuzmenko 2022-03-09 22:43:47 +02:00
parent ba2a01f7da
commit 9cbc8928c9
3 changed files with 22 additions and 4 deletions

View File

@ -56,10 +56,11 @@ import debounce from "../../helpers/schedulers/debounce";
import generateVerifiedIcon from "../../components/generateVerifiedIcon";
import { NULL_PEER_ID } from "../mtproto/mtproto_config";
import groupCallActiveIcon from "../../components/groupCallActiveIcon";
import { Chat } from "../../layer";
import { Chat, NotifyPeer } from "../../layer";
import IS_GROUP_CALL_SUPPORTED from "../../environment/groupCallSupport";
import mediaSizes from "../../helpers/mediaSizes";
import appNavigationController, { NavigationItem } from "../../components/appNavigationController";
import assumeType from "../../helpers/assumeType";
export type DialogDom = {
avatarEl: AvatarElement,
@ -579,6 +580,16 @@ export class AppDialogsManager {
}
private async onStateLoaded(state: State) {
if(state.notifySettings) {
for(const key in state.notifySettings) {
assumeType<Exclude<NotifyPeer['_'], 'notifyPeer'>>(key);
appNotificationsManager.savePeerSettings({
key,
settings: state.notifySettings[key]
});
}
}
appNotificationsManager.getNotifyPeerTypeSettings();
if(!this.initedListeners) {

View File

@ -475,6 +475,11 @@ export class AppNotificationsManager {
if(!peerId) {
rootScope.dispatchEvent('notify_peer_type_settings', {key, settings});
appStateManager.getState().then(state => {
const notifySettings = state.notifySettings;
notifySettings[key] = settings;
appStateManager.pushToState('notifySettings', notifySettings);
});
} else {
this.checkMuteUntilThrottled();
}

View File

@ -18,7 +18,7 @@ import { copy, setDeepProperty, validateInitObject } from '../../helpers/object'
import App from '../../config/app';
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
import AppStorage from '../storage';
import { AutoDownloadSettings, Chat } from '../../layer';
import { AutoDownloadSettings, Chat, NotifyPeer, PeerNotifySettings } from '../../layer';
import { IS_MOBILE } from '../../environment/userAgent';
import DATABASE_STATE from '../../config/databases/state';
import sessionStorage from '../sessionStorage';
@ -114,7 +114,8 @@ export type State = {
},
keepSigned: boolean,
chatContextMenuHintWasShown: boolean,
stateId: number
stateId: number,
notifySettings: {[k in Exclude<NotifyPeer['_'], 'notifyPeer'>]?: PeerNotifySettings.peerNotifySettings}
};
export const STATE_INIT: State = {
@ -207,7 +208,8 @@ export const STATE_INIT: State = {
},
keepSigned: true,
chatContextMenuHintWasShown: false,
stateId: nextRandomUint(32)
stateId: nextRandomUint(32),
notifySettings: {}
};
const ALL_KEYS = Object.keys(STATE_INIT) as any as Array<keyof State>;