2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Update API scheme to layer 133.

This commit is contained in:
John Preston
2021-08-25 11:15:05 +03:00
parent ce7a3c354c
commit a6c98f4bb4
61 changed files with 618 additions and 615 deletions

View File

@@ -178,7 +178,7 @@ void writePeer(QDataStream &stream, not_null<PeerData*> peer) {
<< channel->name
<< quint64(channel->access)
<< qint32(channel->date)
<< qint32(channel->version())
<< qint32(0) // legacy - version
<< qint32(0)
<< quint32(channel->flags())
<< channel->inviteLink();
@@ -277,9 +277,8 @@ PeerData *readPeer(
user->input = MTP_inputPeerSelf();
user->inputUser = MTP_inputUserSelf();
} else {
// #TODO ids
user->input = MTP_inputPeerUser(MTP_int(peerToUser(user->id).bare), MTP_long(user->accessHash()));
user->inputUser = MTP_inputUser(MTP_int(peerToUser(user->id).bare), MTP_long(user->accessHash()));
user->input = MTP_inputPeerUser(MTP_long(peerToUser(user->id).bare), MTP_long(user->accessHash()));
user->inputUser = MTP_inputUser(MTP_long(peerToUser(user->id).bare), MTP_long(user->accessHash()));
}
}
} else if (const auto chat = result->asChat()) {
@@ -350,8 +349,7 @@ PeerData *readPeer(
chat->creator = creator;
chat->setInviteLink(inviteLink);
// #TODO ids
chat->input = MTP_inputPeerChat(MTP_int(peerToChat(chat->id).bare));
chat->input = MTP_inputPeerChat(MTP_long(peerToChat(chat->id).bare));
}
} else if (const auto channel = result->asChannel()) {
QString name, inviteLink;
@@ -374,10 +372,6 @@ PeerData *readPeer(
channel->access = access;
channel->date = date;
// We don't save participants, admin status and banned rights.
// So we don't restore the version field, info is still unknown.
channel->setVersion(0);
if (streamAppVersion >= 2008007) {
channel->setFlags(ChannelDataFlags::from_raw(flags));
} else {
@@ -422,9 +416,8 @@ PeerData *readPeer(
channel->setInviteLink(inviteLink);
// #TODO ids
channel->input = MTP_inputPeerChannel(MTP_int(peerToChannel(channel->id).bare), MTP_long(access));
channel->inputChannel = MTP_inputChannel(MTP_int(peerToChannel(channel->id).bare), MTP_long(access));
channel->input = MTP_inputPeerChannel(MTP_long(peerToChannel(channel->id).bare), MTP_long(access));
channel->inputChannel = MTP_inputChannel(MTP_long(peerToChannel(channel->id).bare), MTP_long(access));
}
}
if (apply) {

View File

@@ -42,7 +42,7 @@ using Database = Cache::Database;
constexpr auto kDelayedWriteTimeout = crl::time(1000);
constexpr auto kStickersVersionTag = quint32(-1);
constexpr auto kStickersSerializeVersion = 1;
constexpr auto kStickersSerializeVersion = 2;
constexpr auto kMaxSavedStickerSetsCount = 1000;
constexpr auto kDefaultStickerInstallDate = TimeId(1);
@@ -1550,11 +1550,11 @@ void Account::writeStickerSet(
const auto writeInfo = [&](int count) {
stream
<< quint64(set.id)
<< quint64(set.access)
<< quint64(set.accessHash)
<< quint64(set.hash)
<< set.title
<< set.shortName
<< qint32(count)
<< qint32(set.hash)
<< qint32(set.flags)
<< qint32(set.installDate);
Serialize::writeImageLocation(stream, set.thumbnailLocation());
@@ -1625,11 +1625,11 @@ void Account::writeStickerSets(
continue;
}
// id + access + title + shortName + stickersCount + hash + flags + installDate
size += sizeof(quint64) * 2
// id + accessHash + hash + title + shortName + stickersCount + flags + installDate
size += sizeof(quint64) * 3
+ Serialize::stringSize(raw->title)
+ Serialize::stringSize(raw->shortName)
+ sizeof(qint32) * 4
+ sizeof(qint32) * 3
+ Serialize::imageLocationSize(raw->thumbnailLocation());
if (raw->flags & SetFlag::NotLoaded) {
continue;
@@ -1724,22 +1724,21 @@ void Account::readStickerSets(
return failed();
}
for (auto i = 0; i != count; ++i) {
quint64 setId = 0, setAccess = 0;
quint64 setId = 0, setAccessHash = 0, setHash = 0;
QString setTitle, setShortName;
qint32 scnt = 0;
qint32 setInstallDate = 0;
qint32 setHash = 0;
Data::StickersSetFlags setFlags = 0;
qint32 setFlagsValue = 0;
ImageLocation setThumbnail;
stickers.stream
>> setId
>> setAccess
>> setAccessHash
>> setHash
>> setTitle
>> setShortName
>> scnt
>> setHash
>> setFlagsValue
>> setInstallDate;
const auto thumbnail = Serialize::readImageLocation(
@@ -1754,34 +1753,7 @@ void Account::readStickerSets(
setThumbnail = *thumbnail;
}
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;
}
setFlags = Data::StickersSetFlags::from_raw(setFlagsValue);
if (setId == Data::Stickers::DefaultSetId) {
setTitle = tr::lng_stickers_default_set(tr::now);
setFlags |= SetFlag::Official | SetFlag::Special;
@@ -1806,11 +1778,11 @@ void Account::readStickerSets(
it = sets.emplace(setId, std::make_unique<Data::StickersSet>(
&_owner->session().data(),
setId,
setAccess,
setAccessHash,
setHash,
setTitle,
setShortName,
0,
setHash,
setFlags,
setInstallDate)).first;
it->second->setThumbnail(
@@ -1832,7 +1804,10 @@ void Account::readStickerSets(
set->count = 0;
}
Serialize::Document::StickerSetInfo info(setId, setAccess, setShortName);
Serialize::Document::StickerSetInfo info(
setId,
setAccessHash,
setShortName);
base::flat_set<DocumentId> read;
for (int32 j = 0; j < scnt; ++j) {
auto document = Serialize::Document::readStickerFromStream(
@@ -2095,11 +2070,11 @@ void Account::importOldRecentStickers() {
std::make_unique<Data::StickersSet>(
&_owner->session().data(),
Data::Stickers::DefaultSetId,
uint64(0),
uint64(0), // accessHash
uint64(0), // hash
tr::lng_stickers_default_set(tr::now),
QString(),
0, // count
0, // hash
(SetFlag::Official | SetFlag::Installed | SetFlag::Special),
kDefaultStickerInstallDate)).first->second.get();
const auto custom = sets.emplace(
@@ -2107,11 +2082,11 @@ void Account::importOldRecentStickers() {
std::make_unique<Data::StickersSet>(
&_owner->session().data(),
Data::Stickers::CustomSetId,
uint64(0),
uint64(0), // accessHash
uint64(0), // hash
qsl("Custom stickers"),
QString(),
0, // count
0, // hash
(SetFlag::Installed | SetFlag::Special),
kDefaultStickerInstallDate)).first->second.get();
@@ -2607,13 +2582,13 @@ Export::Settings Account::readExportSettings() {
switch (singlePeerType) {
case kSinglePeerTypeUser:
return MTP_inputPeerUser(
MTP_int(singlePeerBareId),
MTP_long(singlePeerBareId),
MTP_long(singlePeerAccessHash));
case kSinglePeerTypeChat:
return MTP_inputPeerChat(MTP_int(singlePeerBareId));
return MTP_inputPeerChat(MTP_long(singlePeerBareId));
case kSinglePeerTypeChannel:
return MTP_inputPeerChannel(
MTP_int(singlePeerBareId),
MTP_long(singlePeerBareId),
MTP_long(singlePeerAccessHash));
case kSinglePeerTypeSelf:
return MTP_inputPeerSelf();