From 59977da2b458133546ebb7c61eab4ee3540ee185 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 1 Sep 2021 01:22:31 +0300 Subject: [PATCH] Added choosing sticker action to field autocomplete. --- .../SourceFiles/chat_helpers/field_autocomplete.cpp | 5 +++++ .../SourceFiles/chat_helpers/field_autocomplete.h | 13 +++++++------ Telegram/SourceFiles/history/history_widget.cpp | 12 ++++++++++++ .../view/controls/history_view_compose_controls.cpp | 9 +++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 0f83918ab..6f0cbfaed 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -199,6 +199,11 @@ auto FieldAutocomplete::stickerChosen() const return _inner->stickerChosen(); } +auto FieldAutocomplete::choosingProcesses() const +-> rpl::producer { + return _scroll->scrollTopChanges() | rpl::map([=] { return _type; }); +} + FieldAutocomplete::~FieldAutocomplete() = default; void FieldAutocomplete::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index 50e335596..f149b5c95 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -87,6 +87,12 @@ public: Api::SendOptions options; ChooseMethod method; }; + enum class Type { + Mentions, + Hashtags, + BotCommands, + Stickers, + }; bool chooseSelected(ChooseMethod method) const; @@ -111,6 +117,7 @@ public: rpl::producer hashtagChosen() const; rpl::producer botCommandChosen() const; rpl::producer stickerChosen() const; + rpl::producer choosingProcesses() const; public Q_SLOTS: void showAnimated(); @@ -176,12 +183,6 @@ private: ChannelData *_channel = nullptr; EmojiPtr _emoji; uint64 _stickersSeed = 0; - enum class Type { - Mentions, - Hashtags, - BotCommands, - Stickers, - }; Type _type = Type::Mentions; QString _filter; QRect _boundings; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 24e3bd4c5..7181fa6fb 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -360,6 +360,18 @@ HistoryWidget::HistoryWidget( : _keyboard->moderateKeyActivate(key); }); + _fieldAutocomplete->choosingProcesses( + ) | rpl::start_with_next([=](FieldAutocomplete::Type type) { + if (!_history) { + return; + } + if (type == FieldAutocomplete::Type::Stickers) { + session().sendProgressManager().update( + _history, + Api::SendProgressType::ChooseSticker); + } + }, lifetime()); + _fieldAutocomplete->setSendMenuType([=] { return sendMenuType(); }); if (_supportAutocomplete) { 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 2f41f1005..8c31ddb1e 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1236,6 +1236,15 @@ void ComposeControls::initAutocomplete() { }); }, _autocomplete->lifetime()); + _autocomplete->choosingProcesses( + ) | rpl::start_with_next([=](FieldAutocomplete::Type type) { + if (type == FieldAutocomplete::Type::Stickers) { + _sendActionUpdates.fire({ + .type = Api::SendProgressType::ChooseSticker, + }); + } + }, _autocomplete->lifetime()); + _autocomplete->setSendMenuType([=] { return sendMenuType(); }); //_autocomplete->setModerateKeyActivateCallback([=](int key) {