mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to get sponsored details from constructor of HistoryItem.
This commit is contained in:
parent
a8de145e01
commit
17f89ba1f9
2 changed files with 15 additions and 5 deletions
|
@ -78,9 +78,13 @@ bool SponsoredMessages::append(not_null<History*> history) {
|
||||||
list.showedAll = true;
|
list.showedAll = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// SponsoredMessages::Details can be requested within
|
||||||
|
// the constructor of HistoryItem, so itemFullId is used as a key.
|
||||||
|
entryIt->itemFullId = FullMsgId(
|
||||||
|
history->peer->id,
|
||||||
|
_session->data().nextLocalMessageId());
|
||||||
entryIt->item.reset(history->addNewLocalMessage(
|
entryIt->item.reset(history->addNewLocalMessage(
|
||||||
_session->data().nextLocalMessageId(),
|
entryIt->itemFullId.msg,
|
||||||
entryIt->sponsored.from,
|
entryIt->sponsored.from,
|
||||||
entryIt->sponsored.textWithEntities));
|
entryIt->sponsored.textWithEntities));
|
||||||
|
|
||||||
|
@ -159,8 +163,13 @@ void SponsoredMessages::inject(
|
||||||
? viewHeight
|
? viewHeight
|
||||||
: (*lastViewIt)->resizeGetHeight(fallbackWidth);
|
: (*lastViewIt)->resizeGetHeight(fallbackWidth);
|
||||||
}
|
}
|
||||||
|
// SponsoredMessages::Details can be requested within
|
||||||
|
// the constructor of HistoryItem, so itemFullId is used as a key.
|
||||||
|
entryIt->itemFullId = FullMsgId(
|
||||||
|
history->peer->id,
|
||||||
|
_session->data().nextLocalMessageId());
|
||||||
const auto makedMessage = history->makeMessage(
|
const auto makedMessage = history->makeMessage(
|
||||||
_session->data().nextLocalMessageId(),
|
entryIt->itemFullId.msg,
|
||||||
entryIt->sponsored.from,
|
entryIt->sponsored.from,
|
||||||
entryIt->sponsored.textWithEntities,
|
entryIt->sponsored.textWithEntities,
|
||||||
(*lastViewIt)->data());
|
(*lastViewIt)->data());
|
||||||
|
@ -357,7 +366,7 @@ void SponsoredMessages::append(
|
||||||
.sponsorInfo = std::move(sponsorInfo),
|
.sponsorInfo = std::move(sponsorInfo),
|
||||||
.additionalInfo = std::move(additionalInfo),
|
.additionalInfo = std::move(additionalInfo),
|
||||||
};
|
};
|
||||||
list.entries.push_back({ nullptr, std::move(sharedMessage) });
|
list.entries.push_back({ nullptr, {}, std::move(sharedMessage) });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SponsoredMessages::clearItems(not_null<History*> history) {
|
void SponsoredMessages::clearItems(not_null<History*> history) {
|
||||||
|
@ -385,7 +394,7 @@ const SponsoredMessages::Entry *SponsoredMessages::find(
|
||||||
}
|
}
|
||||||
auto &list = it->second;
|
auto &list = it->second;
|
||||||
const auto entryIt = ranges::find_if(list.entries, [&](const Entry &e) {
|
const auto entryIt = ranges::find_if(list.entries, [&](const Entry &e) {
|
||||||
return e.item && e.item->fullId() == fullId;
|
return e.itemFullId == fullId;
|
||||||
});
|
});
|
||||||
if (entryIt == end(list.entries)) {
|
if (entryIt == end(list.entries)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -89,6 +89,7 @@ private:
|
||||||
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
||||||
struct Entry {
|
struct Entry {
|
||||||
OwnedItem item;
|
OwnedItem item;
|
||||||
|
FullMsgId itemFullId;
|
||||||
SponsoredMessage sponsored;
|
SponsoredMessage sponsored;
|
||||||
};
|
};
|
||||||
struct List {
|
struct List {
|
||||||
|
|
Loading…
Add table
Reference in a new issue