mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed display at least one injected sponsored message.
This commit is contained in:
parent
8060691f3d
commit
aa1f8cfb8f
1 changed files with 24 additions and 12 deletions
|
@ -156,10 +156,11 @@ void SponsoredMessages::inject(
|
||||||
if (blockIt == end(history->blocks)) {
|
if (blockIt == end(history->blocks)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto messages = [&]() -> const std::vector<ViewPtr> & {
|
const auto messages = [&]() -> const std::vector<ViewPtr>& {
|
||||||
return (*blockIt)->messages;
|
return (*blockIt)->messages;
|
||||||
};
|
};
|
||||||
auto lastViewIt = ranges::find(messages(), lastView, &ViewPtr::get);
|
auto lastViewIt = ranges::find(messages(), lastView, &ViewPtr::get);
|
||||||
|
auto appendAtLeastToEnd = false;
|
||||||
while ((summaryBetween < list.postsBetween)
|
while ((summaryBetween < list.postsBetween)
|
||||||
|| (summaryHeight < betweenHeight)) {
|
|| (summaryHeight < betweenHeight)) {
|
||||||
lastViewIt++;
|
lastViewIt++;
|
||||||
|
@ -168,6 +169,10 @@ void SponsoredMessages::inject(
|
||||||
if (blockIt != end(history->blocks)) {
|
if (blockIt != end(history->blocks)) {
|
||||||
lastViewIt = begin(messages());
|
lastViewIt = begin(messages());
|
||||||
} else {
|
} else {
|
||||||
|
if (!list.injectedCount) {
|
||||||
|
appendAtLeastToEnd = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,17 +187,24 @@ void SponsoredMessages::inject(
|
||||||
entryIt->itemFullId = FullMsgId(
|
entryIt->itemFullId = FullMsgId(
|
||||||
history->peer->id,
|
history->peer->id,
|
||||||
_session->data().nextLocalMessageId());
|
_session->data().nextLocalMessageId());
|
||||||
const auto makedMessage = history->makeMessage(
|
if (appendAtLeastToEnd) {
|
||||||
entryIt->itemFullId.msg,
|
entryIt->item.reset(history->addSponsoredMessage(
|
||||||
entryIt->sponsored.from,
|
entryIt->itemFullId.msg,
|
||||||
entryIt->sponsored.textWithEntities,
|
entryIt->sponsored.from,
|
||||||
(*lastViewIt)->data());
|
entryIt->sponsored.textWithEntities));
|
||||||
entryIt->item.reset(makedMessage.get());
|
} else {
|
||||||
history->addNewInTheMiddle(
|
const auto makedMessage = history->makeMessage(
|
||||||
makedMessage.get(),
|
entryIt->itemFullId.msg,
|
||||||
std::distance(begin(history->blocks), blockIt),
|
entryIt->sponsored.from,
|
||||||
std::distance(begin(messages()), lastViewIt) + 1);
|
entryIt->sponsored.textWithEntities,
|
||||||
messages().back().get()->setPendingResize();
|
(*lastViewIt)->data());
|
||||||
|
entryIt->item.reset(makedMessage.get());
|
||||||
|
history->addNewInTheMiddle(
|
||||||
|
makedMessage.get(),
|
||||||
|
std::distance(begin(history->blocks), blockIt),
|
||||||
|
std::distance(begin(messages()), lastViewIt) + 1);
|
||||||
|
messages().back().get()->setPendingResize();
|
||||||
|
}
|
||||||
list.injectedCount++;
|
list.injectedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue