From 5cae7dcad92ff67e048c060d1b580019baf2484d Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 4 May 2021 00:12:46 +0400 Subject: [PATCH] Fix handling chat photo update --- src/layer.d.ts | 11 ++++++---- src/lib/appManagers/appChatsManager.ts | 23 ++++++++++---------- src/scripts/in/schema_additional_params.json | 17 ++++++++++++++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/layer.d.ts b/src/layer.d.ts index 0516a13f..d084d298 100644 --- a/src/layer.d.ts +++ b/src/layer.d.ts @@ -600,13 +600,14 @@ export namespace Chat { migrated_to?: InputChannel, admin_rights?: ChatAdminRights, default_banned_rights?: ChatBannedRights, - rTitle?: string + initials?: string }; export type chatForbidden = { _: 'chatForbidden', id: number, - title: string + title: string, + initials?: string }; export type channel = { @@ -641,7 +642,8 @@ export namespace Chat { admin_rights?: ChatAdminRights, banned_rights?: ChatBannedRights, default_banned_rights?: ChatBannedRights, - participants_count?: number + participants_count?: number, + initials?: string }; export type channelForbidden = { @@ -654,7 +656,8 @@ export namespace Chat { id: number, access_hash: string, title: string, - until_date?: number + until_date?: number, + initials?: string }; } diff --git a/src/lib/appManagers/appChatsManager.ts b/src/lib/appManagers/appChatsManager.ts index 4087f8f2..57f65df3 100644 --- a/src/lib/appManagers/appChatsManager.ts +++ b/src/lib/appManagers/appChatsManager.ts @@ -12,7 +12,7 @@ import { MOUNT_CLASS_TO } from "../../config/debug"; import { numberThousandSplitter } from "../../helpers/number"; import { isObject, safeReplaceObject, copy, deepEqual } from "../../helpers/object"; -import { ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipant, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Update, Updates } from "../../layer"; +import { ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipant, ChatParticipants, ChatPhoto, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Update, Updates } from "../../layer"; import { i18n, LangPackKey } from "../langPack"; import apiManagerProxy from "../mtproto/mtprotoworker"; import apiManager from '../mtproto/mtprotoworker'; @@ -178,7 +178,8 @@ export class AppChatsManager { apiChats.forEach(chat => this.saveApiChat(chat, override)); } - public saveApiChat(chat: any, override?: boolean) { + public saveApiChat(chat: Chat, override?: boolean) { + if(chat._ === 'chatEmpty') return; /* if(chat._ !== 'chat' && chat._ !== 'channel') { return; } */ @@ -186,17 +187,17 @@ export class AppChatsManager { // * exclude from state // defineNotNumerableProperties(chat, ['rTitle', 'initials']); - const oldChat = this.chats[chat.id]; + const oldChat: Exclude = this.chats[chat.id]; /* if(oldChat && !override) { return; } */ - if(chat.pFlags === undefined) { - chat.pFlags = {}; + if((chat as Chat.chat).pFlags === undefined) { + (chat as Chat.chat).pFlags = {}; } - if(chat.pFlags.min && oldChat !== undefined) { + if((chat as Chat.channel).pFlags.min && oldChat !== undefined) { return; } @@ -205,8 +206,8 @@ export class AppChatsManager { if(chat._ === 'channel' && chat.participants_count === undefined && oldChat !== undefined && - oldChat.participants_count) { - chat.participants_count = oldChat.participants_count; + (oldChat as Chat.channel).participants_count) { + chat.participants_count = (oldChat as Chat.channel).participants_count; } /* if(chat.username) { @@ -218,9 +219,9 @@ export class AppChatsManager { if(oldChat === undefined) { this.chats[chat.id] = chat; } else { - const oldPhoto = oldChat.photo?.photo_small; - const newPhoto = chat.photo?.photo_small; - if(JSON.stringify(oldPhoto) !== JSON.stringify(newPhoto)) { + const oldPhotoId = ((oldChat as Chat.chat).photo as ChatPhoto.chatPhoto)?.photo_id; + const newPhotoId = ((chat as Chat.chat).photo as ChatPhoto.chatPhoto)?.photo_id; + if(oldPhotoId !== newPhotoId) { changedPhoto = true; } diff --git a/src/scripts/in/schema_additional_params.json b/src/scripts/in/schema_additional_params.json index f6fa7d9b..039dfce4 100644 --- a/src/scripts/in/schema_additional_params.json +++ b/src/scripts/in/schema_additional_params.json @@ -114,7 +114,22 @@ }, { "predicate": "chat", "params": [ - {"name": "rTitle", "type": "string"} + {"name": "initials", "type": "string"} + ] +}, { + "predicate": "chatForbidden", + "params": [ + {"name": "initials", "type": "string"} + ] +}, { + "predicate": "channel", + "params": [ + {"name": "initials", "type": "string"} + ] +}, { + "predicate": "channelForbidden", + "params": [ + {"name": "initials", "type": "string"} ] }, { "predicate": "messageActionChatLeave",