Fix handling contact update
This commit is contained in:
parent
4eaf47f84c
commit
d840352168
@ -333,7 +333,7 @@ export class AppChatsManager {
|
||||
|
||||
public isChannel(id: ChatId) {
|
||||
const chat = this.chats[id];
|
||||
return chat && (chat._ === 'channel' || chat._ === 'channelForbidden')/* || this.channelAccess[id] */;
|
||||
return !!(chat && (chat._ === 'channel' || chat._ === 'channelForbidden')/* || this.channelAccess[id] */);
|
||||
}
|
||||
|
||||
public isMegagroup(id: ChatId) {
|
||||
@ -341,8 +341,8 @@ export class AppChatsManager {
|
||||
return true;
|
||||
} */
|
||||
|
||||
const chat = this.chats[id];
|
||||
return chat && chat._ === 'channel' && chat.pFlags.megagroup;
|
||||
const chat: Chat = this.chats[id];
|
||||
return !!(chat && chat._ === 'channel' && chat.pFlags.megagroup);
|
||||
}
|
||||
|
||||
public isBroadcast(id: ChatId) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import type { Dialog } from './appMessagesManager';
|
||||
import type { UserAuth } from '../mtproto/mtproto_config';
|
||||
import { NULL_PEER_ID, UserAuth } from '../mtproto/mtproto_config';
|
||||
import type { MyTopPeer, TopPeerType, User } from './appUsersManager';
|
||||
import type { AuthState } from '../../types';
|
||||
import type FiltersStorage from '../storages/filters';
|
||||
@ -174,6 +174,8 @@ const ALL_KEYS = Object.keys(STATE_INIT) as any as Array<keyof State>;
|
||||
const REFRESH_KEYS = ['contactsList', 'stateCreatedTime',
|
||||
'maxSeenMsgId', 'filters', 'topPeers'] as any as Array<keyof State>;
|
||||
|
||||
export type StatePeerType = 'recentSearch' | 'topPeer' | 'dialog' | 'contact' | 'topMessage';
|
||||
|
||||
//const REFRESH_KEYS_WEEK = ['dialogs', 'allDialogsLoaded', 'updates', 'pinnedOrders'] as any as Array<keyof State>;
|
||||
|
||||
export class AppStateManager extends EventListenerBase<{
|
||||
@ -476,7 +478,7 @@ export class AppStateManager extends EventListenerBase<{
|
||||
});
|
||||
}
|
||||
|
||||
public requestPeer(peerId: PeerId, type: string, limit?: number) {
|
||||
public requestPeer(peerId: PeerId, type: StatePeerType, limit?: number) {
|
||||
let set = this.neededPeers.get(peerId);
|
||||
if(set && set.has(type)) {
|
||||
return;
|
||||
@ -496,11 +498,19 @@ export class AppStateManager extends EventListenerBase<{
|
||||
}
|
||||
}
|
||||
|
||||
public requestPeerSingle(peerId: PeerId, type: StatePeerType, keepPeerIdSingle: PeerId = peerId) {
|
||||
return this.requestPeer(peerId, type + '_' + keepPeerIdSingle as any, 1);
|
||||
}
|
||||
|
||||
public releaseSinglePeer(peerId: PeerId, type: StatePeerType) {
|
||||
return this.keepPeerSingle(NULL_PEER_ID, type + '_' + peerId as any);
|
||||
}
|
||||
|
||||
public isPeerNeeded(peerId: PeerId) {
|
||||
return this.neededPeers.has(peerId);
|
||||
}
|
||||
|
||||
public keepPeerSingle(peerId: PeerId, type: string) {
|
||||
public keepPeerSingle(peerId: PeerId, type: StatePeerType) {
|
||||
const existsPeerId = this.singlePeerMap.get(type);
|
||||
if(existsPeerId && existsPeerId !== peerId && this.neededPeers.has(existsPeerId)) {
|
||||
const set = this.neededPeers.get(existsPeerId);
|
||||
|
@ -261,7 +261,13 @@ export class AppUsersManager {
|
||||
public pushContact(id: UserId) {
|
||||
this.contactsList.add(id);
|
||||
this.contactsIndex.indexObject(id, this.getUserSearchText(id));
|
||||
appStateManager.requestPeer(id.toPeerId(), 'contacts');
|
||||
appStateManager.requestPeerSingle(id.toPeerId(), 'contact');
|
||||
}
|
||||
|
||||
public popContact(id: UserId) {
|
||||
this.contactsList.delete(id);
|
||||
this.contactsIndex.indexObject(id, ''); // delete search index
|
||||
appStateManager.releaseSinglePeer(id.toPeerId(), 'contact');
|
||||
}
|
||||
|
||||
public getUserSearchText(id: UserId) {
|
||||
@ -616,11 +622,11 @@ export class AppUsersManager {
|
||||
}
|
||||
|
||||
public isBot(id: UserId) {
|
||||
return this.users[id] && this.users[id].pFlags.bot;
|
||||
return this.users[id] && !!this.users[id].pFlags.bot;
|
||||
}
|
||||
|
||||
public isContact(id: UserId) {
|
||||
return this.contactsList.has(id) || (this.users[id] && this.users[id].pFlags.contact);
|
||||
return this.contactsList.has(id) || !!(this.users[id] && this.users[id].pFlags.contact);
|
||||
}
|
||||
|
||||
public isRegularUser(id: UserId) {
|
||||
@ -629,7 +635,7 @@ export class AppUsersManager {
|
||||
}
|
||||
|
||||
public isNonContactUser(id: UserId) {
|
||||
return this.isRegularUser(id) && !this.isContact(id) && id !== rootScope.myId;
|
||||
return this.isRegularUser(id) && !this.isContact(id) && id.toPeerId() !== rootScope.myId;
|
||||
}
|
||||
|
||||
public hasUser(id: UserId, allowMin?: boolean) {
|
||||
@ -639,7 +645,7 @@ export class AppUsersManager {
|
||||
|
||||
public canSendToUser(id: UserId) {
|
||||
const user = this.getUser(id);
|
||||
return !user.pFlags.deleted && user.id !== REPLIES_PEER_ID;
|
||||
return !user.pFlags.deleted && user.id.toPeerId() !== REPLIES_PEER_ID;
|
||||
}
|
||||
|
||||
public getUserPhoto(id: UserId) {
|
||||
@ -879,7 +885,7 @@ export class AppUsersManager {
|
||||
if(isContact) {
|
||||
this.pushContact(userId);
|
||||
} else {
|
||||
this.contactsList.delete(userId);
|
||||
this.popContact(userId);
|
||||
}
|
||||
|
||||
this.onContactsModified();
|
||||
|
@ -529,7 +529,7 @@ export default class DialogsStorage {
|
||||
|
||||
const fromId = message.viaBotId || message.fromId;
|
||||
if(fromId !== peerId) {
|
||||
this.appStateManager.requestPeer(fromId, 'topMessage_' + peerId, 1);
|
||||
this.appStateManager.requestPeerSingle(fromId, 'topMessage', peerId);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -557,7 +557,7 @@ export default class DialogsStorage {
|
||||
[peerId]: dialog
|
||||
});
|
||||
|
||||
this.appStateManager.requestPeer(peerId, 'dialog_' + peerId, 1);
|
||||
this.appStateManager.requestPeerSingle(peerId, 'dialog');
|
||||
|
||||
/* for(let id in this.appMessagesManager.filtersStorage.filters) {
|
||||
const filter = this.appMessagesManager.filtersStorage.filters[id];
|
||||
@ -644,8 +644,8 @@ export default class DialogsStorage {
|
||||
|
||||
public clearDialogFromState(dialog: Dialog, keepLocal: boolean) {
|
||||
const peerId = dialog.peerId;
|
||||
this.appStateManager.keepPeerSingle(NULL_PEER_ID, 'topMessage_' + peerId);
|
||||
this.appStateManager.keepPeerSingle(NULL_PEER_ID, 'dialog_' + peerId);
|
||||
this.appStateManager.releaseSinglePeer(peerId, 'topMessage');
|
||||
this.appStateManager.releaseSinglePeer(peerId, 'dialog');
|
||||
this.storage.delete(peerId, keepLocal);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user