diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 120c35b847..1f9ccba0a9 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -2373,7 +2373,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { ////// Cloud saved GIFs case mtpc_updateSavedGifs: { session().data().stickers().setLastSavedGifsUpdate(0); - session().api().updateStickers(); + session().api().updateSavedGifs(); } break; ////// Cloud drafts diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 4f316cfe02..4fa3aab5fd 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2526,7 +2526,10 @@ void ApiWrap::updateStickers() { requestRecentStickers(now); requestFavedStickers(now); requestFeaturedStickers(now); - requestFeaturedEmoji(now); +} + +void ApiWrap::updateSavedGifs() { + const auto now = crl::now(); requestSavedGifs(now); } @@ -2539,6 +2542,7 @@ void ApiWrap::updateMasks() { void ApiWrap::updateCustomEmoji() { const auto now = crl::now(); requestCustomEmoji(now); + requestFeaturedEmoji(now); } void ApiWrap::requestRecentStickersForce(bool attached) { diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index b67f1a586c..18a693eb0a 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -232,6 +232,7 @@ public: const Data::StickersSetsOrder &localRemoved, Data::StickersType type); void updateStickers(); + void updateSavedGifs(); void updateMasks(); void updateCustomEmoji(); void requestRecentStickersForce(bool attached = false); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index d0766585fe..51b0897675 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -388,6 +388,7 @@ StickersBox::StickersBox( controller->session().data().stickers().featuredSetsUnreadCountValue()) , _section(section) , _isMasks(masks) +, _isEmoji(false) , _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed)) , _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab()) , _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured)) @@ -403,6 +404,7 @@ StickersBox::StickersBox( , _api(&controller->session().mtp()) , _section(Section::Installed) , _isMasks(false) +, _isEmoji(false) , _installed(0, this, controller, megagroup) , _megagroupSet(megagroup) { _installed.widget()->scrollsToY( @@ -419,6 +421,7 @@ StickersBox::StickersBox( , _api(&controller->session().mtp()) , _section(Section::Attached) , _isMasks(false) +, _isEmoji(false) , _attached(0, this, controller, Section::Attached) , _attachedType(Data::StickersType::Stickers) , _attachedSets(attachedSets) { @@ -432,6 +435,7 @@ StickersBox::StickersBox( , _api(&controller->session().mtp()) , _section(Section::Attached) , _isMasks(false) +, _isEmoji(true) , _attached(0, this, controller, Section::Attached) , _attachedType(Data::StickersType::Emoji) , _emojiSets(emojiSets) { @@ -618,13 +622,22 @@ void StickersBox::prepare() { setInnerWidget(_tab->takeWidget(), getTopSkip()); setDimensions(st::boxWideWidth, st::boxMaxListHeight); - session().data().stickers().updated( - _isMasks ? Data::StickersType::Masks : Data::StickersType::Stickers + session().data().stickers().updated(_isEmoji + ? Data::StickersType::Emoji + : _isMasks + ? Data::StickersType::Masks + : Data::StickersType::Stickers ) | rpl::start_with_next([=] { handleStickersUpdated(); }, lifetime()); - session().api().updateStickers(); - session().api().updateMasks(); + + if (_isEmoji) { + session().api().updateCustomEmoji(); + } else if (_isMasks) { + session().api().updateMasks(); + } else { + session().api().updateStickers(); + } for (const auto &widget : { _installed.widget(), _masks.widget() }) { if (widget) { @@ -1053,9 +1066,23 @@ StickersBox::Inner::Row::Row( , removed(removed) , pixw(pixw) , pixh(pixh) { + ++set->locked; } -StickersBox::Inner::Row::~Row() = default; +StickersBox::Inner::Row::~Row() { + if (!--set->locked) { + const auto installed = !!(set->flags & SetFlag::Installed); + const auto featured = !!(set->flags & SetFlag::Featured); + const auto special = !!(set->flags & SetFlag::Special); + const auto archived = !!(set->flags & SetFlag::Archived); + if (!installed && !featured && !special && !archived) { + auto &sets = set->owner().stickers().setsRef(); + if (const auto i = sets.find(set->id); i != end(sets)) { + sets.erase(i); + } + } + } +} bool StickersBox::Inner::Row::isRecentSet() const { return (set->id == Data::Stickers::CloudRecentSetId) diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 8ee2807197..bb1c712eb4 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -154,6 +154,7 @@ private: Section _section; const bool _isMasks; + const bool _isEmoji; Tab _installed; Tab _masks; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index fb1461fc32..959e71a40e 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -151,7 +151,6 @@ StickersListWidget::Set &StickersListWidget::Set::operator=( Set &&other) = default; StickersListWidget::Set::~Set() = default; - void StickersListWidget::Sticker::ensureMediaCreated() { if (documentMedia) { return; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 023127c06b..5718f195fb 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -801,6 +801,9 @@ void TabbedSelector::showStarted() { if (hasEmojiTab()) { session().api().updateCustomEmoji(); } + if (hasGifsTab()) { + session().api().updateSavedGifs(); + } currentTab()->widget()->refreshRecent(); currentTab()->widget()->preloadImages(); _a_slide.stop(); diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index b9b489d5bc..88b529e52b 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -334,7 +334,7 @@ void Stickers::addSavedGif( notifySavedGifsUpdated(); setLastSavedGifsUpdate(0); - session->api().updateStickers(); + session->api().updateSavedGifs(); } void Stickers::checkSavedGif(not_null item) { @@ -734,6 +734,7 @@ void Stickers::somethingReceived( const auto featured = !!(set->flags & SetFlag::Featured); const auto special = !!(set->flags & SetFlag::Special); const auto archived = !!(set->flags & SetFlag::Archived); + const auto locked = (set->locked > 0); if (!installed) { // remove not mine sets from recent stickers for (auto i = recent.begin(); i != recent.cend();) { if (set->stickers.indexOf(i->first) >= 0) { @@ -744,7 +745,7 @@ void Stickers::somethingReceived( } } } - if (installed || featured || special || archived) { + if (installed || featured || special || archived || locked) { ++it; } else { it = sets.erase(it); @@ -1055,11 +1056,12 @@ void Stickers::featuredReceived( auto unreadCount = 0; for (auto it = sets.begin(); it != sets.end();) { const auto set = it->second.get(); - bool installed = (set->flags & SetFlag::Installed); - bool featured = (set->flags & SetFlag::Featured); - bool special = (set->flags & SetFlag::Special); - bool archived = (set->flags & SetFlag::Archived); - if (installed || featured || special || archived) { + const auto installed = (set->flags & SetFlag::Installed); + const auto featured = (set->flags & SetFlag::Featured); + const auto special = (set->flags & SetFlag::Special); + const auto archived = (set->flags & SetFlag::Archived); + const auto locked = (set->locked > 0); + if (installed || featured || special || archived || locked) { if (featured && (set->flags & SetFlag::Unread)) { if (!(set->flags & SetFlag::Emoji)) { ++unreadCount; diff --git a/Telegram/SourceFiles/data/stickers/data_stickers_set.h b/Telegram/SourceFiles/data/stickers/data_stickers_set.h index 2a3063c3ed..4fc9b5f823 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers_set.h +++ b/Telegram/SourceFiles/data/stickers/data_stickers_set.h @@ -105,6 +105,7 @@ public: DocumentId thumbnailDocumentId = 0; QString title, shortName; int count = 0; + int locked = 0; StickersSetFlags flags; TimeId installDate = 0; StickersPack covers;