From a7772b922ce6047de40076bd60f011281f9b3dec Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 Sep 2018 21:08:11 +0300 Subject: [PATCH] Improve sticker file reference refreshing. --- Telegram/SourceFiles/apiwrap.cpp | 8 +++++--- Telegram/SourceFiles/boxes/about_box.cpp | 7 +++---- Telegram/SourceFiles/data/data_document.cpp | 9 +++++++++ Telegram/SourceFiles/data/data_document.h | 1 + Telegram/SourceFiles/intro/introphone.cpp | 5 +++-- Telegram/SourceFiles/storage/localstorage.cpp | 7 ++++--- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index a95bfa20e9..9946d7dda4 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2505,9 +2505,11 @@ void ApiWrap::refreshFileReference( if (additional) { const auto i = _fileReferenceHandlers.find(origin); Assert(i != end(_fileReferenceHandlers)); - i->second.push_back([=](auto&&) { - additional(); - }); + if (i->second.size() == 1) { + i->second.push_back([=](auto&&) { + additional(); + }); + } } }; const auto fail = [&] { diff --git a/Telegram/SourceFiles/boxes/about_box.cpp b/Telegram/SourceFiles/boxes/about_box.cpp index cda2b2e4d7..b90d3c4732 100644 --- a/Telegram/SourceFiles/boxes/about_box.cpp +++ b/Telegram/SourceFiles/boxes/about_box.cpp @@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" AboutBox::AboutBox(QWidget *parent) -: _version(this, lng_about_version(lt_version, QString::fromLatin1(AppVersionStr.c_str()) + (AppBetaVersion ? " beta" : "") + (cAlphaVersion() ? qsl(" alpha %1").arg(cAlphaVersion()) : QString())), st::aboutVersionLink) +: _version(this, lng_about_version(lt_version, QString::fromLatin1(AppVersionStr.c_str()) + (cAlphaVersion() ? qsl(" alpha %1").arg(cAlphaVersion()) : (AppBetaVersion ? " beta" : ""))), st::aboutVersionLink) , _text1(this, lang(lng_about_text_1), Ui::FlatLabel::InitType::Rich, st::aboutLabel) , _text2(this, lang(lng_about_text_2), Ui::FlatLabel::InitType::Rich, st::aboutLabel) , _text3(this, st::aboutLabel) { @@ -99,11 +99,10 @@ QString telegramFaqLink() { QString currentVersionText() { auto result = QString::fromLatin1(AppVersionStr.c_str()); - if (AppBetaVersion) { - result += " beta"; - } if (cAlphaVersion()) { result += qsl(" alpha %1").arg(cAlphaVersion() % 1000); + } else if (AppBetaVersion) { + result += " beta"; } return result; } diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index c06b671616..f1d095ab34 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -1071,6 +1071,15 @@ void DocumentData::refreshFileReference(const QByteArray &value) { _fileReference = value; } +void DocumentData::refreshStickerThumbFileReference() { + if (const auto data = sticker()) { + if (thumb->loading()) { + data->loc.refreshFileReference( + thumb->location().fileReference()); + } + } +} + QString DocumentData::filename() const { return _filename; } diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 2aaf4951be..79e6a57ba3 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -166,6 +166,7 @@ public: MTPInputDocument mtpInput() const; QByteArray fileReference() const; void refreshFileReference(const QByteArray &value); + void refreshStickerThumbFileReference(); // When we have some client-side generated document // (for example for displaying an external inline bot result) diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 906d0dd664..9603f9bba8 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -25,8 +25,9 @@ namespace { void SendToBannedHelp(const QString &phone) { const auto version = QString::fromLatin1(AppVersionStr.c_str()) - + (AppBetaVersion ? " beta" : "") - + (cAlphaVersion() ? qsl(" alpha %1").arg(cAlphaVersion()) : QString()); + + (cAlphaVersion() + ? qsl(" alpha %1").arg(cAlphaVersion()) + : (AppBetaVersion ? " beta" : "")); const auto subject = qsl("Banned phone number: ") + phone; diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 36d0d6e8be..d701cb8139 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -3210,7 +3210,7 @@ template void _writeStickerSets(FileKey &stickersKey, CheckSet checkSet, const Stickers::Order &order) { if (!_working()) return; - auto &sets = Auth().data().stickerSets(); + const auto &sets = Auth().data().stickerSets(); if (sets.isEmpty()) { if (stickersKey) { clearKey(stickersKey); @@ -3223,7 +3223,7 @@ void _writeStickerSets(FileKey &stickersKey, CheckSet checkSet, const Stickers:: int32 setsCount = 0; QByteArray hashToWrite; quint32 size = sizeof(quint32) + Serialize::bytearraySize(hashToWrite); - for_const (auto &set, sets) { + for (const auto &set : sets) { auto result = checkSet(set); if (result == StickerSetCheckResult::Abort) { return; @@ -3233,7 +3233,8 @@ void _writeStickerSets(FileKey &stickersKey, CheckSet checkSet, const Stickers:: // id + access + title + shortName + stickersCount + hash + flags + installDate size += sizeof(quint64) * 2 + Serialize::stringSize(set.title) + Serialize::stringSize(set.shortName) + sizeof(quint32) + sizeof(qint32) * 3; - for_const (auto &sticker, set.stickers) { + for (const auto sticker : std::as_const(set.stickers)) { + sticker->refreshStickerThumbFileReference(); size += Serialize::Document::sizeInStream(sticker); } size += sizeof(qint32); // dates count