From 2fb747c5845a369a7182be5d8a7e98010b883426 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Thu, 21 Oct 2021 19:51:25 +0400 Subject: [PATCH] Fix some identifies --- src/components/sidebarLeft/tabs/newGroup.ts | 6 +++--- src/components/sidebarRight/tabs/editContact.ts | 2 +- src/components/sidebarRight/tabs/sharedMedia.ts | 2 +- src/helpers/dom/getRichElementValue.ts | 2 +- src/helpers/peerIdPolyfill.ts | 2 +- src/lib/appManagers/appImManager.ts | 4 ++-- src/lib/appManagers/appInlineBotsManager.ts | 2 +- src/lib/appManagers/appMessagesManager.ts | 2 +- src/lib/appManagers/appProfileManager.ts | 4 ++-- src/lib/mtproto/mtprotoworker.ts | 1 - src/lib/richtextprocessor.ts | 2 +- 11 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/sidebarLeft/tabs/newGroup.ts b/src/components/sidebarLeft/tabs/newGroup.ts index 3ade5d00..c3baa209 100644 --- a/src/components/sidebarLeft/tabs/newGroup.ts +++ b/src/components/sidebarLeft/tabs/newGroup.ts @@ -53,7 +53,7 @@ export default class AppNewGroupTab extends SliderSuperTab { const title = this.groupNameInputField.value; this.nextBtn.disabled = true; - appChatsManager.createChat(title, this.peerIds).then((chatId) => { + appChatsManager.createChat(title, this.peerIds.map(peerId => peerId.toUserId())).then((chatId) => { if(this.uploadAvatar) { this.uploadAvatar().then((inputFile) => { appChatsManager.editPhoto(chatId, inputFile); @@ -81,10 +81,10 @@ export default class AppNewGroupTab extends SliderSuperTab { this.nextBtn.disabled = false; } - public open(userIds: PeerId[]) { + public open(peerIds: PeerId[]) { const result = super.open(); result.then(() => { - this.peerIds = userIds; + this.peerIds = peerIds; this.peerIds.forEach(userId => { let {dom} = appDialogsManager.addDialogNew({ diff --git a/src/components/sidebarRight/tabs/editContact.ts b/src/components/sidebarRight/tabs/editContact.ts index c1b0c1a5..a62f1808 100644 --- a/src/components/sidebarRight/tabs/editContact.ts +++ b/src/components/sidebarRight/tabs/editContact.ts @@ -31,7 +31,7 @@ export default class AppEditContactTab extends SliderSuperTab { protected init() { this.container.classList.add('edit-peer-container', 'edit-contact-container'); - const isNew = !appUsersManager.isContact(this.peerId); + const isNew = !appUsersManager.isContact(this.peerId.toUserId()); this.setTitle(isNew ? 'AddContactTitle' : 'Edit'); { diff --git a/src/components/sidebarRight/tabs/sharedMedia.ts b/src/components/sidebarRight/tabs/sharedMedia.ts index 4c5e9cea..15a1f058 100644 --- a/src/components/sidebarRight/tabs/sharedMedia.ts +++ b/src/components/sidebarRight/tabs/sharedMedia.ts @@ -433,7 +433,7 @@ export default class AppSharedMediaTab extends SliderSuperTab { private toggleEditBtn() { let show: boolean; if(this.peerId.isUser()) { - show = this.peerId !== rootScope.myId && appUsersManager.isContact(this.peerId); + show = this.peerId !== rootScope.myId && appUsersManager.isContact(this.peerId.toUserId()); } else { show = appChatsManager.hasRights(this.peerId.toChatId(), 'change_info'); } diff --git a/src/helpers/dom/getRichElementValue.ts b/src/helpers/dom/getRichElementValue.ts index 8ef37dcf..77b5deac 100644 --- a/src/helpers/dom/getRichElementValue.ts +++ b/src/helpers/dom/getRichElementValue.ts @@ -77,7 +77,7 @@ export default function getRichElementValue(node: HTMLElement, lines: string[], _: tag.entityName, offset: offset.offset, length: nodeValue.length, - user_id: parentElement.dataset.follow + user_id: parentElement.dataset.follow.toUserId() }); } else { entities.push({ diff --git a/src/helpers/peerIdPolyfill.ts b/src/helpers/peerIdPolyfill.ts index eca8dd44..6de8771f 100644 --- a/src/helpers/peerIdPolyfill.ts +++ b/src/helpers/peerIdPolyfill.ts @@ -25,7 +25,7 @@ Number.prototype.toUserId = function() { }; Number.prototype.toChatId = function() { - return -this; + return Math.abs(this as any); }; Number.prototype.toPeerId = function(isChat?: boolean) { diff --git a/src/lib/appManagers/appImManager.ts b/src/lib/appManagers/appImManager.ts index ff3b56b6..54a4a9d8 100644 --- a/src/lib/appManagers/appImManager.ts +++ b/src/lib/appManagers/appImManager.ts @@ -535,8 +535,8 @@ export class AppImManager { } case INTERNAL_LINK_TYPE.PRIVATE_POST: { - const chatId: ChatId = link.channel; - const peerId = link.channel.toPeerId(true); + const chatId = link.channel.toChatId(); + const peerId = chatId.toPeerId(true); const chat = appChatsManager.getChat(chatId); if(chat.deleted) { diff --git a/src/lib/appManagers/appInlineBotsManager.ts b/src/lib/appManagers/appInlineBotsManager.ts index a343c012..33a29fca 100644 --- a/src/lib/appManagers/appInlineBotsManager.ts +++ b/src/lib/appManagers/appInlineBotsManager.ts @@ -107,7 +107,7 @@ export class AppInlineBotsManager { public switchToPM(fromPeerId: PeerId, botId: BotId, startParam: string) { this.setHash[botId] = {peerId: fromPeerId, time: Date.now()}; rootScope.dispatchEvent('history_focus', {peerId: botId.toPeerId()}); - return appMessagesManager.startBot(botId, '0', startParam); + return appMessagesManager.startBot(botId, undefined, startParam); } /* diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index c778ee85..409a6eff 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -3069,7 +3069,7 @@ export class AppMessagesManager { }); } - public startBot(botId: BotId, chatId: ChatId, startParam: string) { + public startBot(botId: BotId, chatId?: ChatId, startParam?: string) { const peerId = chatId ? chatId.toPeerId(true) : botId.toPeerId(); if(startParam) { const randomId = randomLong(); diff --git a/src/lib/appManagers/appProfileManager.ts b/src/lib/appManagers/appProfileManager.ts index e3dd5671..558cb0ea 100644 --- a/src/lib/appManagers/appProfileManager.ts +++ b/src/lib/appManagers/appProfileManager.ts @@ -170,7 +170,7 @@ export class AppProfileManager { appUsersManager.saveApiUser(user, true); if(userFull.profile_photo) { - userFull.profile_photo = appPhotosManager.savePhoto(userFull.profile_photo, {type: 'profilePhoto', peerId: peerId}); + userFull.profile_photo = appPhotosManager.savePhoto(userFull.profile_photo, {type: 'profilePhoto', peerId}); } if(userFull.about !== undefined) { @@ -262,7 +262,7 @@ export class AppProfileManager { appUsersManager.saveApiUsers(result.users); const fullChat = result.full_chat as ChatFull.chatFull; if(fullChat && fullChat.chat_photo && fullChat.chat_photo.id) { - fullChat.chat_photo = appPhotosManager.savePhoto(fullChat.chat_photo, {type: 'profilePhoto', peerId: peerId}); + fullChat.chat_photo = appPhotosManager.savePhoto(fullChat.chat_photo, {type: 'profilePhoto', peerId}); } //appMessagesManager.savePinnedMessage(peerId, fullChat.pinned_msg_id); diff --git a/src/lib/mtproto/mtprotoworker.ts b/src/lib/mtproto/mtprotoworker.ts index 6b52816e..cafe90f3 100644 --- a/src/lib/mtproto/mtprotoworker.ts +++ b/src/lib/mtproto/mtprotoworker.ts @@ -31,7 +31,6 @@ import telegramMeWebManager from './telegramMeWebManager'; import { CacheStorageDbName } from '../cacheStorage'; import { pause } from '../../helpers/schedulers/pause'; import IS_WEBP_SUPPORTED from '../../environment/webpSupport'; -import appUsersManager from '../appManagers/appUsersManager'; type Task = { taskId: number, diff --git a/src/lib/richtextprocessor.ts b/src/lib/richtextprocessor.ts index 7096e35a..46d8d0e4 100644 --- a/src/lib/richtextprocessor.ts +++ b/src/lib/richtextprocessor.ts @@ -305,7 +305,7 @@ namespace RichTextProcessor { } else if(match[11]) { // custom mention entity = { _: 'messageEntityMentionName', - user_id: match[10], + user_id: match[10].toUserId(), offset: matchIndex, length: text.length };