From 8c17e3e578ffc2b25ff55e60ee655d121cefc5e0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Aug 2021 18:05:07 +0300 Subject: [PATCH] Added sending action when choosing sticker. --- Telegram/SourceFiles/api/api_send_progress.cpp | 1 + .../chat_helpers/stickers_list_widget.cpp | 11 +++++++++++ .../chat_helpers/stickers_list_widget.h | 2 ++ .../chat_helpers/tabbed_selector.cpp | 7 +++++++ .../SourceFiles/chat_helpers/tabbed_selector.h | 5 +++++ Telegram/SourceFiles/history/history_widget.cpp | 13 +++++++++++++ .../view/controls/compose_controls_common.h | 1 + .../controls/history_view_compose_controls.cpp | 8 ++++++++ .../view/history_view_replies_section.cpp | 17 ++++++++++++----- 9 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/api/api_send_progress.cpp b/Telegram/SourceFiles/api/api_send_progress.cpp index 563262a5b..7913babfd 100644 --- a/Telegram/SourceFiles/api/api_send_progress.cpp +++ b/Telegram/SourceFiles/api/api_send_progress.cpp @@ -129,6 +129,7 @@ void SendProgressManager::send(const Key &key, int progress) { case Type::ChooseContact: return MTP_sendMessageChooseContactAction(); case Type::PlayGame: return MTP_sendMessageGamePlayAction(); case Type::Speaking: return MTP_speakingInGroupCallAction(); + case Type::ChooseSticker: return MTP_sendMessageChooseStickerAction(); default: return MTP_sendMessageTypingAction(); } }(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index f2dcd6f42..87ed1aa95 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -970,6 +970,11 @@ StickersListWidget::StickersListWidget( } refreshRecent(); }, lifetime()); + + positionValue( + ) | rpl::skip(1) | rpl::map_to( + TabbedSelector::Action::Update + ) | rpl::start_to_stream(_choosingUpdated, lifetime()); } Main::Session &StickersListWidget::session() const { @@ -988,6 +993,11 @@ rpl::producer<> StickersListWidget::checkForHide() const { return _checkForHide.events(); } +auto StickersListWidget::choosingUpdated() const +-> rpl::producer { + return _choosingUpdated.events(); +} + object_ptr StickersListWidget::createFooter() { Expects(_footer == nullptr); @@ -2361,6 +2371,7 @@ TabbedSelector::InnerFooter *StickersListWidget::getFooter() const { } void StickersListWidget::processHideFinished() { + _choosingUpdated.fire(TabbedSelector::Action::Cancel); clearSelection(); clearHeavyData(); if (_footer) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 49a24b440..225f569ae 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -55,6 +55,7 @@ public: rpl::producer chosen() const; rpl::producer<> scrollUpdated() const; rpl::producer<> checkForHide() const; + rpl::producer choosingUpdated() const; void refreshRecent() override; void preloadImages() override; @@ -392,6 +393,7 @@ private: rpl::event_stream _chosen; rpl::event_stream<> _scrollUpdated; rpl::event_stream<> _checkForHide; + rpl::event_stream _choosingUpdated; }; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index f5ebc830d..47bfaf5f7 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -479,6 +479,13 @@ auto TabbedSelector::inlineResultChosen() const return hasGifsTab() ? gifs()->inlineResultChosen() : nullptr; } +auto TabbedSelector::choosingStickerUpdated() const +-> rpl::producer{ + return hasStickersTab() + ? stickers()->choosingUpdated() + : rpl::never(); +} + rpl::producer<> TabbedSelector::cancelled() const { return hasGifsTab() ? gifs()->cancelRequests() : nullptr; } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 74bbcb4d2..256031dd5 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -67,6 +67,10 @@ public: EmojiOnly, MediaEditor, }; + enum class Action { + Update, + Cancel, + }; TabbedSelector( QWidget *parent, @@ -85,6 +89,7 @@ public: rpl::producer<> checkForHide() const; rpl::producer<> slideFinished() const; rpl::producer<> contextMenuRequested() const; + rpl::producer choosingStickerUpdated() const; void setRoundRadius(int radius); void refreshStickers(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cfe43ea9c..5d02c5ed7 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -904,6 +904,19 @@ void HistoryWidget::initTabbedSelector() { ) | filter | rpl::start_with_next([=] { selector->showMenuWithType(sendMenuType()); }, lifetime()); + + selector->choosingStickerUpdated( + ) | rpl::start_with_next([=](const Selector::Action &data) { + if (!_history) { + return; + } + const auto type = Api::SendProgressType::ChooseSticker; + if (data != Selector::Action::Cancel) { + session().sendProgressManager().update(_history, type); + } else { + session().sendProgressManager().cancel(_history, type); + } + }, lifetime()); } void HistoryWidget::supportInitAutocomplete() { diff --git a/Telegram/SourceFiles/history/view/controls/compose_controls_common.h b/Telegram/SourceFiles/history/view/controls/compose_controls_common.h index 25a9a2744..971739734 100644 --- a/Telegram/SourceFiles/history/view/controls/compose_controls_common.h +++ b/Telegram/SourceFiles/history/view/controls/compose_controls_common.h @@ -30,6 +30,7 @@ struct VoiceToSend { struct SendActionUpdate { Api::SendProgressType type = Api::SendProgressType(); int progress = 0; + bool cancel = false; }; struct SetHistoryArgs { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 3acf9d9f7..2f41f1005 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1560,6 +1560,14 @@ void ComposeControls::initTabbedSelector() { ) | rpl::start_with_next([=] { selector->showMenuWithType(sendMenuType()); }, wrap->lifetime()); + + selector->choosingStickerUpdated( + ) | rpl::start_with_next([=](ChatHelpers::TabbedSelector::Action action) { + _sendActionUpdates.fire({ + .type = Api::SendProgressType::ChooseSticker, + .cancel = (action == ChatHelpers::TabbedSelector::Action::Cancel), + }); + }, wrap->lifetime()); } void ComposeControls::initSendButton() { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index d12d4d7b2..679b46097 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -240,11 +240,18 @@ RepliesWidget::RepliesWidget( _composeControls->sendActionUpdates( ) | rpl::start_with_next([=](ComposeControls::SendActionUpdate &&data) { - session().sendProgressManager().update( - _history, - _rootId, - data.type, - data.progress); + if (!data.cancel) { + session().sendProgressManager().update( + _history, + _rootId, + data.type, + data.progress); + } else { + session().sendProgressManager().cancel( + _history, + _rootId, + data.type); + } }, lifetime()); using MessageUpdateFlag = Data::MessageUpdate::Flag;