mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 08:51:12 +00:00
Use not type-erased producers in code.
This commit is contained in:
parent
cdda7f8f9a
commit
fddcdf359b
@ -136,7 +136,7 @@ public:
|
||||
void stickerSetInstalled(uint64 setId) {
|
||||
_stickerSetInstalled.fire_copy(setId);
|
||||
}
|
||||
rpl::producer<uint64> stickerSetInstalled() const {
|
||||
auto stickerSetInstalled() const {
|
||||
return _stickerSetInstalled.events();
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
return _variables.thirdSectionInfoEnabled;
|
||||
}
|
||||
void setThirdSectionInfoEnabled(bool enabled);
|
||||
rpl::producer<bool> thirdSectionInfoEnabledValue() const {
|
||||
auto thirdSectionInfoEnabledValue() const {
|
||||
return _thirdSectionInfoEnabledValue.events_starting_with(
|
||||
thirdSectionInfoEnabled());
|
||||
}
|
||||
@ -114,7 +114,7 @@ public:
|
||||
return _tabbedReplacedWithInfo;
|
||||
}
|
||||
void setTabbedReplacedWithInfo(bool enabled);
|
||||
rpl::producer<bool> tabbedReplacedWithInfoValue() const {
|
||||
auto tabbedReplacedWithInfoValue() const {
|
||||
return _tabbedReplacedWithInfoValue.events_starting_with(
|
||||
tabbedReplacedWithInfo());
|
||||
}
|
||||
|
@ -464,9 +464,9 @@ void HandleObservables();
|
||||
template <
|
||||
typename Type,
|
||||
typename = std::enable_if_t<!std::is_same_v<Type, void>>>
|
||||
inline rpl::producer<Type> ObservableViewer(
|
||||
base::Observable<Type> &observable) {
|
||||
return [&observable](const rpl::consumer<Type> &consumer) {
|
||||
inline auto ObservableViewer(base::Observable<Type> &observable) {
|
||||
return rpl::make_producer<Type>([&observable](
|
||||
const rpl::consumer<Type> &consumer) {
|
||||
auto lifetime = rpl::lifetime();
|
||||
lifetime.make_state<base::Subscription>(
|
||||
observable.add_subscription([consumer](auto &&update) {
|
||||
@ -474,19 +474,19 @@ inline rpl::producer<Type> ObservableViewer(
|
||||
std::forward<decltype(update)>(update));
|
||||
}));
|
||||
return lifetime;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
inline rpl::producer<> ObservableViewer(
|
||||
base::Observable<void> &observable) {
|
||||
return [&observable](const rpl::consumer<> &consumer) {
|
||||
inline auto ObservableViewer(base::Observable<void> &observable) {
|
||||
return rpl::make_producer<>([&observable](
|
||||
const rpl::consumer<> &consumer) {
|
||||
auto lifetime = rpl::lifetime();
|
||||
lifetime.make_state<base::Subscription>(
|
||||
observable.add_subscription([consumer]() {
|
||||
consumer.put_next({});
|
||||
}));
|
||||
return lifetime;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
@ -402,7 +402,7 @@ public:
|
||||
update();
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const {
|
||||
auto scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
QString shortName() const;
|
||||
|
||||
void install();
|
||||
rpl::producer<uint64> setInstalled() const {
|
||||
auto setInstalled() const {
|
||||
return _setInstalled.events();
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
bool wheelEventFromFloatPlayer(QEvent *e);
|
||||
QRect rectForFloatPlayer() const;
|
||||
|
||||
rpl::producer<> showRequests() const {
|
||||
auto showRequests() const {
|
||||
return _showRequests.events();
|
||||
}
|
||||
|
||||
|
@ -69,13 +69,13 @@ public:
|
||||
updated(diff);
|
||||
}
|
||||
}
|
||||
Type current() const {
|
||||
auto current() const {
|
||||
return _value;
|
||||
}
|
||||
rpl::producer<Change> changes() const {
|
||||
auto changes() const {
|
||||
return _changes.events();
|
||||
}
|
||||
rpl::producer<Change> value() const {
|
||||
auto value() const {
|
||||
return _changes.events_starting_with({
|
||||
Type::from_raw(kEssential),
|
||||
_value });
|
||||
|
@ -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<Flags::Change> 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<FullFlags::Change> 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<Flags::Change> 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<Flags::Change> 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<FullFlags::Change> fullFlagsValue() const {
|
||||
auto fullFlagsValue() const {
|
||||
return _fullFlags.value();
|
||||
}
|
||||
|
||||
@ -923,20 +923,20 @@ public:
|
||||
using Restrictions = ChannelRestrictions;
|
||||
using AdminRightFlags = Data::Flags<AdminRights>;
|
||||
using RestrictionFlags = Data::Flags<Restrictions>;
|
||||
AdminRights adminRights() const {
|
||||
auto adminRights() const {
|
||||
return _adminRights.current();
|
||||
}
|
||||
rpl::producer<AdminRightFlags::Change> 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<RestrictionFlags::Change> restrictionsValue() const {
|
||||
auto restrictionsValue() const {
|
||||
return _restrictions.value();
|
||||
}
|
||||
bool restricted(Restriction right) const {
|
||||
|
@ -27,9 +27,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
|
||||
namespace Data {
|
||||
|
||||
template <typename ChangeType>
|
||||
template <typename ChangeType, typename Error, typename Generator>
|
||||
inline auto FlagsValueWithMask(
|
||||
rpl::producer<ChangeType> &&value,
|
||||
rpl::producer<ChangeType, Error, Generator> &&value,
|
||||
typename ChangeType::Type mask) {
|
||||
return std::move(value)
|
||||
| rpl::filter([mask](const ChangeType &change) {
|
||||
@ -40,9 +40,9 @@ inline auto FlagsValueWithMask(
|
||||
});
|
||||
}
|
||||
|
||||
template <typename ChangeType>
|
||||
template <typename ChangeType, typename Error, typename Generator>
|
||||
inline auto SingleFlagValue(
|
||||
rpl::producer<ChangeType> &&value,
|
||||
rpl::producer<ChangeType, Error, Generator> &&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<bool> CanWriteValue(ChannelData *channel) {
|
||||
inline auto CanWriteValue(ChannelData *channel) {
|
||||
auto flagsMask = 0
|
||||
| MTPDchannel::Flag::f_left
|
||||
| MTPDchannel_ClientFlag::f_forbidden
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void checkInsufficientMedia();
|
||||
using AroundData = std::pair<MsgId, ApiWrap::SliceType>;
|
||||
rpl::producer<AroundData> insufficientMediaAround() const {
|
||||
auto insufficientMediaAround() const {
|
||||
return _insufficientMediaAround.events();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
bool applyUpdate(const Storage::UserPhotosResult &update);
|
||||
bool applyUpdate(const Storage::UserPhotosSliceUpdate &update);
|
||||
void checkInsufficientPhotos();
|
||||
rpl::producer<PhotoId> insufficientPhotosAround() const {
|
||||
auto insufficientPhotosAround() const {
|
||||
return _insufficientPhotosAround.events();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,10 @@ Button *Button::toggleOn(rpl::producer<bool> &&toggled) {
|
||||
}
|
||||
|
||||
rpl::producer<bool> Button::toggledValue() const {
|
||||
return _toggle ? _toggle->checkedValue() : rpl::never<bool>();
|
||||
if (_toggle) {
|
||||
return _toggle->checkedValue();
|
||||
}
|
||||
return rpl::never<bool>();
|
||||
}
|
||||
|
||||
void Button::paintEvent(QPaintEvent *e) {
|
||||
|
@ -223,7 +223,7 @@ void InnerWidget::setupUserButtons(
|
||||
using namespace rpl::mappers;
|
||||
auto tracker = MultiLineTracker();
|
||||
auto topSkip = wrap->add(createSlideSkipWidget(wrap));
|
||||
auto addButton = [&](rpl::producer<QString> &&text) {
|
||||
auto addButton = [&](auto &&text) {
|
||||
auto result = wrap->add(object_ptr<Ui::SlideWrap<Button>>(
|
||||
wrap,
|
||||
object_ptr<Button>(
|
||||
@ -269,7 +269,7 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
||||
auto content = object_ptr<Ui::VerticalLayout>(parent);
|
||||
auto tracker = MultiLineTracker();
|
||||
auto addButton = [&](
|
||||
rpl::producer<int> &&count,
|
||||
auto &&count,
|
||||
auto textFromCount) {
|
||||
auto forked = std::move(count)
|
||||
| start_spawning(content->lifetime());
|
||||
@ -375,8 +375,8 @@ object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
|
||||
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
||||
result->add(createSkipWidget(result));
|
||||
auto addButton = [&](
|
||||
rpl::producer<QString> &&text,
|
||||
rpl::producer<bool> &&toggleOn,
|
||||
auto &&text,
|
||||
auto &&toggleOn,
|
||||
auto &&callback,
|
||||
const style::InfoProfileButton &st
|
||||
= st::infoSharedMediaButton) {
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<> clicks() const {
|
||||
auto clicks() const {
|
||||
return _clicks.events();
|
||||
}
|
||||
|
||||
|
@ -39,36 +39,36 @@ class RpWidgetWrap : public RpWidgetParent<Widget> {
|
||||
public:
|
||||
using Parent::Parent;
|
||||
|
||||
rpl::producer<QRect> geometryValue() const {
|
||||
auto geometryValue() const {
|
||||
auto &stream = eventStreams().geometry;
|
||||
return stream.events_starting_with_copy(this->geometry());
|
||||
}
|
||||
rpl::producer<QSize> sizeValue() const {
|
||||
auto sizeValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.size(); })
|
||||
| rpl::distinct_until_changed();
|
||||
}
|
||||
rpl::producer<int> heightValue() const {
|
||||
auto heightValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.height(); })
|
||||
| rpl::distinct_until_changed();
|
||||
}
|
||||
rpl::producer<int> widthValue() const {
|
||||
auto widthValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.width(); })
|
||||
| rpl::distinct_until_changed();
|
||||
}
|
||||
rpl::producer<QPoint> positionValue() const {
|
||||
auto positionValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.topLeft(); })
|
||||
| rpl::distinct_until_changed();
|
||||
}
|
||||
rpl::producer<int> leftValue() const {
|
||||
auto leftValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.left(); })
|
||||
| rpl::distinct_until_changed();
|
||||
}
|
||||
rpl::producer<int> topValue() const {
|
||||
auto topValue() const {
|
||||
return geometryValue()
|
||||
| rpl::map([](QRect &&value) { return value.top(); })
|
||||
| rpl::distinct_until_changed();
|
||||
@ -77,15 +77,16 @@ public:
|
||||
return heightValue();
|
||||
}
|
||||
|
||||
rpl::producer<QRect> paintRequest() const {
|
||||
auto paintRequest() const {
|
||||
return eventStreams().paint.events();
|
||||
}
|
||||
|
||||
rpl::producer<> alive() const {
|
||||
auto alive() const {
|
||||
return eventStreams().alive.events();
|
||||
}
|
||||
|
||||
void showOn(rpl::producer<bool> &&shown) {
|
||||
template <typename Error, typename Generator>
|
||||
void showOn(rpl::producer<bool, Error, Generator> &&shown) {
|
||||
std::move(shown)
|
||||
| rpl::start_with_next([this](bool visible) {
|
||||
this->setVisible(visible);
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
}
|
||||
float64 currentAnimationValue(TimeMs ms);
|
||||
|
||||
rpl::producer<bool> checkedValue() const {
|
||||
auto checkedValue() const {
|
||||
return _checks.events_starting_with(checked());
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
void setActiveSectionFast(int index);
|
||||
void finishAnimations();
|
||||
|
||||
rpl::producer<int> sectionActivated() const {
|
||||
auto sectionActivated() const {
|
||||
return _sectionActivated.events();
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
bool viewportEvent(QEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
rpl::producer<int> scrollTopValue() const {
|
||||
auto scrollTopValue() const {
|
||||
return _scrollTopUpdated.events_starting_with(scrollTop());
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
return !_shown;
|
||||
}
|
||||
|
||||
rpl::producer<bool> shownValue() const {
|
||||
auto shownValue() const {
|
||||
return _shownUpdated.events_starting_with_copy(_shown);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user