mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Fix possible crash in ads preloading.
This commit is contained in:
parent
03e4592082
commit
b4f173cdb3
2 changed files with 12 additions and 13 deletions
Telegram/SourceFiles/history
|
@ -321,30 +321,26 @@ HistoryWidget::HistoryWidget(
|
|||
_list->onParentGeometryChanged();
|
||||
}), lifetime());
|
||||
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
_scroll->addContentRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (_history && _history->loadedAtBottom()) {
|
||||
using Result = Data::SponsoredMessages::AppendResult;
|
||||
const auto tryToAppend = [=] {
|
||||
const auto r = session().sponsoredMessages().append(_history);
|
||||
if (r == Result::Appended) {
|
||||
const auto sponsored = &session().sponsoredMessages();
|
||||
const auto result = sponsored->append(_history);
|
||||
if (result == Result::Appended) {
|
||||
_scroll->contentAdded();
|
||||
}
|
||||
return r;
|
||||
return result;
|
||||
};
|
||||
if (tryToAppend() == Result::MediaLoading) {
|
||||
const auto sharedLifetime = std::make_shared<rpl::lifetime>();
|
||||
if (tryToAppend() == Result::MediaLoading
|
||||
&& !_historySponsoredPreloading) {
|
||||
session().downloaderTaskFinished(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (const auto strong = weak.data()) {
|
||||
if (tryToAppend() != Result::MediaLoading) {
|
||||
sharedLifetime->destroy();
|
||||
}
|
||||
} else {
|
||||
sharedLifetime->destroy();
|
||||
if (tryToAppend() != Result::MediaLoading) {
|
||||
_historySponsoredPreloading.destroy();
|
||||
}
|
||||
}, *sharedLifetime);
|
||||
}, _historySponsoredPreloading);
|
||||
}
|
||||
}
|
||||
}, lifetime());
|
||||
|
@ -2625,6 +2621,7 @@ void HistoryWidget::setHistory(History *history) {
|
|||
unregisterDraftSources();
|
||||
clearAllLoadRequests();
|
||||
clearSupportPreloadRequest();
|
||||
_historySponsoredPreloading.destroy();
|
||||
const auto wasHistory = base::take(_history);
|
||||
const auto wasMigrated = base::take(_migrated);
|
||||
unloadHeavyViewParts(wasHistory);
|
||||
|
|
|
@ -744,6 +744,8 @@ private:
|
|||
QPointer<HistoryInner> _list;
|
||||
History *_migrated = nullptr;
|
||||
History *_history = nullptr;
|
||||
rpl::lifetime _historySponsoredPreloading;
|
||||
|
||||
// Initial updateHistoryGeometry() was called.
|
||||
bool _historyInited = false;
|
||||
// If updateListSize() was called without updateHistoryGeometry().
|
||||
|
|
Loading…
Add table
Reference in a new issue