Browse Source

Fix filling folders when reloading filters

master
morethanwords 3 years ago
parent
commit
42fc7ef557
  1. 2
      src/helpers/object.ts
  2. 1
      src/lib/appManagers/appStateManager.ts
  3. 1
      src/lib/rootScope.ts
  4. 7
      src/lib/storages/dialogs.ts
  5. 7
      src/lib/storages/filters.ts

2
src/helpers/object.ts

@ -51,7 +51,7 @@ export function defineNotNumerableProperties<T extends any>(obj: T, names: (keyo
const props = {writable: true, configurable: true}; const props = {writable: true, configurable: true};
const out: {[name in keyof T]?: typeof props} = {}; const out: {[name in keyof T]?: typeof props} = {};
names.forEach(name => { names.forEach(name => {
if(obj[name] === undefined) { if(!obj.hasOwnProperty(name)) {
out[name] = props; out[name] = props;
} }
}); });

1
src/lib/appManagers/appStateManager.ts

@ -26,6 +26,7 @@ import { nextRandomUint } from '../../helpers/random';
import compareVersion from '../../helpers/compareVersion'; import compareVersion from '../../helpers/compareVersion';
const REFRESH_EVERY = 24 * 60 * 60 * 1000; // 1 day const REFRESH_EVERY = 24 * 60 * 60 * 1000; // 1 day
// const REFRESH_EVERY = 1e3;
//const REFRESH_EVERY_WEEK = 24 * 60 * 60 * 1000 * 7; // 7 days //const REFRESH_EVERY_WEEK = 24 * 60 * 60 * 1000 * 7; // 7 days
const STATE_VERSION = App.versionFull; const STATE_VERSION = App.versionFull;
const BUILD = App.build; const BUILD = App.build;

1
src/lib/rootScope.ts

@ -34,6 +34,7 @@ export type BroadcastEvents = {
'filter_delete': MyDialogFilter, 'filter_delete': MyDialogFilter,
'filter_update': MyDialogFilter, 'filter_update': MyDialogFilter,
'filter_new': MyDialogFilter,
'filter_order': number[], 'filter_order': number[],
'folder_unread': Folder, 'folder_unread': Folder,

7
src/lib/storages/dialogs.ts

@ -94,12 +94,15 @@ export default class DialogsStorage {
} }
}); });
rootScope.addEventListener('filter_update', (filter) => { const onFilterUpdate = (filter: MyDialogFilter) => {
const dialogs = this.getCachedDialogs(false); const dialogs = this.getCachedDialogs(false);
for(let i = 0; i < dialogs.length; ++i) { for(let i = 0; i < dialogs.length; ++i) {
this.processDialogForFilter(dialogs[i], filter); this.processDialogForFilter(dialogs[i], filter);
} }
}); };
rootScope.addEventListener('filter_update', onFilterUpdate);
rootScope.addEventListener('filter_new', onFilterUpdate);
rootScope.addEventListener('filter_delete', (filter) => { rootScope.addEventListener('filter_delete', (filter) => {
delete this.folders[filter.id]; delete this.folders[filter.id];

7
src/lib/storages/filters.ts

@ -303,8 +303,9 @@ export default class FiltersStorage {
filter.include_peers = filter.pinned_peers.concat(filter.include_peers); filter.include_peers = filter.pinned_peers.concat(filter.include_peers);
filter.includePeerIds = filter.pinnedPeerIds.concat(filter.includePeerIds); filter.includePeerIds = filter.pinnedPeerIds.concat(filter.includePeerIds);
if(this.filters[filter.id]) { const oldFilter = this.filters[filter.id];
Object.assign(this.filters[filter.id], filter); if(oldFilter) {
Object.assign(oldFilter, filter);
} else { } else {
this.filters[filter.id] = filter; this.filters[filter.id] = filter;
} }
@ -313,6 +314,8 @@ export default class FiltersStorage {
if(update) { if(update) {
this.rootScope.dispatchEvent('filter_update', filter); this.rootScope.dispatchEvent('filter_update', filter);
} else if(!oldFilter) {
this.rootScope.dispatchEvent('filter_new', filter);
} }
} }

Loading…
Cancel
Save