diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index d81d4a2544..044a604167 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -45,10 +45,11 @@ AuthSessionData::Variables::Variables() } QByteArray AuthSessionData::serialize() const { - auto size = sizeof(qint32) * 4; + auto size = sizeof(qint32) * 8; for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) { size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value()); } + size += _variables.groupStickersSectionHidden.size() * sizeof(quint64); auto result = QByteArray(); result.reserve(size); @@ -70,6 +71,10 @@ QByteArray AuthSessionData::serialize() const { stream << qint32(_variables.tabbedSelectorSectionTooltipShown); stream << qint32(_variables.floatPlayerColumn); stream << qint32(_variables.floatPlayerCorner); + stream << qint32(_variables.groupStickersSectionHidden.size()); + for (auto peerId : _variables.groupStickersSectionHidden) { + stream << quint64(peerId); + } } return result; } @@ -93,6 +98,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { qint32 floatPlayerColumn = static_cast(Window::Column::Second); qint32 floatPlayerCorner = static_cast(RectPart::TopRight); QMap soundOverrides; + OrderedSet groupStickersSectionHidden; stream >> selectorTab; stream >> lastSeenWarningSeen; if (!stream.atEnd()) { @@ -115,6 +121,17 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> floatPlayerColumn >> floatPlayerCorner; } + if (!stream.atEnd()) { + auto count = qint32(0); + stream >> count; + if (stream.status() == QDataStream::Ok) { + for (auto i = 0; i != count; ++i) { + quint64 peerId; + stream >> peerId; + groupStickersSectionHidden.insert(peerId); + } + } + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()")); return; @@ -143,6 +160,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { case RectPart::BottomLeft: case RectPart::BottomRight: _variables.floatPlayerCorner = uncheckedCorner; break; } + _variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden); } QString AuthSessionData::getSoundPath(const QString &key) const { diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index bb704c7ea6..c444381d40 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -133,6 +133,15 @@ public: RectPart floatPlayerCorner() const { return _variables.floatPlayerCorner; } + void setGroupStickersSectionHidden(PeerId peerId) { + _variables.groupStickersSectionHidden.insert(peerId); + } + bool isGroupStickersSectionHidden(PeerId peerId) const { + return _variables.groupStickersSectionHidden.contains(peerId); + } + void removeGroupStickersSectionHidden(PeerId peerId) { + _variables.groupStickersSectionHidden.remove(peerId); + } private: struct Variables { @@ -145,6 +154,7 @@ private: QMap soundOverrides; Window::Column floatPlayerColumn; RectPart floatPlayerCorner; + OrderedSet groupStickersSectionHidden; }; base::Variable _contactsLoaded = { false }; diff --git a/Telegram/SourceFiles/base/ordered_set.h b/Telegram/SourceFiles/base/ordered_set.h index d4845a59dd..9305be4b91 100644 --- a/Telegram/SourceFiles/base/ordered_set.h +++ b/Telegram/SourceFiles/base/ordered_set.h @@ -34,6 +34,13 @@ class OrderedSet { Impl impl_; public: + OrderedSet() = default; + OrderedSet(const OrderedSet &other) = default; + OrderedSet(OrderedSet &&other) = default; + OrderedSet &operator=(const OrderedSet &other) = default; + OrderedSet &operator=(OrderedSet &&other) = default; + ~OrderedSet() = default; + inline bool operator==(const Self &other) const { return impl_ == other.impl_; } inline bool operator!=(const Self &other) const { return impl_ != other.impl_; } inline int size() const { return impl_.size(); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index d28f4be705..e94baaf418 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1131,10 +1131,11 @@ void StickersListWidget::refreshStickers() { refreshRecentStickers(false); refreshFavedStickers(); - refreshMegagroupStickers(); + refreshMegagroupStickers(GroupStickersPlace::Visible); for_const (auto setId, Global::StickerSetsOrder()) { appendSet(_mySets, setId, AppendSkip::Archived); } + refreshMegagroupStickers(GroupStickersPlace::Hidden); _featuredSets.clear(); _featuredSets.reserve(Global::FeaturedStickerSetsOrder().size()); @@ -1288,16 +1289,26 @@ void StickersListWidget::refreshFavedStickers() { _mySets.push_back(Set(Stickers::FavedSetId, MTPDstickerSet::Flag::f_official | MTPDstickerSet_ClientFlag::f_special, lang(lng_faved_stickers), it->stickers.size() * 2, it->stickers)); } -void StickersListWidget::refreshMegagroupStickers() { +void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { if (!_megagroupSet) { return; } if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) { if (_megagroupSet->canEditStickers()) { - _mySets.push_back(Set(Stickers::MegagroupSetId, qFlags(MTPDstickerSet_ClientFlag::f_special), lang(lng_group_stickers), 0)); + auto hidden = Auth().data().isGroupStickersSectionHidden(_megagroupSet->id); + if (hidden == (place == GroupStickersPlace::Hidden)) { + _mySets.push_back(Set(Stickers::MegagroupSetId, qFlags(MTPDstickerSet_ClientFlag::f_special), lang(lng_group_stickers), 0)); + } } return; } + if (place != GroupStickersPlace::Visible) { + return; + } + if (Auth().data().isGroupStickersSectionHidden(_megagroupSet->id)) { + Auth().data().removeGroupStickersSectionHidden(_megagroupSet->id); + Local::writeUserSettings(); + } if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) { auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID(); auto &sets = Global::StickerSets(); @@ -1599,7 +1610,10 @@ void StickersListWidget::installSet(uint64 setId) { void StickersListWidget::removeMegagroupSet(bool empty) { if (empty) { - return; // TODO + Auth().data().setGroupStickersSectionHidden(_megagroupSet->id); + Local::writeUserSettings(); + refreshStickers(); + return; } _removingSetId = Stickers::MegagroupSetId; Ui::show(Box(lang(lng_stickers_remove_group_set), base::lambda_guarded(this, [this, group = _megagroupSet] { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 99dddb101c..e81740e445 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -155,7 +155,11 @@ private: bool stickerHasDeleteButton(const Set &set, int index) const; void refreshRecentStickers(bool resize = true); void refreshFavedStickers(); - void refreshMegagroupStickers(); + enum class GroupStickersPlace { + Visible, + Hidden, + }; + void refreshMegagroupStickers(GroupStickersPlace place); void updateSelected(); void setSelected(OverState newSelected);