From ee4501810c3f77ced1e5d0e08dfdb9b9c5f05d01 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 23 Jun 2019 12:45:43 +0300 Subject: [PATCH] Added restriction info of posting stickers to touchbar. --- .../SourceFiles/platform/mac/mac_touchbar.mm | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index 765420f53..7b54d278f 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -173,17 +173,31 @@ inline int UnreadCount(not_null peer) { return 0; } -inline bool CanWriteToActiveChat() { +inline auto GetActiveChat() { if (const auto window = App::wnd()) { if (const auto controller = window->sessionController()) { - if (const auto chat = controller->activeChatCurrent()) { - return chat.history()->peer->canWrite(); - } + return controller->activeChatCurrent(); } } + return Dialogs::Key(); +} + +inline bool CanWriteToActiveChat() { + if (const auto history = GetActiveChat().history()) { + return history->peer->canWrite(); + } return false; } +inline std::optional RestrictionToSendStickers() { + if (const auto peer = GetActiveChat().peer()) { + return Data::RestrictionError( + peer, + ChatRestriction::f_send_stickers); + } + return std::nullopt; +} + QString TitleRecentlyUsed() { const auto &sets = Auth().data().stickerSets(); const auto it = sets.constFind(Stickers::CloudRecentSetId); @@ -692,15 +706,12 @@ void AppendEmojiPacks(std::vector &to) { if (!CanWriteToActiveChat()) { return; } - const auto chat = App::wnd()->sessionController()->activeChatCurrent(); + const auto chat = GetActiveChat(); const auto callback = [&]() -> bool { if (const auto document = _stickers[index].document) { - if (const auto error = Data::RestrictionError( - chat.peer(), - ChatRestriction::f_send_stickers)) { + if (const auto error = RestrictionToSendStickers()) { Ui::show(Box(*error)); - return true; } Auth().api().sendExistingDocument( document, @@ -731,6 +742,12 @@ void AppendEmojiPacks(std::vector &to) { - (void)updateStickers { std::vector temp; + if (const auto error = RestrictionToSendStickers()) { + temp.emplace_back(PickerScrubberItem( + tr::lng_restricted_send_stickers_all(tr::now))); + _stickers = std::move(temp); + return; + } AppendFavedStickers(temp); AppendRecentStickers(temp); auto count = 0;