mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Don't use MTP* for StickersSet flags.
This commit is contained in:
@@ -1511,6 +1511,7 @@ Cache::Database::Settings Account::cacheBigFileSettings() const {
|
||||
void Account::writeStickerSet(
|
||||
QDataStream &stream,
|
||||
const Data::StickersSet &set) {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
const auto writeInfo = [&](int count) {
|
||||
stream
|
||||
<< quint64(set.id)
|
||||
@@ -1523,7 +1524,7 @@ void Account::writeStickerSet(
|
||||
<< qint32(set.installDate);
|
||||
Serialize::writeImageLocation(stream, set.thumbnailLocation());
|
||||
};
|
||||
if (set.flags & MTPDstickerSet_ClientFlag::f_not_loaded) {
|
||||
if (set.flags & SetFlag::NotLoaded) {
|
||||
writeInfo(-set.count);
|
||||
return;
|
||||
} else if (set.stickers.isEmpty()) {
|
||||
@@ -1564,6 +1565,8 @@ void Account::writeStickerSets(
|
||||
FileKey &stickersKey,
|
||||
CheckSet checkSet,
|
||||
const Data::StickersSetsOrder &order) {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
const auto &sets = _owner->session().data().stickers().sets();
|
||||
if (sets.empty()) {
|
||||
if (stickersKey) {
|
||||
@@ -1593,7 +1596,7 @@ void Account::writeStickerSets(
|
||||
+ Serialize::stringSize(raw->shortName)
|
||||
+ sizeof(qint32) * 4
|
||||
+ Serialize::imageLocationSize(raw->thumbnailLocation());
|
||||
if (raw->flags & MTPDstickerSet_ClientFlag::f_not_loaded) {
|
||||
if (raw->flags & SetFlag::NotLoaded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1651,7 +1654,9 @@ void Account::writeStickerSets(
|
||||
void Account::readStickerSets(
|
||||
FileKey &stickersKey,
|
||||
Data::StickersSetsOrder *outOrder,
|
||||
MTPDstickerSet::Flags readingFlags) {
|
||||
Data::StickersSetFlags readingFlags) {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
FileReadDescriptor stickers;
|
||||
if (!ReadEncryptedFile(stickers, stickersKey, _basePath, _localKey)) {
|
||||
ClearKey(stickersKey, _basePath);
|
||||
@@ -1689,7 +1694,7 @@ void Account::readStickerSets(
|
||||
qint32 scnt = 0;
|
||||
qint32 setInstallDate = 0;
|
||||
qint32 setHash = 0;
|
||||
MTPDstickerSet::Flags setFlags = 0;
|
||||
Data::StickersSetFlags setFlags = 0;
|
||||
qint32 setFlagsValue = 0;
|
||||
ImageLocation setThumbnail;
|
||||
|
||||
@@ -1714,20 +1719,47 @@ void Account::readStickerSets(
|
||||
setThumbnail = *thumbnail;
|
||||
}
|
||||
|
||||
setFlags = MTPDstickerSet::Flags::from_raw(setFlagsValue);
|
||||
if (stickers.version >= 2008007) {
|
||||
setFlags = Data::StickersSetFlags::from_raw(setFlagsValue);
|
||||
} else {
|
||||
using Saved = MTPDstickerSet::Flag;
|
||||
using Flag = SetFlag;
|
||||
struct Conversion {
|
||||
Saved saved;
|
||||
Flag flag;
|
||||
};
|
||||
const auto conversions = {
|
||||
Conversion{ Saved::f_archived, Flag::Archived },
|
||||
Conversion{ Saved::f_installed_date, Flag::Installed },
|
||||
Conversion{ Saved::f_masks, Flag::Masks },
|
||||
Conversion{ Saved::f_official, Flag::Official },
|
||||
Conversion{ Saved(1U << 30), Flag::NotLoaded },
|
||||
Conversion{ Saved(1U << 29), Flag::Featured },
|
||||
Conversion{ Saved(1U << 28), Flag::Unread },
|
||||
Conversion{ Saved(1U << 27), Flag::Special },
|
||||
};
|
||||
auto flagsSet = Flag() | 0;
|
||||
for (const auto &conversion : conversions) {
|
||||
if (setFlagsValue & int(conversion.saved)) {
|
||||
flagsSet |= conversion.flag;
|
||||
}
|
||||
}
|
||||
setFlags = flagsSet;
|
||||
}
|
||||
|
||||
if (setId == Data::Stickers::DefaultSetId) {
|
||||
setTitle = tr::lng_stickers_default_set(tr::now);
|
||||
setFlags |= MTPDstickerSet::Flag::f_official | MTPDstickerSet_ClientFlag::f_special;
|
||||
setFlags |= SetFlag::Official | SetFlag::Special;
|
||||
} else if (setId == Data::Stickers::CustomSetId) {
|
||||
setTitle = qsl("Custom stickers");
|
||||
setFlags |= MTPDstickerSet_ClientFlag::f_special;
|
||||
setFlags |= SetFlag::Special;
|
||||
} else if ((setId == Data::Stickers::CloudRecentSetId)
|
||||
|| (setId == Data::Stickers::CloudRecentAttachedSetId)) {
|
||||
setTitle = tr::lng_recent_stickers(tr::now);
|
||||
setFlags |= MTPDstickerSet_ClientFlag::f_special;
|
||||
setFlags |= SetFlag::Special;
|
||||
} else if (setId == Data::Stickers::FavedSetId) {
|
||||
setTitle = Lang::Hard::FavedSetTitle();
|
||||
setFlags |= MTPDstickerSet_ClientFlag::f_special;
|
||||
setFlags |= SetFlag::Special;
|
||||
} else if (!setId) {
|
||||
continue;
|
||||
}
|
||||
@@ -1735,7 +1767,7 @@ void Account::readStickerSets(
|
||||
auto it = sets.find(setId);
|
||||
if (it == sets.cend()) {
|
||||
// We will set this flags from order lists when reading those stickers.
|
||||
setFlags &= ~(MTPDstickerSet::Flag::f_installed_date | MTPDstickerSet_ClientFlag::f_featured);
|
||||
setFlags &= ~(SetFlag::Installed | SetFlag::Featured);
|
||||
it = sets.emplace(setId, std::make_unique<Data::StickersSet>(
|
||||
&_owner->session().data(),
|
||||
setId,
|
||||
@@ -1744,7 +1776,7 @@ void Account::readStickerSets(
|
||||
setShortName,
|
||||
0,
|
||||
setHash,
|
||||
MTPDstickerSet::Flags(setFlags),
|
||||
setFlags,
|
||||
setInstallDate)).first;
|
||||
it->second->setThumbnail(
|
||||
ImageWithLocation{ .location = setThumbnail });
|
||||
@@ -1782,7 +1814,7 @@ void Account::readStickerSets(
|
||||
read.emplace(document->id);
|
||||
if (fillStickers) {
|
||||
set->stickers.push_back(document);
|
||||
if (!(set->flags & MTPDstickerSet_ClientFlag::f_special)) {
|
||||
if (!(set->flags & SetFlag::Special)) {
|
||||
if (!document->sticker()->set.id) {
|
||||
document->sticker()->set = inputSet;
|
||||
}
|
||||
@@ -1871,7 +1903,7 @@ void Account::readStickerSets(
|
||||
if (it != sets.cend()) {
|
||||
const auto set = it->second.get();
|
||||
set->flags |= readingFlags;
|
||||
if ((readingFlags == MTPDstickerSet::Flag::f_installed_date)
|
||||
if ((readingFlags == SetFlag::Installed)
|
||||
&& !set->installDate) {
|
||||
set->installDate = kDefaultStickerInstallDate;
|
||||
}
|
||||
@@ -1881,20 +1913,25 @@ void Account::readStickerSets(
|
||||
}
|
||||
|
||||
void Account::writeInstalledStickers() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
writeStickerSets(_installedStickersKey, [](const Data::StickersSet &set) {
|
||||
if (set.id == Data::Stickers::CloudRecentSetId
|
||||
|| set.id == Data::Stickers::FavedSetId
|
||||
|| set.id == Data::Stickers::CloudRecentAttachedSetId) { // separate files for them
|
||||
|| set.id == Data::Stickers::CloudRecentAttachedSetId) {
|
||||
// separate files for them
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (set.flags & MTPDstickerSet_ClientFlag::f_special) {
|
||||
} else if (set.flags & SetFlag::Special) {
|
||||
if (set.stickers.isEmpty()) { // all other special are "installed"
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
} else if (!(set.flags & MTPDstickerSet::Flag::f_installed_date) || (set.flags & MTPDstickerSet::Flag::f_archived)) {
|
||||
} else if (!(set.flags & SetFlag::Installed)
|
||||
|| (set.flags & SetFlag::Archived)) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (set.flags & MTPDstickerSet::Flag::f_masks) {
|
||||
} else if (set.flags & SetFlag::Masks) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (set.flags & MTPDstickerSet_ClientFlag::f_not_loaded) { // waiting to receive
|
||||
} else if (set.flags & SetFlag::NotLoaded) {
|
||||
// waiting to receive
|
||||
return StickerSetCheckResult::Abort;
|
||||
} else if (set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
@@ -1904,16 +1941,19 @@ void Account::writeInstalledStickers() {
|
||||
}
|
||||
|
||||
void Account::writeFeaturedStickers() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
writeStickerSets(_featuredStickersKey, [](const Data::StickersSet &set) {
|
||||
if (set.id == Data::Stickers::CloudRecentSetId
|
||||
|| set.id == Data::Stickers::FavedSetId
|
||||
|| set.id == Data::Stickers::CloudRecentAttachedSetId) { // separate files for them
|
||||
|| set.id == Data::Stickers::CloudRecentAttachedSetId) {
|
||||
// separate files for them
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (set.flags & MTPDstickerSet_ClientFlag::f_special) {
|
||||
} else if (set.flags & SetFlag::Special) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (!(set.flags & MTPDstickerSet_ClientFlag::f_featured)) {
|
||||
} else if (!(set.flags & SetFlag::Featured)) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
} else if (set.flags & MTPDstickerSet_ClientFlag::f_not_loaded) { // waiting to receive
|
||||
} else if (set.flags & SetFlag::NotLoaded) { // waiting to receive
|
||||
return StickerSetCheckResult::Abort;
|
||||
} else if (set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
@@ -1924,7 +1964,8 @@ void Account::writeFeaturedStickers() {
|
||||
|
||||
void Account::writeRecentStickers() {
|
||||
writeStickerSets(_recentStickersKey, [](const Data::StickersSet &set) {
|
||||
if (set.id != Data::Stickers::CloudRecentSetId || set.stickers.isEmpty()) {
|
||||
if (set.id != Data::Stickers::CloudRecentSetId
|
||||
|| set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
return StickerSetCheckResult::Write;
|
||||
@@ -1941,11 +1982,14 @@ void Account::writeFavedStickers() {
|
||||
}
|
||||
|
||||
void Account::writeArchivedStickers() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
writeStickerSets(_archivedStickersKey, [](const Data::StickersSet &set) {
|
||||
if (set.flags & MTPDstickerSet::Flag::f_masks) {
|
||||
if (set.flags & SetFlag::Masks) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
if (!(set.flags & MTPDstickerSet::Flag::f_archived) || set.stickers.isEmpty()) {
|
||||
if (!(set.flags & SetFlag::Archived)
|
||||
|| set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
return StickerSetCheckResult::Write;
|
||||
@@ -1953,11 +1997,13 @@ void Account::writeArchivedStickers() {
|
||||
}
|
||||
|
||||
void Account::writeArchivedMasks() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
writeStickerSets(_archivedStickersKey, [](const Data::StickersSet &set) {
|
||||
if (!(set.flags & MTPDstickerSet::Flag::f_masks)) {
|
||||
if (!(set.flags & SetFlag::Masks)) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
if (!(set.flags & MTPDstickerSet::Flag::f_archived) || set.stickers.isEmpty()) {
|
||||
if (!(set.flags & SetFlag::Archived) || set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
return StickerSetCheckResult::Write;
|
||||
@@ -1965,8 +2011,10 @@ void Account::writeArchivedMasks() {
|
||||
}
|
||||
|
||||
void Account::writeInstalledMasks() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
writeStickerSets(_installedMasksKey, [](const Data::StickersSet &set) {
|
||||
if (!(set.flags & MTPDstickerSet::Flag::f_masks) || set.stickers.isEmpty()) {
|
||||
if (!(set.flags & SetFlag::Masks) || set.stickers.isEmpty()) {
|
||||
return StickerSetCheckResult::Skip;
|
||||
}
|
||||
return StickerSetCheckResult::Write;
|
||||
@@ -1984,6 +2032,8 @@ void Account::writeRecentMasks() {
|
||||
}
|
||||
|
||||
void Account::importOldRecentStickers() {
|
||||
using SetFlag = Data::StickersSetFlag;
|
||||
|
||||
if (!_recentStickersKeyOld) {
|
||||
return;
|
||||
}
|
||||
@@ -2015,9 +2065,7 @@ void Account::importOldRecentStickers() {
|
||||
QString(),
|
||||
0, // count
|
||||
0, // hash
|
||||
(MTPDstickerSet::Flag::f_official
|
||||
| MTPDstickerSet::Flag::f_installed_date
|
||||
| MTPDstickerSet_ClientFlag::f_special),
|
||||
(SetFlag::Official | SetFlag::Installed | SetFlag::Special),
|
||||
kDefaultStickerInstallDate)).first->second.get();
|
||||
const auto custom = sets.emplace(
|
||||
Data::Stickers::CustomSetId,
|
||||
@@ -2029,8 +2077,7 @@ void Account::importOldRecentStickers() {
|
||||
QString(),
|
||||
0, // count
|
||||
0, // hash
|
||||
(MTPDstickerSet::Flag::f_installed_date
|
||||
| MTPDstickerSet_ClientFlag::f_special),
|
||||
(SetFlag::Installed | SetFlag::Special),
|
||||
kDefaultStickerInstallDate)).first->second.get();
|
||||
|
||||
QMap<uint64, bool> read;
|
||||
@@ -2112,14 +2159,14 @@ void Account::readInstalledStickers() {
|
||||
readStickerSets(
|
||||
_installedStickersKey,
|
||||
&_owner->session().data().stickers().setsOrderRef(),
|
||||
MTPDstickerSet::Flag::f_installed_date);
|
||||
Data::StickersSetFlag::Installed);
|
||||
}
|
||||
|
||||
void Account::readFeaturedStickers() {
|
||||
readStickerSets(
|
||||
_featuredStickersKey,
|
||||
&_owner->session().data().stickers().featuredSetsOrderRef(),
|
||||
MTPDstickerSet::Flags() | MTPDstickerSet_ClientFlag::f_featured);
|
||||
Data::StickersSetFlag::Featured);
|
||||
|
||||
const auto &sets = _owner->session().data().stickers().sets();
|
||||
const auto &order = _owner->session().data().stickers().featuredSetsOrder();
|
||||
@@ -2127,7 +2174,7 @@ void Account::readFeaturedStickers() {
|
||||
for (const auto setId : order) {
|
||||
auto it = sets.find(setId);
|
||||
if (it != sets.cend()
|
||||
&& (it->second->flags & MTPDstickerSet_ClientFlag::f_unread)) {
|
||||
&& (it->second->flags & Data::StickersSetFlag::Unread)) {
|
||||
++unreadCount;
|
||||
}
|
||||
}
|
||||
@@ -2172,7 +2219,7 @@ void Account::readInstalledMasks() {
|
||||
readStickerSets(
|
||||
_installedMasksKey,
|
||||
&_owner->session().data().stickers().maskSetsOrderRef(),
|
||||
MTPDstickerSet::Flag::f_installed_date);
|
||||
Data::StickersSetFlag::Installed);
|
||||
}
|
||||
|
||||
void Account::writeSavedGifs() {
|
||||
|
Reference in New Issue
Block a user