Browse Source

Cache notifications settings by peer type

master
Eduard Kuzmenko 3 years ago
parent
commit
8fa86191aa
  1. 13
      src/lib/appManagers/appDialogsManager.ts
  2. 5
      src/lib/appManagers/appNotificationsManager.ts
  3. 8
      src/lib/appManagers/appStateManager.ts

13
src/lib/appManagers/appDialogsManager.ts

@ -56,10 +56,11 @@ import debounce from "../../helpers/schedulers/debounce";
import generateVerifiedIcon from "../../components/generateVerifiedIcon"; import generateVerifiedIcon from "../../components/generateVerifiedIcon";
import { NULL_PEER_ID } from "../mtproto/mtproto_config"; import { NULL_PEER_ID } from "../mtproto/mtproto_config";
import groupCallActiveIcon from "../../components/groupCallActiveIcon"; import groupCallActiveIcon from "../../components/groupCallActiveIcon";
import { Chat } from "../../layer"; import { Chat, NotifyPeer } from "../../layer";
import IS_GROUP_CALL_SUPPORTED from "../../environment/groupCallSupport"; import IS_GROUP_CALL_SUPPORTED from "../../environment/groupCallSupport";
import mediaSizes from "../../helpers/mediaSizes"; import mediaSizes from "../../helpers/mediaSizes";
import appNavigationController, { NavigationItem } from "../../components/appNavigationController"; import appNavigationController, { NavigationItem } from "../../components/appNavigationController";
import assumeType from "../../helpers/assumeType";
export type DialogDom = { export type DialogDom = {
avatarEl: AvatarElement, avatarEl: AvatarElement,
@ -579,6 +580,16 @@ export class AppDialogsManager {
} }
private async onStateLoaded(state: State) { 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(); appNotificationsManager.getNotifyPeerTypeSettings();
if(!this.initedListeners) { if(!this.initedListeners) {

5
src/lib/appManagers/appNotificationsManager.ts

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

8
src/lib/appManagers/appStateManager.ts

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

Loading…
Cancel
Save