mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
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 {
|
void Data::prepare(const Options &options, Fn<void(Prepared)> done) const {
|
||||||
crl::async([source = *_source, options, done = std::move(done)] {
|
crl::async([source = *_source, options, done = std::move(done)] {
|
||||||
done(Prepare(source, options));
|
done(Prepare(source, options));
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
[[nodiscard]] QString id() const;
|
[[nodiscard]] QString id() const;
|
||||||
[[nodiscard]] bool partial() const;
|
[[nodiscard]] bool partial() const;
|
||||||
|
|
||||||
|
void updateCachedViews(int cachedViews);
|
||||||
|
|
||||||
void prepare(const Options &options, Fn<void(Prepared)> done) const;
|
void prepare(const Options &options, Fn<void(Prepared)> done) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1001,14 +1001,20 @@ WebPageData *Instance::processReceivedPage(
|
||||||
owner->processChats(data.vchats());
|
owner->processChats(data.vchats());
|
||||||
auto &requested = _fullRequested[session][url];
|
auto &requested = _fullRequested[session][url];
|
||||||
const auto &mtp = data.vwebpage();
|
const auto &mtp = data.vwebpage();
|
||||||
return mtp.match([&](const MTPDwebPageNotModified &data) {
|
mtp.match([&](const MTPDwebPageNotModified &data) {
|
||||||
return requested.page;
|
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) {
|
}, [&](const MTPDwebPage &data) {
|
||||||
requested.hash = data.vhash().v;
|
requested.hash = data.vhash().v;
|
||||||
return owner->processWebpage(data).get();
|
requested.page = owner->processWebpage(data).get();
|
||||||
}, [&](const auto &) {
|
}, [&](const auto &) {
|
||||||
return owner->processWebpage(mtp).get();
|
requested.page = owner->processWebpage(mtp).get();
|
||||||
});
|
});
|
||||||
|
return requested.page;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::processOpenChannel(const QString &context) {
|
void Instance::processOpenChannel(const QString &context) {
|
||||||
|
|
|
@ -229,7 +229,9 @@ Parser::Parser(const Source &source, const Options &options)
|
||||||
_result.name = source.name;
|
_result.name = source.name;
|
||||||
_result.rtl = source.page.data().is_rtl();
|
_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());
|
const auto content = list(source.page.data().vblocks());
|
||||||
_result.content = wrap(content, views);
|
_result.content = wrap(content, views);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct Source {
|
||||||
std::optional<MTPPhoto> webpagePhoto;
|
std::optional<MTPPhoto> webpagePhoto;
|
||||||
std::optional<MTPDocument> webpageDocument;
|
std::optional<MTPDocument> webpageDocument;
|
||||||
QString name;
|
QString name;
|
||||||
|
int updatedCachedViews = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] Prepared Prepare(const Source &source, const Options &options);
|
[[nodiscard]] Prepared Prepare(const Source &source, const Options &options);
|
||||||
|
|
Loading…
Add table
Reference in a new issue