diff --git a/Telegram/SourceFiles/api/api_editing.cpp b/Telegram/SourceFiles/api/api_editing.cpp index d5f76bf86..662bfc980 100644 --- a/Telegram/SourceFiles/api/api_editing.cpp +++ b/Telegram/SourceFiles/api/api_editing.cpp @@ -128,7 +128,7 @@ mtpRequestId EditMessage( } if (updateRecentStickers) { - api->requestRecentStickersForce(true); + api->requestSpecialStickersForce(false, false, true); } }).fail([=](const MTP::Error &error, mtpRequestId requestId) { if constexpr (ErrorWithId) { diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 04a2e25f1..0f0fa264b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2585,7 +2585,7 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &resu void ApiWrap::updateStickers() { const auto now = crl::now(); requestStickers(now); - requestRecentStickers(now); + requestRecentStickers(now, false); requestFavedStickers(now); requestFeaturedStickers(now); } @@ -2607,8 +2607,15 @@ void ApiWrap::updateCustomEmoji() { requestFeaturedEmoji(now); } -void ApiWrap::requestRecentStickersForce(bool attached) { - requestRecentStickersWithHash(0, attached); +void ApiWrap::requestSpecialStickersForce( + bool faved, + bool recent, + bool attached) { + if (faved) { + requestFavedStickers(std::nullopt); + } else if (recent || attached) { + requestRecentStickers(std::nullopt, attached); + } } void ApiWrap::setGroupStickerSet( @@ -2761,18 +2768,17 @@ void ApiWrap::requestCustomEmoji(TimeId now) { }).send(); } -void ApiWrap::requestRecentStickers(TimeId now, bool attached) { - const auto needed = attached - ? _session->data().stickers().recentAttachedUpdateNeeded(now) - : _session->data().stickers().recentUpdateNeeded(now); +void ApiWrap::requestRecentStickers( + std::optional now, + bool attached) { + const auto needed = !now + ? true + : attached + ? _session->data().stickers().recentAttachedUpdateNeeded(*now) + : _session->data().stickers().recentUpdateNeeded(*now); if (!needed) { return; } - requestRecentStickersWithHash( - Api::CountRecentStickersHash(_session, attached), attached); -} - -void ApiWrap::requestRecentStickersWithHash(uint64 hash, bool attached) { const auto requestId = [=]() -> mtpRequestId & { return attached ? _recentAttachedStickersUpdateRequest @@ -2795,7 +2801,7 @@ void ApiWrap::requestRecentStickersWithHash(uint64 hash, bool attached) { : MTPmessages_getRecentStickers::Flags(0); requestId() = request(MTPmessages_GetRecentStickers( MTP_flags(flags), - MTP_long(hash) + MTP_long(now ? Api::CountRecentStickersHash(_session, attached) : 0) )).done([=](const MTPmessages_RecentStickers &result) { finish(); @@ -2822,13 +2828,15 @@ void ApiWrap::requestRecentStickersWithHash(uint64 hash, bool attached) { }).send(); } -void ApiWrap::requestFavedStickers(TimeId now) { - if (!_session->data().stickers().favedUpdateNeeded(now) - || _favedStickersUpdateRequest) { - return; +void ApiWrap::requestFavedStickers(std::optional now) { + if (now) { + if (!_session->data().stickers().favedUpdateNeeded(*now) + || _favedStickersUpdateRequest) { + return; + } } _favedStickersUpdateRequest = request(MTPmessages_GetFavedStickers( - MTP_long(Api::CountFavedStickersHash(_session)) + MTP_long(now ? Api::CountFavedStickersHash(_session) : 0) )).done([=](const MTPmessages_FavedStickers &result) { _session->data().stickers().setLastFavedUpdate(crl::now()); _favedStickersUpdateRequest = 0; @@ -4204,7 +4212,7 @@ void ApiWrap::sendMediaWithRandomId( ), [=](const MTPUpdates &result, const MTP::Response &response) { if (done) done(true); if (updateRecentStickers) { - requestRecentStickersForce(true); + requestRecentStickers(std::nullopt, true); } }, [=](const MTP::Error &error, const MTP::Response &response) { if (done) done(false); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 15c0941c3..7259c410d 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -244,7 +244,10 @@ public: void updateSavedGifs(); void updateMasks(); void updateCustomEmoji(); - void requestRecentStickersForce(bool attached = false); + void requestSpecialStickersForce( + bool faved, + bool recent, + bool attached); void setGroupStickerSet( not_null megagroup, const StickerSetIdentifier &set); @@ -477,9 +480,10 @@ private: void requestStickers(TimeId now); void requestMasks(TimeId now); void requestCustomEmoji(TimeId now); - void requestRecentStickers(TimeId now, bool attached = false); - void requestRecentStickersWithHash(uint64 hash, bool attached = false); - void requestFavedStickers(TimeId now); + void requestRecentStickers( + std::optional now, + bool attached); + void requestFavedStickers(std::optional now); void requestFeaturedStickers(TimeId now); void requestFeaturedEmoji(TimeId now); void requestSavedGifs(TimeId now); diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index 9ed24fb38..8000355c2 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -228,7 +228,7 @@ void Stickers::incrementSticker(not_null document) { auto index = set->stickers.indexOf(document); if (index > 0) { if (set->dates.empty()) { - session().api().requestRecentStickersForce(); + session().api().requestSpecialStickersForce(false, true, false); } else { Assert(set->dates.size() == set->stickers.size()); set->dates.erase(set->dates.begin() + index); @@ -260,7 +260,7 @@ void Stickers::incrementSticker(not_null document) { set->emoji[emoji].push_front(document); } } else { - session().api().requestRecentStickersForce(); + session().api().requestSpecialStickersForce(false, true, false); } writeRecentStickers = true;