|
|
@ -36,16 +36,18 @@ export type User = MTUser.user; |
|
|
|
export class AppUsersManager { |
|
|
|
export class AppUsersManager { |
|
|
|
private storage = appStateManager.storages.users; |
|
|
|
private storage = appStateManager.storages.users; |
|
|
|
|
|
|
|
|
|
|
|
private users: {[userId: number]: User} = {}; |
|
|
|
private users: {[userId: number]: User}; |
|
|
|
private usernames: {[username: string]: number} = {}; |
|
|
|
private usernames: {[username: string]: number}; |
|
|
|
private contactsIndex = new SearchIndex<number>(); |
|
|
|
private contactsIndex: SearchIndex<number>; |
|
|
|
private contactsFillPromise: Promise<Set<number>>; |
|
|
|
private contactsFillPromise: Promise<Set<number>>; |
|
|
|
private contactsList: Set<number> = new Set(); |
|
|
|
private contactsList: Set<number>; |
|
|
|
private updatedContactsList = false; |
|
|
|
private updatedContactsList: boolean; |
|
|
|
|
|
|
|
|
|
|
|
private getTopPeersPromise: Promise<number[]>; |
|
|
|
private getTopPeersPromise: Promise<number[]>; |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
|
|
|
|
this.clear(); |
|
|
|
|
|
|
|
|
|
|
|
setInterval(this.updateUsersStatuses, 60000); |
|
|
|
setInterval(this.updateUsersStatuses, 60000); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('state_synchronized', this.updateUsersStatuses); |
|
|
|
rootScope.addEventListener('state_synchronized', this.updateUsersStatuses); |
|
|
@ -158,6 +160,29 @@ export class AppUsersManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public clear() { |
|
|
|
|
|
|
|
if(this.users) { |
|
|
|
|
|
|
|
for(const userId in this.users) { |
|
|
|
|
|
|
|
if(!appStateManager.isPeerNeeded(+userId)) { |
|
|
|
|
|
|
|
const user = this.users[userId]; |
|
|
|
|
|
|
|
if(user.username) { |
|
|
|
|
|
|
|
delete this.usernames[cleanUsername(user.username)]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete this.users[userId]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.users = {}; |
|
|
|
|
|
|
|
this.usernames = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.contactsIndex = new SearchIndex(); |
|
|
|
|
|
|
|
this.contactsFillPromise = undefined; |
|
|
|
|
|
|
|
this.contactsList = new Set(); |
|
|
|
|
|
|
|
this.updatedContactsList = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private onContactsModified() { |
|
|
|
private onContactsModified() { |
|
|
|
const contactsList = [...this.contactsList]; |
|
|
|
const contactsList = [...this.contactsList]; |
|
|
|
appStateManager.pushToState('contactsList', contactsList); |
|
|
|
appStateManager.pushToState('contactsList', contactsList); |
|
|
|