From fddcdf359b9c678e271f12927cc4aa2b8da5448b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Sep 2017 15:04:19 +0300 Subject: [PATCH] Use not type-erased producers in code. --- Telegram/SourceFiles/apiwrap.h | 2 +- Telegram/SourceFiles/auth_session.h | 4 +-- Telegram/SourceFiles/base/observer.h | 16 +++++------ Telegram/SourceFiles/boxes/peer_list_box.h | 2 +- Telegram/SourceFiles/boxes/sticker_set_box.h | 2 +- .../chat_helpers/tabbed_selector.h | 2 +- Telegram/SourceFiles/data/data_flags.h | 6 ++-- Telegram/SourceFiles/data/data_peer.h | 28 +++++++++---------- Telegram/SourceFiles/data/data_peer_values.h | 10 +++---- .../history/history_shared_media.cpp | 2 +- .../history/history_user_photos.cpp | 2 +- Telegram/SourceFiles/info/info_top_bar.h | 2 +- .../info/profile/info_profile_button.cpp | 5 +++- .../profile/info_profile_inner_widget.cpp | 8 +++--- Telegram/SourceFiles/ui/abstract_button.h | 2 +- Telegram/SourceFiles/ui/rp_widget.h | 21 +++++++------- Telegram/SourceFiles/ui/widgets/checkbox.h | 2 +- .../SourceFiles/ui/widgets/discrete_sliders.h | 2 +- Telegram/SourceFiles/ui/widgets/scroll_area.h | 2 +- Telegram/SourceFiles/ui/wrap/slide_wrap.h | 2 +- 20 files changed, 63 insertions(+), 59 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 558903b68b..2cc80bf9ee 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -136,7 +136,7 @@ public: void stickerSetInstalled(uint64 setId) { _stickerSetInstalled.fire_copy(setId); } - rpl::producer stickerSetInstalled() const { + auto stickerSetInstalled() const { return _stickerSetInstalled.events(); } diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index 25ed3da89a..e6228a5362 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -106,7 +106,7 @@ public: return _variables.thirdSectionInfoEnabled; } void setThirdSectionInfoEnabled(bool enabled); - rpl::producer thirdSectionInfoEnabledValue() const { + auto thirdSectionInfoEnabledValue() const { return _thirdSectionInfoEnabledValue.events_starting_with( thirdSectionInfoEnabled()); } @@ -114,7 +114,7 @@ public: return _tabbedReplacedWithInfo; } void setTabbedReplacedWithInfo(bool enabled); - rpl::producer tabbedReplacedWithInfoValue() const { + auto tabbedReplacedWithInfoValue() const { return _tabbedReplacedWithInfoValue.events_starting_with( tabbedReplacedWithInfo()); } diff --git a/Telegram/SourceFiles/base/observer.h b/Telegram/SourceFiles/base/observer.h index e557aeeae1..79f8149b3c 100644 --- a/Telegram/SourceFiles/base/observer.h +++ b/Telegram/SourceFiles/base/observer.h @@ -464,9 +464,9 @@ void HandleObservables(); template < typename Type, typename = std::enable_if_t>> -inline rpl::producer ObservableViewer( - base::Observable &observable) { - return [&observable](const rpl::consumer &consumer) { +inline auto ObservableViewer(base::Observable &observable) { + return rpl::make_producer([&observable]( + const rpl::consumer &consumer) { auto lifetime = rpl::lifetime(); lifetime.make_state( observable.add_subscription([consumer](auto &&update) { @@ -474,19 +474,19 @@ inline rpl::producer ObservableViewer( std::forward(update)); })); return lifetime; - }; + }); } -inline rpl::producer<> ObservableViewer( - base::Observable &observable) { - return [&observable](const rpl::consumer<> &consumer) { +inline auto ObservableViewer(base::Observable &observable) { + return rpl::make_producer<>([&observable]( + const rpl::consumer<> &consumer) { auto lifetime = rpl::lifetime(); lifetime.make_state( observable.add_subscription([consumer]() { consumer.put_next({}); })); return lifetime; - }; + }); } } // namespace base diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 05df4bf743..79e4326771 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -402,7 +402,7 @@ public: update(); } - rpl::producer scrollToRequests() const { + auto scrollToRequests() const { return _scrollToRequests.events(); } diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 9e2259e153..16f3785008 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -69,7 +69,7 @@ public: QString shortName() const; void install(); - rpl::producer setInstalled() const { + auto setInstalled() const { return _setInstalled.events(); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 26a9f8f7ab..434e1aa3c4 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -87,7 +87,7 @@ public: bool wheelEventFromFloatPlayer(QEvent *e); QRect rectForFloatPlayer() const; - rpl::producer<> showRequests() const { + auto showRequests() const { return _showRequests.events(); } diff --git a/Telegram/SourceFiles/data/data_flags.h b/Telegram/SourceFiles/data/data_flags.h index 34f12fcf7e..06e030a94b 100644 --- a/Telegram/SourceFiles/data/data_flags.h +++ b/Telegram/SourceFiles/data/data_flags.h @@ -69,13 +69,13 @@ public: updated(diff); } } - Type current() const { + auto current() const { return _value; } - rpl::producer changes() const { + auto changes() const { return _changes.events(); } - rpl::producer value() const { + auto value() const { return _changes.events_starting_with({ Type::from_raw(kEssential), _value }); diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 5a78801015..1693191b37 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -395,10 +395,10 @@ public: void removeFlags(MTPDuser::Flags which) { _flags.remove(which); } - MTPDuser::Flags flags() const { + auto flags() const { return _flags.current(); } - rpl::producer flagsValue() const { + auto flagsValue() const { return _flags.value(); } @@ -411,10 +411,10 @@ public: void removeFullFlags(MTPDuserFull::Flags which) { _fullFlags.remove(which); } - MTPDuserFull::Flags fullFlags() const { + auto fullFlags() const { return _fullFlags.current(); } - rpl::producer fullFlagsValue() const { + auto fullFlagsValue() const { return _fullFlags.value(); } @@ -569,10 +569,10 @@ public: void removeFlags(MTPDchat::Flags which) { _flags.remove(which); } - MTPDchat::Flags flags() const { + auto flags() const { return _flags.current(); } - rpl::producer flagsValue() const { + auto flagsValue() const { return _flags.value(); } @@ -803,10 +803,10 @@ public: void removeFlags(MTPDchannel::Flags which) { _flags.remove(which); } - MTPDchannel::Flags flags() const { + auto flags() const { return _flags.current(); } - rpl::producer flagsValue() const { + auto flagsValue() const { return _flags.value(); } @@ -819,10 +819,10 @@ public: void removeFullFlags(MTPDchannelFull::Flags which) { _fullFlags.remove(which); } - MTPDchannelFull::Flags fullFlags() const { + auto fullFlags() const { return _fullFlags.current(); } - rpl::producer fullFlagsValue() const { + auto fullFlagsValue() const { return _fullFlags.value(); } @@ -923,20 +923,20 @@ public: using Restrictions = ChannelRestrictions; using AdminRightFlags = Data::Flags; using RestrictionFlags = Data::Flags; - AdminRights adminRights() const { + auto adminRights() const { return _adminRights.current(); } - rpl::producer adminRightsValue() const { + auto adminRightsValue() const { return _adminRights.value(); } void setAdminRights(const MTPChannelAdminRights &rights); bool hasAdminRights() const { return (adminRights() != 0); } - Restrictions restrictions() const { + auto restrictions() const { return _restrictions.current(); } - rpl::producer restrictionsValue() const { + auto restrictionsValue() const { return _restrictions.value(); } bool restricted(Restriction right) const { diff --git a/Telegram/SourceFiles/data/data_peer_values.h b/Telegram/SourceFiles/data/data_peer_values.h index 4036c57fb2..e766f34b26 100644 --- a/Telegram/SourceFiles/data/data_peer_values.h +++ b/Telegram/SourceFiles/data/data_peer_values.h @@ -27,9 +27,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Data { -template +template inline auto FlagsValueWithMask( - rpl::producer &&value, + rpl::producer &&value, typename ChangeType::Type mask) { return std::move(value) | rpl::filter([mask](const ChangeType &change) { @@ -40,9 +40,9 @@ inline auto FlagsValueWithMask( }); } -template +template inline auto SingleFlagValue( - rpl::producer &&value, + rpl::producer &&value, typename ChangeType::Enum flag) { return FlagsValueWithMask(std::move(value), flag) | rpl::map([flag](typename ChangeType::Type value) { @@ -169,7 +169,7 @@ inline auto CanWriteValue(ChatData *chat) { | rpl::map(!$1); } -inline rpl::producer CanWriteValue(ChannelData *channel) { +inline auto CanWriteValue(ChannelData *channel) { auto flagsMask = 0 | MTPDchannel::Flag::f_left | MTPDchannel_ClientFlag::f_forbidden diff --git a/Telegram/SourceFiles/history/history_shared_media.cpp b/Telegram/SourceFiles/history/history_shared_media.cpp index c5de5c303a..dfbb301c48 100644 --- a/Telegram/SourceFiles/history/history_shared_media.cpp +++ b/Telegram/SourceFiles/history/history_shared_media.cpp @@ -79,7 +79,7 @@ public: void checkInsufficientMedia(); using AroundData = std::pair; - rpl::producer insufficientMediaAround() const { + auto insufficientMediaAround() const { return _insufficientMediaAround.events(); } diff --git a/Telegram/SourceFiles/history/history_user_photos.cpp b/Telegram/SourceFiles/history/history_user_photos.cpp index b7cab88a8f..6837ceb115 100644 --- a/Telegram/SourceFiles/history/history_user_photos.cpp +++ b/Telegram/SourceFiles/history/history_user_photos.cpp @@ -34,7 +34,7 @@ public: bool applyUpdate(const Storage::UserPhotosResult &update); bool applyUpdate(const Storage::UserPhotosSliceUpdate &update); void checkInsufficientPhotos(); - rpl::producer insufficientPhotosAround() const { + auto insufficientPhotosAround() const { return _insufficientPhotosAround.events(); } diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index f6f6ccf89a..c5c6e60ef8 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -37,7 +37,7 @@ class TopBar : public Ui::RpWidget { public: TopBar(QWidget *parent, const style::InfoTopBar &st); - rpl::producer<> backRequest() const { + auto backRequest() const { return _backClicks.events(); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_button.cpp b/Telegram/SourceFiles/info/profile/info_profile_button.cpp index 6e70c0d4f9..8af671d4be 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_button.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_button.cpp @@ -64,7 +64,10 @@ Button *Button::toggleOn(rpl::producer &&toggled) { } rpl::producer Button::toggledValue() const { - return _toggle ? _toggle->checkedValue() : rpl::never(); + if (_toggle) { + return _toggle->checkedValue(); + } + return rpl::never(); } void Button::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index e7e308abf2..a3adec29f1 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -223,7 +223,7 @@ void InnerWidget::setupUserButtons( using namespace rpl::mappers; auto tracker = MultiLineTracker(); auto topSkip = wrap->add(createSlideSkipWidget(wrap)); - auto addButton = [&](rpl::producer &&text) { + auto addButton = [&](auto &&text) { auto result = wrap->add(object_ptr>( wrap, object_ptr