mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-11 01:10:13 +00:00
Allow to hide empty megagroup sticker set.
This commit is contained in:
parent
25f18c0c3a
commit
7f5a91d2bb
@ -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<qint32>(Window::Column::Second);
|
||||
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
|
||||
QMap<QString, QString> soundOverrides;
|
||||
OrderedSet<PeerId> 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 {
|
||||
|
@ -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<QString, QString> soundOverrides;
|
||||
Window::Column floatPlayerColumn;
|
||||
RectPart floatPlayerCorner;
|
||||
OrderedSet<PeerId> groupStickersSectionHidden;
|
||||
};
|
||||
|
||||
base::Variable<bool> _contactsLoaded = { false };
|
||||
|
@ -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(); }
|
||||
|
@ -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<ConfirmBox>(lang(lng_stickers_remove_group_set), base::lambda_guarded(this, [this, group = _megagroupSet] {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user