|
|
@ -13,7 +13,7 @@ import { formatPhoneNumber } from "../../components/misc"; |
|
|
|
import { MOUNT_CLASS_TO } from "../../config/debug"; |
|
|
|
import { MOUNT_CLASS_TO } from "../../config/debug"; |
|
|
|
import { tsNow } from "../../helpers/date"; |
|
|
|
import { tsNow } from "../../helpers/date"; |
|
|
|
import { safeReplaceObject, isObject } from "../../helpers/object"; |
|
|
|
import { safeReplaceObject, isObject } from "../../helpers/object"; |
|
|
|
import { InputUser, Update, User as MTUser, UserProfilePhoto, UserStatus } from "../../layer"; |
|
|
|
import { InputUser, Update, User as MTUser, UserStatus } from "../../layer"; |
|
|
|
import I18n, { i18n, LangPackKey } from "../langPack"; |
|
|
|
import I18n, { i18n, LangPackKey } from "../langPack"; |
|
|
|
//import apiManager from '../mtproto/apiManager';
|
|
|
|
//import apiManager from '../mtproto/apiManager';
|
|
|
|
import apiManager from '../mtproto/mtprotoworker'; |
|
|
|
import apiManager from '../mtproto/mtprotoworker'; |
|
|
@ -22,6 +22,7 @@ import serverTimeManager from "../mtproto/serverTimeManager"; |
|
|
|
import { RichTextProcessor } from "../richtextprocessor"; |
|
|
|
import { RichTextProcessor } from "../richtextprocessor"; |
|
|
|
import rootScope from "../rootScope"; |
|
|
|
import rootScope from "../rootScope"; |
|
|
|
import searchIndexManager from "../searchIndexManager"; |
|
|
|
import searchIndexManager from "../searchIndexManager"; |
|
|
|
|
|
|
|
//import AppStorage from "../storage";
|
|
|
|
import apiUpdatesManager from "./apiUpdatesManager"; |
|
|
|
import apiUpdatesManager from "./apiUpdatesManager"; |
|
|
|
import appChatsManager from "./appChatsManager"; |
|
|
|
import appChatsManager from "./appChatsManager"; |
|
|
|
import appPeersManager from "./appPeersManager"; |
|
|
|
import appPeersManager from "./appPeersManager"; |
|
|
@ -32,12 +33,15 @@ import appStateManager from "./appStateManager"; |
|
|
|
export type User = MTUser.user; |
|
|
|
export type User = MTUser.user; |
|
|
|
|
|
|
|
|
|
|
|
export class AppUsersManager { |
|
|
|
export class AppUsersManager { |
|
|
|
|
|
|
|
/* private storage = new AppStorage<Record<number, User>>({ |
|
|
|
|
|
|
|
storeName: 'users' |
|
|
|
|
|
|
|
}); */ |
|
|
|
|
|
|
|
|
|
|
|
private users: {[userId: number]: User} = {}; |
|
|
|
private users: {[userId: number]: User} = {}; |
|
|
|
private usernames: {[username: string]: number} = {}; |
|
|
|
private usernames: {[username: string]: number} = {}; |
|
|
|
//public userAccess: {[userId: number]: string} = {};
|
|
|
|
|
|
|
|
private contactsIndex = searchIndexManager.createIndex(); |
|
|
|
private contactsIndex = searchIndexManager.createIndex(); |
|
|
|
private contactsFillPromise: Promise<Set<number>>; |
|
|
|
private contactsFillPromise: Promise<Set<number>>; |
|
|
|
public contactsList: Set<number> = new Set(); |
|
|
|
private contactsList: Set<number> = new Set(); |
|
|
|
private updatedContactsList = false; |
|
|
|
private updatedContactsList = false; |
|
|
|
|
|
|
|
|
|
|
|
private getTopPeersPromise: Promise<number[]>; |
|
|
|
private getTopPeersPromise: Promise<number[]>; |
|
|
@ -47,73 +51,63 @@ export class AppUsersManager { |
|
|
|
|
|
|
|
|
|
|
|
rootScope.on('state_synchronized', this.updateUsersStatuses); |
|
|
|
rootScope.on('state_synchronized', this.updateUsersStatuses); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.on('apiUpdate', (e) => { |
|
|
|
rootScope.addMultipleEventsListeners({ |
|
|
|
const update = e as Update; |
|
|
|
updateUserStatus: (update) => { |
|
|
|
//console.log('on apiUpdate', update);
|
|
|
|
const userId = update.user_id; |
|
|
|
switch(update._) { |
|
|
|
const user = this.users[userId]; |
|
|
|
case 'updateUserStatus': { |
|
|
|
if(user) { |
|
|
|
const userId = update.user_id; |
|
|
|
user.status = update.status; |
|
|
|
const user = this.users[userId]; |
|
|
|
if(user.status) { |
|
|
|
if(user) { |
|
|
|
if('expires' in user.status) { |
|
|
|
user.status = update.status; |
|
|
|
user.status.expires -= serverTimeManager.serverTimeOffset; |
|
|
|
if(user.status) { |
|
|
|
|
|
|
|
if('expires' in user.status) { |
|
|
|
|
|
|
|
user.status.expires -= serverTimeManager.serverTimeOffset; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if('was_online' in user.status) { |
|
|
|
|
|
|
|
user.status.was_online -= serverTimeManager.serverTimeOffset; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user.sortStatus = this.getUserStatusForSort(user.status); |
|
|
|
if('was_online' in user.status) { |
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
user.status.was_online -= serverTimeManager.serverTimeOffset; |
|
|
|
} //////else console.warn('No user by id:', userId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updateUserPhoto': { |
|
|
|
|
|
|
|
const userId = update.user_id; |
|
|
|
|
|
|
|
const user = this.users[userId]; |
|
|
|
|
|
|
|
if(user) { |
|
|
|
|
|
|
|
this.forceUserOnline(userId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(update.photo._ === 'userProfilePhotoEmpty') { |
|
|
|
|
|
|
|
delete user.photo; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
user.photo = safeReplaceObject(user.photo, update.photo); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
user.sortStatus = this.getUserStatusForSort(user.status); |
|
|
|
rootScope.broadcast('avatar_update', userId); |
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
} else console.warn('No user by id:', userId); |
|
|
|
} //////else console.warn('No user by id:', userId);
|
|
|
|
|
|
|
|
}, |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
updateUserPhoto: (update) => { |
|
|
|
|
|
|
|
const userId = update.user_id; |
|
|
|
case 'updateUserName': { |
|
|
|
const user = this.users[userId]; |
|
|
|
const userId = update.user_id; |
|
|
|
if(user) { |
|
|
|
const user = this.users[userId]; |
|
|
|
this.forceUserOnline(userId); |
|
|
|
if(user) { |
|
|
|
|
|
|
|
this.forceUserOnline(userId); |
|
|
|
if(update.photo._ === 'userProfilePhotoEmpty') { |
|
|
|
|
|
|
|
delete user.photo; |
|
|
|
this.saveApiUser(Object.assign({}, user, { |
|
|
|
} else { |
|
|
|
first_name: update.first_name, |
|
|
|
user.photo = safeReplaceObject(user.photo, update.photo); |
|
|
|
last_name: update.last_name, |
|
|
|
|
|
|
|
username: update.username |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
|
|
|
|
rootScope.broadcast('avatar_update', userId); |
|
|
|
|
|
|
|
} else console.warn('No user by id:', userId); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateUserName: (update) => { |
|
|
|
|
|
|
|
const userId = update.user_id; |
|
|
|
|
|
|
|
const user = this.users[userId]; |
|
|
|
|
|
|
|
if(user) { |
|
|
|
|
|
|
|
this.forceUserOnline(userId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.saveApiUser(Object.assign({}, user, { |
|
|
|
|
|
|
|
first_name: update.first_name, |
|
|
|
|
|
|
|
last_name: update.last_name, |
|
|
|
|
|
|
|
username: update.username |
|
|
|
|
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* case 'updateContactLink': |
|
|
|
|
|
|
|
this.onContactUpdated(update.user_id, update.my_link._ === 'contactLinkContact'); |
|
|
|
|
|
|
|
break; */ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* case 'updateContactLink': |
|
|
|
|
|
|
|
this.onContactUpdated(update.user_id, update.my_link._ === 'contactLinkContact'); |
|
|
|
|
|
|
|
break; */ |
|
|
|
|
|
|
|
|
|
|
|
rootScope.on('language_change', (e) => { |
|
|
|
rootScope.on('language_change', (e) => { |
|
|
|
const userId = this.getSelf().id; |
|
|
|
const userId = this.getSelf().id; |
|
|
|
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex); |
|
|
|
searchIndexManager.indexObject(userId, this.getUserSearchText(userId), this.contactsIndex); |
|
|
@ -350,19 +344,14 @@ export class AppUsersManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
safeReplaceObject(oldUser, user); |
|
|
|
safeReplaceObject(oldUser, user); |
|
|
|
|
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rootScope.broadcast('user_update', userId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(changedTitle) { |
|
|
|
if(changedTitle) { |
|
|
|
rootScope.broadcast('peer_title_edit', user.id); |
|
|
|
rootScope.broadcast('peer_title_edit', user.id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* public saveUserAccess(id: number, accessHash: string) { |
|
|
|
|
|
|
|
this.userAccess[id] = accessHash; |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public getUserStatusForSort(status: User['status'] | number) { |
|
|
|
public getUserStatusForSort(status: User['status'] | number) { |
|
|
|
if(typeof(status) === 'number') { |
|
|
|
if(typeof(status) === 'number') { |
|
|
|
status = this.getUser(status).status; |
|
|
|
status = this.getUser(status).status; |
|
|
@ -401,7 +390,7 @@ export class AppUsersManager { |
|
|
|
return id; |
|
|
|
return id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.users[id] || {id: id, pFlags: {deleted: true}, access_hash: ''/* this.userAccess[id] */} as User; |
|
|
|
return this.users[id] || {id: id, pFlags: {deleted: true}, access_hash: ''} as User; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public getSelf() { |
|
|
|
public getSelf() { |
|
|
@ -755,7 +744,7 @@ export class AppUsersManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public onContactUpdated(userId: number, isContact: boolean) { |
|
|
|
public onContactUpdated(userId: number, isContact: boolean) { |
|
|
|
const curIsContact = this.contactsList.has(userId); |
|
|
|
const curIsContact = this.isContact(userId); |
|
|
|
if(isContact !== curIsContact) { |
|
|
|
if(isContact !== curIsContact) { |
|
|
|
if(isContact) { |
|
|
|
if(isContact) { |
|
|
|
this.contactsList.add(userId) |
|
|
|
this.contactsList.add(userId) |
|
|
|