From e26250071dae9cc738564fce350e2981528838b4 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 13 Sep 2023 12:21:48 +0200 Subject: [PATCH] Basic Group: Fix API errors (#3845) --- src/api/gramjs/gramjsBuilders/index.ts | 8 +++++++- src/global/helpers/users.ts | 9 ++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/gramjs/gramjsBuilders/index.ts b/src/api/gramjs/gramjsBuilders/index.ts index b8c5508f7..ee1db52eb 100644 --- a/src/api/gramjs/gramjsBuilders/index.ts +++ b/src/api/gramjs/gramjsBuilders/index.ts @@ -39,6 +39,12 @@ import localDb from '../localDb'; const CHANNEL_ID_MIN_LENGTH = 11; // Example: -1000000000 +function checkIfChannelId(id: string) { + // HOTFIX New group id range starts with -4 + if (id.length === CHANNEL_ID_MIN_LENGTH && id.startsWith('-4')) return false; + return id.length >= CHANNEL_ID_MIN_LENGTH; +} + export function getEntityTypeById(chatOrUserId: string) { if (typeof chatOrUserId === 'number') { return getEntityTypeByDeprecatedId(chatOrUserId); @@ -46,7 +52,7 @@ export function getEntityTypeById(chatOrUserId: string) { if (!chatOrUserId.startsWith('-')) { return 'user'; - } else if (chatOrUserId.length >= CHANNEL_ID_MIN_LENGTH) { + } else if (checkIfChannelId(chatOrUserId)) { return 'channel'; } else { return 'chat'; diff --git a/src/global/helpers/users.ts b/src/global/helpers/users.ts index b615386f7..95bab0605 100644 --- a/src/global/helpers/users.ts +++ b/src/global/helpers/users.ts @@ -261,13 +261,8 @@ export function filterUsersByName( }); } -export function getUserIdDividend(userId: string) { - // Workaround for old-fashioned IDs stored locally - if (typeof userId === 'number') { - return Math.abs(userId); - } - - return Math.abs(Number(userId)); +export function getUserIdDividend(peerId: string) { + return Math.abs(Number(peerId)); } // https://github.com/telegramdesktop/tdesktop/blob/371510cfe23b0bd226de8c076bc49248fbe40c26/Telegram/SourceFiles/data/data_peer.cpp#L53