From 7be8a806ab8347f5bc78c12a36f1064a5b3bb064 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Thu, 14 Apr 2022 02:29:41 +0300 Subject: [PATCH] Notifications: Ignore muted state for mention Display forwarded message content when it's single --- src/lib/appManagers/appMessagesManager.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 4480012b..dd459a05 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -4483,7 +4483,7 @@ export class AppMessagesManager { const notifyPeerToHandle = this.notificationsToHandle[peerId]; this.getNotifyPeerSettings(peerId).then(({muted, peerTypeNotifySettings}) => { const topMessage = notifyPeerToHandle.topMessage; - if(muted || !topMessage.pFlags.unread) { + if((muted && !topMessage.pFlags.mentioned) || !topMessage.pFlags.unread) { return; } @@ -4734,9 +4734,9 @@ export class AppMessagesManager { ) ) { this.getNotifyPeerSettings(peerId).then(({muted, peerTypeNotifySettings}) => { - if(muted || !peerTypeNotifySettings.show_previews) return; + if(/* muted || */!peerTypeNotifySettings.show_previews) return; this.notifyAboutMessage(message, { - userReaction: recentReaction, + peerReaction: recentReaction, peerTypeNotifySettings }); }); @@ -5591,7 +5591,7 @@ export class AppMessagesManager { private notifyAboutMessage(message: MyMessage, options: Partial<{ fwdCount: number, - userReaction: MessagePeerReaction, + peerReaction: MessagePeerReaction, peerTypeNotifySettings: PeerNotifySettings }> = {}) { const peerId = this.getMessagePeer(message); @@ -5606,15 +5606,15 @@ export class AppMessagesManager { let notificationMessage: string; if(options.peerTypeNotifySettings.show_previews) { - if(message._ === 'message' && message.fwd_from && options.fwdCount) { + if(message._ === 'message' && message.fwd_from && options.fwdCount > 1) { notificationMessage = I18n.format('Notifications.Forwarded', true, [options.fwdCount]); } else { notificationMessage = this.wrapMessageForReply(message, undefined, undefined, true); - if(options.userReaction) { + if(options.peerReaction) { const langPackKey: LangPackKey = /* isAnyChat ? 'Notification.Group.Reacted' : */'Notification.Contact.Reacted'; const args: FormatterArguments = [ - RichTextProcessor.fixEmoji(options.userReaction.reaction), // can be plain heart + RichTextProcessor.fixEmoji(options.peerReaction.reaction), // can be plain heart notificationMessage ]; @@ -5629,14 +5629,15 @@ export class AppMessagesManager { notificationMessage = I18n.format('Notifications.New', true); } - if(options.userReaction) { + if(options.peerReaction) { notification.noIncrement = true; notification.silent = true; } + const notificationFromPeerId = options.peerReaction ? appPeersManager.getPeerId(options.peerReaction.peer_id) : message.fromId; notification.title = appPeersManager.getPeerTitle(peerId, true); - if(isAnyChat && message.fromId !== message.peerId) { - notification.title = appPeersManager.getPeerTitle(message.fromId, true) + + if(isAnyChat && notificationFromPeerId !== message.peerId) { + notification.title = appPeersManager.getPeerTitle(notificationFromPeerId, true) + ' @ ' + notification.title; } @@ -5655,7 +5656,7 @@ export class AppMessagesManager { const peerPhoto = appPeersManager.getPeerPhoto(peerId); if(peerPhoto) { appAvatarsManager.loadAvatar(peerId, peerPhoto, 'photo_small').loadPromise.then(url => { - if(message.pFlags.unread || options.userReaction) { + if(message.pFlags.unread || options.peerReaction) { notification.image = url; appNotificationsManager.notify(notification); }