mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved out ui callbacks of bar from data class from sponsored messages.
This commit is contained in:
parent
30dae049ff
commit
6237675744
3 changed files with 70 additions and 42 deletions
|
@ -278,38 +278,52 @@ void SponsoredMessages::parse(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SponsoredMessages::fillTopBar(
|
FullMsgId SponsoredMessages::fillTopBar(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
not_null<Ui::RpWidget*> widget,
|
not_null<Ui::RpWidget*> widget) {
|
||||||
Fn<void()> hide) {
|
const auto it = _data.find(history);
|
||||||
|
if (it != end(_data)) {
|
||||||
|
auto &list = it->second;
|
||||||
|
if (!list.entries.empty()) {
|
||||||
|
const auto &entry = list.entries.front();
|
||||||
|
const auto fullId = entry.itemFullId;
|
||||||
|
Ui::FillSponsoredMessageBar(
|
||||||
|
widget,
|
||||||
|
_session,
|
||||||
|
fullId,
|
||||||
|
entry.sponsored.from,
|
||||||
|
entry.sponsored.textWithEntities);
|
||||||
|
return fullId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> SponsoredMessages::itemRemoved(const FullMsgId &fullId) {
|
||||||
|
if (IsServerMsgId(fullId.msg) || !fullId) {
|
||||||
|
return rpl::never<>();
|
||||||
|
}
|
||||||
|
const auto history = _session->data().history(fullId.peer);
|
||||||
const auto it = _data.find(history);
|
const auto it = _data.find(history);
|
||||||
if (it == end(_data)) {
|
if (it == end(_data)) {
|
||||||
return;
|
return rpl::never<>();
|
||||||
}
|
}
|
||||||
auto &list = it->second;
|
auto &list = it->second;
|
||||||
if (list.entries.empty()) {
|
const auto entryIt = ranges::find_if(list.entries, [&](const Entry &e) {
|
||||||
return;
|
return e.itemFullId == fullId;
|
||||||
|
});
|
||||||
|
if (entryIt == end(list.entries)) {
|
||||||
|
return rpl::never<>();
|
||||||
}
|
}
|
||||||
auto &entry = list.entries.front();
|
if (!entryIt->optionalDestructionNotifier) {
|
||||||
if (!entry.optionalDestructionNotifier) {
|
entryIt->optionalDestructionNotifier
|
||||||
entry.optionalDestructionNotifier = std::make_unique<rpl::lifetime>();
|
= std::make_unique<rpl::lifetime>();
|
||||||
|
entryIt->optionalDestructionNotifier->add([this, fullId] {
|
||||||
|
_itemRemoved.fire_copy(fullId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const auto fullId = entry.itemFullId;
|
return _itemRemoved.events(
|
||||||
entry.optionalDestructionNotifier->add(std::move(hide));
|
) | rpl::filter(rpl::mappers::_1 == fullId) | rpl::to_empty;
|
||||||
Ui::FillSponsoredMessageBar(
|
|
||||||
widget,
|
|
||||||
_session,
|
|
||||||
fullId,
|
|
||||||
entry.sponsored.from,
|
|
||||||
entry.sponsored.textWithEntities);
|
|
||||||
|
|
||||||
const auto viewLifetime = widget->lifetime().make_state<rpl::lifetime>();
|
|
||||||
widget->shownValue() | rpl::filter(
|
|
||||||
rpl::mappers::_1
|
|
||||||
) | rpl::start_with_next([=, this](bool shown) {
|
|
||||||
view(fullId);
|
|
||||||
viewLifetime->destroy();
|
|
||||||
}, *viewLifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SponsoredMessages::append(
|
void SponsoredMessages::append(
|
||||||
|
|
|
@ -104,10 +104,10 @@ public:
|
||||||
void clearItems(not_null<History*> history);
|
void clearItems(not_null<History*> history);
|
||||||
[[nodiscard]] Details lookupDetails(const FullMsgId &fullId) const;
|
[[nodiscard]] Details lookupDetails(const FullMsgId &fullId) const;
|
||||||
void clicked(const FullMsgId &fullId, bool isMedia, bool isFullscreen);
|
void clicked(const FullMsgId &fullId, bool isMedia, bool isFullscreen);
|
||||||
void fillTopBar(
|
[[nodiscard]] FullMsgId fillTopBar(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
not_null<Ui::RpWidget*> widget,
|
not_null<Ui::RpWidget*> widget);
|
||||||
Fn<void()> hide);
|
[[nodiscard]] rpl::producer<> itemRemoved(const FullMsgId &);
|
||||||
|
|
||||||
[[nodiscard]] AppendResult append(not_null<History*> history);
|
[[nodiscard]] AppendResult append(not_null<History*> history);
|
||||||
void inject(
|
void inject(
|
||||||
|
@ -167,6 +167,8 @@ private:
|
||||||
base::flat_map<not_null<History*>, Request> _requests;
|
base::flat_map<not_null<History*>, Request> _requests;
|
||||||
base::flat_map<RandomId, Request> _viewRequests;
|
base::flat_map<RandomId, Request> _viewRequests;
|
||||||
|
|
||||||
|
rpl::event_stream<FullMsgId> _itemRemoved;
|
||||||
|
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7648,21 +7648,33 @@ void HistoryWidget::createSponsoredMessageBar() {
|
||||||
object_ptr<Ui::RpWidget>(this));
|
object_ptr<Ui::RpWidget>(this));
|
||||||
|
|
||||||
_sponsoredMessageBar->entity()->resizeToWidth(_scroll->width());
|
_sponsoredMessageBar->entity()->resizeToWidth(_scroll->width());
|
||||||
auto destruction = [this] {
|
const auto maybeFullId = session().sponsoredMessages().fillTopBar(
|
||||||
if (_sponsoredMessageBar) {
|
|
||||||
_sponsoredMessageBar->toggle(false, anim::type::normal);
|
|
||||||
_sponsoredMessageBar->shownValue(
|
|
||||||
) | rpl::start_with_next([=](bool shown) {
|
|
||||||
if (!shown) {
|
|
||||||
_sponsoredMessageBar = nullptr;
|
|
||||||
}
|
|
||||||
}, _sponsoredMessageBar->lifetime());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
session().sponsoredMessages().fillTopBar(
|
|
||||||
_history,
|
_history,
|
||||||
_sponsoredMessageBar->entity(),
|
_sponsoredMessageBar->entity());
|
||||||
std::move(destruction));
|
session().sponsoredMessages().itemRemoved(
|
||||||
|
maybeFullId
|
||||||
|
) | rpl::start_with_next([this] {
|
||||||
|
_sponsoredMessageBar->shownValue() | rpl::filter(
|
||||||
|
!rpl::mappers::_1
|
||||||
|
) | rpl::start_with_next([this] {
|
||||||
|
_sponsoredMessageBar = nullptr;
|
||||||
|
}, _sponsoredMessageBar->lifetime());
|
||||||
|
_sponsoredMessageBar->toggle(false, anim::type::normal);
|
||||||
|
}, _sponsoredMessageBar->lifetime());
|
||||||
|
|
||||||
|
if (maybeFullId) {
|
||||||
|
const auto viewLifetime
|
||||||
|
= _sponsoredMessageBar->lifetime().make_state<rpl::lifetime>();
|
||||||
|
rpl::combine(
|
||||||
|
_sponsoredMessageBar->entity()->heightValue(),
|
||||||
|
_sponsoredMessageBar->heightValue()
|
||||||
|
) | rpl::filter(
|
||||||
|
rpl::mappers::_1 == rpl::mappers::_2
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
session().sponsoredMessages().view(maybeFullId);
|
||||||
|
viewLifetime->destroy();
|
||||||
|
}, *viewLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
_sponsoredMessageBarHeight = 0;
|
_sponsoredMessageBarHeight = 0;
|
||||||
_sponsoredMessageBar->heightValue(
|
_sponsoredMessageBar->heightValue(
|
||||||
|
|
Loading…
Add table
Reference in a new issue