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. 11
      src/lib/storages/filters.ts

2
src/helpers/object.ts

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

1
src/lib/appManagers/appStateManager.ts

@ -26,6 +26,7 @@ import { nextRandomUint } from '../../helpers/random'; @@ -26,6 +26,7 @@ import { nextRandomUint } from '../../helpers/random';
import compareVersion from '../../helpers/compareVersion';
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 STATE_VERSION = App.versionFull;
const BUILD = App.build;

1
src/lib/rootScope.ts

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

7
src/lib/storages/dialogs.ts

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

11
src/lib/storages/filters.ts

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

Loading…
Cancel
Save