From 0d8d776e52bc2a6a258a85fa1afe691a95ca3e6d Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Wed, 1 Feb 2023 17:39:57 +0400 Subject: [PATCH] Fix grouping out messages when sending anonymous --- src/components/chat/bubbleGroups.ts | 5 +++-- src/components/chat/chat.ts | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/chat/bubbleGroups.ts b/src/components/chat/bubbleGroups.ts index c561e4a6e..ca989ebd6 100644 --- a/src/components/chat/bubbleGroups.ts +++ b/src/components/chat/bubbleGroups.ts @@ -404,7 +404,8 @@ export default class BubbleGroups { !item1.single && !item2.single && item1.message.pFlags.out === item2.message.pFlags.out && - (!this.chat.isAllMessagesForum || getMessageThreadId(item1.message, true) === getMessageThreadId(item2.message, true)); + (!this.chat.isAllMessagesForum || getMessageThreadId(item1.message, true) === getMessageThreadId(item2.message, true)) && + (!item1.message.pFlags.out || item1.message.fromId === rootScope.myId); } getSiblingsAtIndex(itemIndex: number, items: GroupItem[]) { @@ -467,7 +468,7 @@ export default class BubbleGroups { } getMessageFromId(message: MyMessage) { - let fromId = message.viaBotId || message.fromId; + let fromId = /* (this.chat.peerId.isAnyChat() && message.viaBotId) || */message.fromId; // fix for saved messages forward to self if(fromId === rootScope.myId && message.peerId === rootScope.myId && (message as Message.message).fwdFromId === fromId) { diff --git a/src/components/chat/chat.ts b/src/components/chat/chat.ts index f86c7d972..f0356856b 100644 --- a/src/components/chat/chat.ts +++ b/src/components/chat/chat.ts @@ -89,6 +89,7 @@ export default class Chat extends EventListenerBase<{ public isMegagroup: boolean; public isForum: boolean; public isAllMessagesForum: boolean; + public isAnonymousSending: boolean; public animationGroup: AnimationItemGroup; @@ -349,6 +350,16 @@ export default class Chat extends EventListenerBase<{ } }); + this.bubbles.listenerSetter.add(rootScope)('chat_update', async(chatId) => { + const {peerId} = this; + if(peerId.isAnyChat() && peerId.toChatId() === chatId) { + const isAnonymousSending = await this.managers.appMessagesManager.isAnonymousSending(peerId); + if(peerId === this.peerId) { + this.isAnonymousSending = isAnonymousSending; + } + } + }); + const freezeObservers = (freeze: boolean) => { const cb = () => { this.bubbles.observer?.toggleObservingNew(freeze); @@ -441,7 +452,8 @@ export default class Chat extends EventListenerBase<{ isBroadcast, isChannel, isBot, - isForum + isForum, + isAnonymousSending ] = await m(Promise.all([ this.managers.appPeersManager.noForwards(peerId), this.managers.appPeersManager.isPeerRestricted(peerId), @@ -451,7 +463,8 @@ export default class Chat extends EventListenerBase<{ this.managers.appPeersManager.isBroadcast(peerId), this.managers.appPeersManager.isChannel(peerId), this.managers.appPeersManager.isBot(peerId), - this.managers.appPeersManager.isForum(peerId) + this.managers.appPeersManager.isForum(peerId), + this.managers.appMessagesManager.isAnonymousSending(peerId) ])); // ! WARNING: TEMPORARY, HAVE TO GET TOPIC @@ -468,6 +481,7 @@ export default class Chat extends EventListenerBase<{ this.isBot = isBot; this.isForum = isForum; this.isAllMessagesForum = isForum && !threadId; + this.isAnonymousSending = isAnonymousSending; if(threadId && !this.isForum) { options.type = 'discussion';