From f49c7ba7eef8c2d2e04546484e2bfd9501540ee4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 Jun 2019 16:09:57 +0200 Subject: [PATCH] Allow hiding contact status bar. --- .../view/history_view_contact_status.cpp | 82 ++++++++++++++++--- .../view/history_view_contact_status.h | 14 +++- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index cc433c4b57..0477b54001 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -46,6 +46,10 @@ bool BarCurrentlyHidden(not_null peer) { return false; } +auto MapToEmpty() { + return rpl::map([] { return rpl::empty_value(); }); +} + } // namespace // //void HistoryWidget::onReportSpamClicked() { @@ -118,14 +122,14 @@ bool BarCurrentlyHidden(not_null peer) { ContactStatus::Bar::Bar(QWidget *parent, const QString &name) : RpWidget(parent) , _name(name) -, _block( - this, - lang(lng_new_contact_block).toUpper(), - st::historyContactStatusBlock) , _add( this, lang(lng_new_contact_add).toUpper(), st::historyContactStatusButton) +, _block( + this, + lang(lng_new_contact_block).toUpper(), + st::historyContactStatusBlock) , _share( this, lang(lng_new_contact_share).toUpper(), @@ -148,6 +152,25 @@ void ContactStatus::Bar::showState(State state) { : lang(lng_new_contact_add).toUpper()); updateButtonsGeometry(); } +rpl::producer<> ContactStatus::Bar::addClicks() const { + return _add->clicks() | MapToEmpty(); +} + +rpl::producer<> ContactStatus::Bar::blockClicks() const { + return _block->clicks() | MapToEmpty(); +} + +rpl::producer<> ContactStatus::Bar::shareClicks() const { + return _share->clicks() | MapToEmpty(); +} + +rpl::producer<> ContactStatus::Bar::reportClicks() const { + return _report->clicks() | MapToEmpty(); +} + +rpl::producer<> ContactStatus::Bar::closeClicks() const { + return _close->clicks() | MapToEmpty(); +} void ContactStatus::Bar::resizeEvent(QResizeEvent *e) { _close->moveToRight(0, 0); @@ -224,6 +247,7 @@ ContactStatus::ContactStatus( , _shadow(parent) { setupWidgets(parent); setupState(peer); + setupHandlers(peer); } void ContactStatus::setupWidgets(not_null parent) { @@ -274,8 +298,11 @@ auto ContactStatus::PeerState(not_null peer) } else { return State::None; } + } else if (settings.value & Setting::f_block_contact) { + return State::AddOrBlock; + } else { + return State::Add; } - return State::AddOrBlock; }); } @@ -291,6 +318,7 @@ void ContactStatus::setupState(not_null peer) { if (!BarCurrentlyHidden(peer)) { peer->session().api().requestPeerSettings(peer); } + PeerState( peer ) | rpl::start_with_next([=](State state) { @@ -304,14 +332,46 @@ void ContactStatus::setupState(not_null peer) { }, _bar.lifetime()); } +void ContactStatus::setupHandlers(not_null peer) { + setupAddHandler(peer); + setupBlockHandler(peer); + setupShareHandler(peer); + setupReportHandler(peer); + setupCloseHandler(peer); +} + +void ContactStatus::setupAddHandler(not_null peer) { +} + +void ContactStatus::setupBlockHandler(not_null peer) { +} + +void ContactStatus::setupShareHandler(not_null peer) { +} + +void ContactStatus::setupReportHandler(not_null peer) { +} + +void ContactStatus::setupCloseHandler(not_null peer) { + const auto request = _bar.lifetime().make_state(0); + _bar.entity()->closeClicks( + ) | rpl::filter([=] { + return !(*request); + }) | rpl::start_with_next([=] { + peer->setSettings(0); + *request = peer->session().api().request( + MTPmessages_HidePeerSettingsBar(peer->input) + ).send(); + }, _bar.lifetime()); +} + void ContactStatus::show() { - if (_shown) { - return; - } - _shown = true; const auto visible = (_state != State::None); - if (visible) { - _bar.entity()->showState(_state); + if (!_shown) { + _shown = true; + if (visible) { + _bar.entity()->showState(_state); + } } _bar.toggle(visible, anim::type::instant); } diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h index 742e36446a..196e34e88c 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.h +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -48,6 +48,12 @@ private: void showState(State state); + rpl::producer<> addClicks() const; + rpl::producer<> blockClicks() const; + rpl::producer<> shareClicks() const; + rpl::producer<> reportClicks() const; + rpl::producer<> closeClicks() const; + protected: void resizeEvent(QResizeEvent *e) override; @@ -55,8 +61,8 @@ private: void updateButtonsGeometry(); QString _name; - object_ptr _block; object_ptr _add; + object_ptr _block; object_ptr _share; object_ptr _report; object_ptr _close; @@ -65,6 +71,12 @@ private: void setupWidgets(not_null parent); void setupState(not_null peer); + void setupHandlers(not_null peer); + void setupAddHandler(not_null peer); + void setupBlockHandler(not_null peer); + void setupShareHandler(not_null peer); + void setupReportHandler(not_null peer); + void setupCloseHandler(not_null peer); static rpl::producer PeerState(not_null peer);