From b2bbe7acd6e2b5832a77d13af144b63a283b2bb2 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Thu, 23 Sep 2021 19:56:19 +0400 Subject: [PATCH] Fix showing wrong pinned message --- src/components/chat/topbar.ts | 85 ++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/components/chat/topbar.ts b/src/components/chat/topbar.ts index 6395aca6..c01376b6 100644 --- a/src/components/chat/topbar.ts +++ b/src/components/chat/topbar.ts @@ -41,6 +41,7 @@ import { ChatFull } from "../../layer"; import PopupPickUser from "../popups/pickUser"; import PopupPeer from "../popups/peer"; import generateVerifiedIcon from "../generateVerifiedIcon"; +import { fastRaf } from "../../helpers/schedulers"; export default class ChatTopbar { public container: HTMLDivElement; @@ -215,46 +216,7 @@ export default class ChatTopbar { text: 'Pinned Messages', onClick: () => this.openPinned(false), verify: () => mediaSizes.isMobile - }, */ { - icon: 'forward', - text: 'ShareContact', - onClick: () => { - const contactPeerId = this.peerId; - new PopupPickUser({ - peerTypes: ['dialogs', 'contacts'], - onSelect: (peerId) => { - return new Promise((resolve, reject) => { - new PopupPeer('', { - titleLangKey: 'SendMessageTitle', - descriptionLangKey: 'SendContactToGroupText', - descriptionLangArgs: [new PeerTitle({peerId, dialog: true}).element], - buttons: [{ - langKey: 'Send', - callback: () => { - resolve(); - - this.appMessagesManager.sendOther(peerId, this.appUsersManager.getContactMediaInput(contactPeerId)); - this.chat.appImManager.setInnerPeer(peerId); - } - }, { - langKey: 'Cancel', - callback: () => { - reject(); - }, - isCancel: true, - }], - peerId, - overlayClosable: true - }).show(); - }); - }, - placeholder: 'ShareModal.Search.Placeholder', - chatRightsAction: 'send_messages', - selfPresence: 'ChatYourSelf' - }); - }, - verify: () => rootScope.myId !== this.peerId && this.peerId > 0 && this.appUsersManager.isContact(this.peerId) - }, { + }, */{ icon: 'mute', text: 'ChatList.Context.Mute', onClick: () => { @@ -311,6 +273,45 @@ export default class ChatTopbar { this.chat.selection.cancelSelection(); }, verify: () => this.chat.selection.isSelecting + }, { + icon: 'forward', + text: 'ShareContact', + onClick: () => { + const contactPeerId = this.peerId; + new PopupPickUser({ + peerTypes: ['dialogs', 'contacts'], + onSelect: (peerId) => { + return new Promise((resolve, reject) => { + new PopupPeer('', { + titleLangKey: 'SendMessageTitle', + descriptionLangKey: 'SendContactToGroupText', + descriptionLangArgs: [new PeerTitle({peerId, dialog: true}).element], + buttons: [{ + langKey: 'Send', + callback: () => { + resolve(); + + this.appMessagesManager.sendOther(peerId, this.appUsersManager.getContactMediaInput(contactPeerId)); + this.chat.appImManager.setInnerPeer(peerId); + } + }, { + langKey: 'Cancel', + callback: () => { + reject(); + }, + isCancel: true, + }], + peerId, + overlayClosable: true + }).show(); + }); + }, + placeholder: 'ShareModal.Search.Placeholder', + chatRightsAction: 'send_messages', + selfPresence: 'ChatYourSelf' + }); + }, + verify: () => rootScope.myId !== this.peerId && this.peerId > 0 && this.appUsersManager.isContact(this.peerId) }, { icon: 'delete danger', text: 'Delete', @@ -506,7 +507,7 @@ export default class ChatTopbar { const middleware = this.chat.bubbles.getMiddleware(); if(this.pinnedMessage) { // * replace with new one if(this.chat.type === 'chat') { - if(this.wasPeerId) { // * change + if(this.wasPeerId !== undefined) { // * change const newPinnedMessage = new ChatPinnedMessage(this, this.chat, this.appMessagesManager, this.appPeersManager); this.pinnedMessage.pinnedMessageContainer.divAndCaption.container.replaceWith(newPinnedMessage.pinnedMessageContainer.divAndCaption.container); this.pinnedMessage.destroy(); @@ -531,7 +532,7 @@ export default class ChatTopbar { } } - window.requestAnimationFrame(() => { + fastRaf(() => { this.setTitle(); this.setPeerStatus(true); this.setMutedState();