From 287dfe640a16f7f5a62cc9603ac9227dfb3441c1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 3 May 2023 20:20:40 +0400 Subject: [PATCH] Chat Management: Changing the group type (#3136) --- src/api/gramjs/methods/management.ts | 7 +++++-- src/util/areDeepEqual.ts | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/gramjs/methods/management.ts b/src/api/gramjs/methods/management.ts index 8ba75360b..215107667 100644 --- a/src/api/gramjs/methods/management.ts +++ b/src/api/gramjs/methods/management.ts @@ -51,14 +51,17 @@ export async function setChatUsername( })); const usernames = chat.usernames - ? chat.usernames.map((u) => (u.isEditable ? { ...u, username } : u)) + ? chat.usernames + .map((u) => (u.isEditable ? { ...u, username } : u)) + // User can remove username from chat when changing it type to private, so we need to filter out empty usernames + .filter((u) => u.username) : [{ username, isEditable: true, isActive: true }]; if (result) { onUpdate({ '@type': 'updateChat', id: chat.id, - chat: { usernames }, + chat: { usernames: usernames.length ? usernames : undefined }, }); } diff --git a/src/util/areDeepEqual.ts b/src/util/areDeepEqual.ts index 21e33e374..508bf5f92 100644 --- a/src/util/areDeepEqual.ts +++ b/src/util/areDeepEqual.ts @@ -31,5 +31,6 @@ export function areDeepEqual(value1: T, value2: T): boolean { const object2 = value2 as AnyLiteral; const keys1 = Object.keys(object1); - return keys1.every((key1) => areDeepEqual(object1[key1], object2[key1])); + return keys1.length === Object.keys(object2).length + && keys1.every((key1) => areDeepEqual(object1[key1], object2[key1])); }