From ad52c0cb16265c91d06d93e329da3b0165a1dd57 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 9 Nov 2021 20:42:35 +0400 Subject: [PATCH] Single-click change Send As. --- .../SourceFiles/ui/chat/choose_send_as.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/ui/chat/choose_send_as.cpp b/Telegram/SourceFiles/ui/chat/choose_send_as.cpp index 16ff42119..62b7af1f3 100644 --- a/Telegram/SourceFiles/ui/chat/choose_send_as.cpp +++ b/Telegram/SourceFiles/ui/chat/choose_send_as.cpp @@ -34,13 +34,14 @@ public: void prepare() override; void rowClicked(not_null row) override; - [[nodiscard]] not_null selected() const; + [[nodiscard]] rpl::producer> clicked() const; private: std::unique_ptr createRow(not_null peer); std::vector> _list; not_null _selected; + rpl::event_stream> _clicked; }; @@ -92,15 +93,11 @@ void ListController::rowClicked(not_null row) { if (peer == _selected) { return; } - const auto previous = delegate()->peerListFindRow(_selected->id.value); - Assert(previous != nullptr); - delegate()->peerListSetRowChecked(previous, false); - delegate()->peerListSetRowChecked(row, true); - _selected = peer; + _clicked.fire_copy(peer); } -not_null ListController::selected() const { - return _selected; +rpl::producer> ListController::clicked() const { + return _clicked.events(); } } // namespace @@ -131,19 +128,22 @@ void ChooseSendAsBox( controller->setStyleOverrides( &st::peerListJoinAsList, nullptr); + + controller->clicked( + ) | rpl::start_with_next([=](not_null peer) { + const auto weak = MakeWeak(box); + done(peer); + if (weak) { + box->closeBox(); + } + }, box->lifetime()); + const auto content = box->addRow( object_ptr(box, controller), style::margins()); delegate->setContent(content); controller->setDelegate(delegate); - box->addButton(tr::lng_settings_save(), [=] { - const auto weak = MakeWeak(box); - done(controller->selected()); - if (weak) { - box->closeBox(); - } - }); - box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + box->addButton(tr::lng_box_done(), [=] { box->closeBox(); }); } void SetupSendAsButton(