From a2c93bc040359bf69c3128f512ea40ad2311b0f0 Mon Sep 17 00:00:00 2001 From: Nicholas Guriev Date: Thu, 17 Aug 2017 18:57:19 +0300 Subject: [PATCH] Fix updates of mute status in context menu of dialog list Signed-off-by: Nicholas Guriev --- Telegram/SourceFiles/mainwidget.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index dde0ff5bf..baab1763f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2248,16 +2248,17 @@ void MainWidget::fillPeerMenu(PeerData *peer, base::lambda(); - QAction *muteAction; - if (!peer->isMuted()) { - muteAction = callback(lang(lng_disable_notifications_from_tray), [peer] { + auto muteAction = callback(!peer->isMuted() ? lang(lng_disable_notifications_from_tray) : lang(lng_enable_notifications_from_tray), [peer, muteSubscription] { + // We have to capture the muteSubscription pointer in this lambda for + // real time updates of the action when an user changes mute status of + // the peer on his (her) another device. Otherwise, the subscription + // will be destroyed ahead of time. + if (!peer->isMuted()) { Ui::show(Box(peer)); - }); - } else { - muteAction = callback(lang(lng_enable_notifications_from_tray), [peer] { + } else { App::main()->updateNotifySetting(peer, NotifySettingSetNotify); - }); - } + } + }); auto muteChangedHandler = Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NotificationsEnabled, [muteAction, peer](const Notify::PeerUpdate &update) { if (update.peer != peer) return; muteAction->setText(lang(peer->isMuted() ? lng_enable_notifications_from_tray : lng_disable_notifications_from_tray));