Basic Group: Fix API errors (#3845)

This commit is contained in:
Alexander Zinchuk 2023-09-13 12:21:48 +02:00
parent ef1afd2379
commit e26250071d
2 changed files with 9 additions and 8 deletions

View File

@ -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';

View File

@ -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