mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-13 04:37:11 +02:00
Use cached views count from not modified page.
This commit is contained in:
parent
ad7d1fddf0
commit
3947056654
5 changed files with 22 additions and 5 deletions
|
@ -71,6 +71,12 @@ bool Data::partial() const {
|
|||
|
||||
Data::~Data() = default;
|
||||
|
||||
void Data::updateCachedViews(int cachedViews) {
|
||||
_source->updatedCachedViews = std::max(
|
||||
_source->updatedCachedViews,
|
||||
cachedViews);
|
||||
}
|
||||
|
||||
void Data::prepare(const Options &options, Fn<void(Prepared)> done) const {
|
||||
crl::async([source = *_source, options, done = std::move(done)] {
|
||||
done(Prepare(source, options));
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
[[nodiscard]] QString id() const;
|
||||
[[nodiscard]] bool partial() const;
|
||||
|
||||
void updateCachedViews(int cachedViews);
|
||||
|
||||
void prepare(const Options &options, Fn<void(Prepared)> done) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -1001,14 +1001,20 @@ WebPageData *Instance::processReceivedPage(
|
|||
owner->processChats(data.vchats());
|
||||
auto &requested = _fullRequested[session][url];
|
||||
const auto &mtp = data.vwebpage();
|
||||
return mtp.match([&](const MTPDwebPageNotModified &data) {
|
||||
return requested.page;
|
||||
mtp.match([&](const MTPDwebPageNotModified &data) {
|
||||
const auto page = requested.page;
|
||||
if (const auto views = data.vcached_page_views()) {
|
||||
if (page && page->iv) {
|
||||
page->iv->updateCachedViews(views->v);
|
||||
}
|
||||
}
|
||||
}, [&](const MTPDwebPage &data) {
|
||||
requested.hash = data.vhash().v;
|
||||
return owner->processWebpage(data).get();
|
||||
requested.page = owner->processWebpage(data).get();
|
||||
}, [&](const auto &) {
|
||||
return owner->processWebpage(mtp).get();
|
||||
requested.page = owner->processWebpage(mtp).get();
|
||||
});
|
||||
return requested.page;
|
||||
}
|
||||
|
||||
void Instance::processOpenChannel(const QString &context) {
|
||||
|
|
|
@ -229,7 +229,9 @@ Parser::Parser(const Source &source, const Options &options)
|
|||
_result.name = source.name;
|
||||
_result.rtl = source.page.data().is_rtl();
|
||||
|
||||
const auto views = source.page.data().vviews().value_or_empty();
|
||||
const auto views = std::max(
|
||||
source.page.data().vviews().value_or_empty(),
|
||||
source.updatedCachedViews);
|
||||
const auto content = list(source.page.data().vblocks());
|
||||
_result.content = wrap(content, views);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ struct Source {
|
|||
std::optional<MTPPhoto> webpagePhoto;
|
||||
std::optional<MTPDocument> webpageDocument;
|
||||
QString name;
|
||||
int updatedCachedViews = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] Prepared Prepare(const Source &source, const Options &options);
|
||||
|
|
Loading…
Add table
Reference in a new issue