Browse Source

Fix handling contact update

master
morethanwords 3 years ago
parent
commit
d840352168
  1. 6
      src/lib/appManagers/appChatsManager.ts
  2. 16
      src/lib/appManagers/appStateManager.ts
  3. 18
      src/lib/appManagers/appUsersManager.ts
  4. 8
      src/lib/storages/dialogs.ts

6
src/lib/appManagers/appChatsManager.ts

@ -333,7 +333,7 @@ export class AppChatsManager {
public isChannel(id: ChatId) { public isChannel(id: ChatId) {
const chat = this.chats[id]; 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) { public isMegagroup(id: ChatId) {
@ -341,8 +341,8 @@ export class AppChatsManager {
return true; return true;
} */ } */
const chat = this.chats[id]; const chat: Chat = this.chats[id];
return chat && chat._ === 'channel' && chat.pFlags.megagroup; return !!(chat && chat._ === 'channel' && chat.pFlags.megagroup);
} }
public isBroadcast(id: ChatId) { public isBroadcast(id: ChatId) {

16
src/lib/appManagers/appStateManager.ts

@ -5,7 +5,7 @@
*/ */
import type { Dialog } from './appMessagesManager'; 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 { MyTopPeer, TopPeerType, User } from './appUsersManager';
import type { AuthState } from '../../types'; import type { AuthState } from '../../types';
import type FiltersStorage from '../storages/filters'; 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', const REFRESH_KEYS = ['contactsList', 'stateCreatedTime',
'maxSeenMsgId', 'filters', 'topPeers'] as any as Array<keyof State>; '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>; //const REFRESH_KEYS_WEEK = ['dialogs', 'allDialogsLoaded', 'updates', 'pinnedOrders'] as any as Array<keyof State>;
export class AppStateManager extends EventListenerBase<{ 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); let set = this.neededPeers.get(peerId);
if(set && set.has(type)) { if(set && set.has(type)) {
return; 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) { public isPeerNeeded(peerId: PeerId) {
return this.neededPeers.has(peerId); return this.neededPeers.has(peerId);
} }
public keepPeerSingle(peerId: PeerId, type: string) { public keepPeerSingle(peerId: PeerId, type: StatePeerType) {
const existsPeerId = this.singlePeerMap.get(type); const existsPeerId = this.singlePeerMap.get(type);
if(existsPeerId && existsPeerId !== peerId && this.neededPeers.has(existsPeerId)) { if(existsPeerId && existsPeerId !== peerId && this.neededPeers.has(existsPeerId)) {
const set = this.neededPeers.get(existsPeerId); const set = this.neededPeers.get(existsPeerId);

18
src/lib/appManagers/appUsersManager.ts

@ -261,7 +261,13 @@ export class AppUsersManager {
public pushContact(id: UserId) { public pushContact(id: UserId) {
this.contactsList.add(id); this.contactsList.add(id);
this.contactsIndex.indexObject(id, this.getUserSearchText(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) { public getUserSearchText(id: UserId) {
@ -616,11 +622,11 @@ export class AppUsersManager {
} }
public isBot(id: UserId) { 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) { 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) { public isRegularUser(id: UserId) {
@ -629,7 +635,7 @@ export class AppUsersManager {
} }
public isNonContactUser(id: UserId) { 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) { public hasUser(id: UserId, allowMin?: boolean) {
@ -639,7 +645,7 @@ export class AppUsersManager {
public canSendToUser(id: UserId) { public canSendToUser(id: UserId) {
const user = this.getUser(id); 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) { public getUserPhoto(id: UserId) {
@ -879,7 +885,7 @@ export class AppUsersManager {
if(isContact) { if(isContact) {
this.pushContact(userId); this.pushContact(userId);
} else { } else {
this.contactsList.delete(userId); this.popContact(userId);
} }
this.onContactsModified(); this.onContactsModified();

8
src/lib/storages/dialogs.ts

@ -529,7 +529,7 @@ export default class DialogsStorage {
const fromId = message.viaBotId || message.fromId; const fromId = message.viaBotId || message.fromId;
if(fromId !== peerId) { if(fromId !== peerId) {
this.appStateManager.requestPeer(fromId, 'topMessage_' + peerId, 1); this.appStateManager.requestPeerSingle(fromId, 'topMessage', peerId);
} }
break; break;
@ -557,7 +557,7 @@ export default class DialogsStorage {
[peerId]: dialog [peerId]: dialog
}); });
this.appStateManager.requestPeer(peerId, 'dialog_' + peerId, 1); this.appStateManager.requestPeerSingle(peerId, 'dialog');
/* for(let id in this.appMessagesManager.filtersStorage.filters) { /* for(let id in this.appMessagesManager.filtersStorage.filters) {
const filter = this.appMessagesManager.filtersStorage.filters[id]; const filter = this.appMessagesManager.filtersStorage.filters[id];
@ -644,8 +644,8 @@ export default class DialogsStorage {
public clearDialogFromState(dialog: Dialog, keepLocal: boolean) { public clearDialogFromState(dialog: Dialog, keepLocal: boolean) {
const peerId = dialog.peerId; const peerId = dialog.peerId;
this.appStateManager.keepPeerSingle(NULL_PEER_ID, 'topMessage_' + peerId); this.appStateManager.releaseSinglePeer(peerId, 'topMessage');
this.appStateManager.keepPeerSingle(NULL_PEER_ID, 'dialog_' + peerId); this.appStateManager.releaseSinglePeer(peerId, 'dialog');
this.storage.delete(peerId, keepLocal); this.storage.delete(peerId, keepLocal);
} }

Loading…
Cancel
Save