From 23996d14d3f4750376c7307df63c26f3fa34c55f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 3 Apr 2021 19:29:30 +0300 Subject: [PATCH] Fixed display of chat buttons on main touchbar after audio touchbar. Fixed #10361. --- .../mac/touchbar/items/mac_scrubber_item.mm | 5 +--- .../mac/touchbar/mac_touchbar_manager.mm | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm index 95f6cdea0b..ae7dc66ae9 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm @@ -540,10 +540,7 @@ void AppendEmojiPacks( self.popoverTouchBar = [[[NSTouchBar alloc] init] autorelease]; self.popoverTouchBar.delegate = self; - rpl::single( - controller->sessionController()->activeChatCurrent() - ) | rpl::then( - controller->sessionController()->activeChatChanges() + controller->sessionController()->activeChatValue( ) | rpl::map([](Dialogs::Key k) { return k.peer() && k.history() diff --git a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm index 2136d6783b..34c53a72d2 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm @@ -59,7 +59,8 @@ const auto kAudioItemIdentifier = @"touchbarAudio"; Main::Session *_session; Window::Controller *_controller; - rpl::producer _canApplyMarkdown; + bool _canApplyMarkdownLast; + rpl::event_stream _canApplyMarkdown; rpl::event_stream<> _touchBarSwitches; rpl::lifetime _lifetime; } @@ -76,7 +77,10 @@ const auto kAudioItemIdentifier = @"touchbarAudio"; self.defaultItemIdentifiers = @[]; }); _controller = controller; - _canApplyMarkdown = std::move(canApplyMarkdown); + _canApplyMarkdownLast = false; + std::move( + canApplyMarkdown + ) | rpl::start_to_stream(_canApplyMarkdown, _lifetime); auto sessionChanges = domain->activeSessionChanges( ) | rpl::map([=](Main::Session *session) { @@ -138,18 +142,16 @@ const auto kAudioItemIdentifier = @"touchbarAudio"; init:_controller touchBarSwitches:_touchBarSwitches.events()] autorelease]; rpl::combine( - rpl::single(false) | rpl::then(rpl::duplicate(_canApplyMarkdown)), - rpl::single( - false - ) | rpl::then( - _controller->sessionController()->activeChatChanges( - ) | rpl::map([](Dialogs::Key k) { - return k.peer() && k.history() && k.peer()->canWrite(); - }) - ) | rpl::distinct_until_changed() + _canApplyMarkdown.events_starting_with_copy( + _canApplyMarkdownLast), + _controller->sessionController()->activeChatValue( + ) | rpl::map([](Dialogs::Key k) { + return k.peer() && k.history() && k.peer()->canWrite(); + }) | rpl::distinct_until_changed() ) | rpl::start_with_next([=]( bool canApplyMarkdown, bool hasActiveChat) { + _canApplyMarkdownLast = canApplyMarkdown; item.groupTouchBar.defaultItemIdentifiers = @[ kPinnedPanelItemIdentifier, canApplyMarkdown