From 3b7123d1598ac426adc7561f7fc4d72eb77cd850 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 1 May 2019 21:09:40 +0300 Subject: [PATCH] Added auto updating of button images when peer changed userpic. --- Telegram/SourceFiles/platform/mac/touchbar.mm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/touchbar.mm b/Telegram/SourceFiles/platform/mac/touchbar.mm index 34e453532a..3f860e2b86 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar.mm @@ -28,6 +28,7 @@ #include "data/data_session.h" #include "history/history.h" #include "ui/empty_userpic.h" +#include "observer_peer.h" namespace { //https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/ @@ -87,12 +88,24 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm); self.view = button; self.customizationLabel = [NSString stringWithFormat:@"Pinned Dialog %d", num]; + const auto updateImage = [self]() { + NSButton *button = self.view; + button.image = [self getPinImage]; + }; + + Notify::PeerUpdateViewer( + self.peer, + Notify::PeerUpdate::Flag::PhotoChanged + ) | rpl::start_with_next([=] { + self.waiting = true; + updateImage(); + }, Auth().lifetime()); + base::ObservableViewer( Auth().downloaderTaskFinished() - ) | rpl::start_with_next([self] { + ) | rpl::start_with_next([=] { if (self.waiting) { - NSButton *button = self.view; - button.image = [self getPinImage]; + updateImage(); } }, Auth().lifetime());