mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Use 48 bit [User/Chat/Channel]Id, 56 bit PeerId.
This commit is contained in:
@@ -35,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Main {
|
||||
namespace {
|
||||
|
||||
constexpr auto kWideIdsTag = ~uint64(0);
|
||||
|
||||
[[nodiscard]] QString ComposeDataString(const QString &dataName, int index) {
|
||||
auto result = dataName;
|
||||
result.replace('#', QString());
|
||||
@@ -127,7 +129,7 @@ uint64 Account::willHaveSessionUniqueId(MTP::Config *config) const {
|
||||
if (!_sessionUserId) {
|
||||
return 0;
|
||||
}
|
||||
return uint64(uint32(_sessionUserId))
|
||||
return _sessionUserId.bare
|
||||
| (config && config->isTestMode() ? 0x0100'0000'0000'0000ULL : 0ULL);
|
||||
}
|
||||
|
||||
@@ -155,7 +157,7 @@ void Account::createSession(
|
||||
createSession(
|
||||
MTP_user(
|
||||
MTP_flags(flags),
|
||||
MTP_int(base::take(_sessionUserId)),
|
||||
MTP_int(base::take(_sessionUserId).bare), // #TODO ids
|
||||
MTPlong(), // access_hash
|
||||
MTPstring(), // first_name
|
||||
MTPstring(), // last_name
|
||||
@@ -276,7 +278,8 @@ QByteArray Account::serializeMtpAuthorization() const {
|
||||
};
|
||||
|
||||
auto result = QByteArray();
|
||||
auto size = sizeof(qint32) + sizeof(qint32); // userId + mainDcId
|
||||
// wide tag + userId + mainDcId
|
||||
auto size = 2 * sizeof(quint64) + sizeof(qint32);
|
||||
size += keysSize(keys) + keysSize(keysToDestroy);
|
||||
result.reserve(size);
|
||||
{
|
||||
@@ -285,12 +288,17 @@ QByteArray Account::serializeMtpAuthorization() const {
|
||||
|
||||
const auto currentUserId = sessionExists()
|
||||
? session().userId()
|
||||
: 0;
|
||||
stream << qint32(currentUserId) << qint32(mainDcId);
|
||||
: UserId();
|
||||
stream
|
||||
<< quint64(kWideIdsTag)
|
||||
<< quint64(currentUserId.bare)
|
||||
<< qint32(mainDcId);
|
||||
writeKeys(stream, keys);
|
||||
writeKeys(stream, keysToDestroy);
|
||||
|
||||
DEBUG_LOG(("MTP Info: Keys written, userId: %1, dcId: %2").arg(currentUserId).arg(mainDcId));
|
||||
DEBUG_LOG(("MTP Info: Keys written, userId: %1, dcId: %2"
|
||||
).arg(currentUserId.bare
|
||||
).arg(mainDcId));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -343,8 +351,18 @@ void Account::setMtpAuthorization(const QByteArray &serialized) {
|
||||
QDataStream stream(serialized);
|
||||
stream.setVersion(QDataStream::Qt_5_1);
|
||||
|
||||
auto userId = Serialize::read<qint32>(stream);
|
||||
auto mainDcId = Serialize::read<qint32>(stream);
|
||||
auto legacyUserId = Serialize::read<qint32>(stream);
|
||||
auto legacyMainDcId = Serialize::read<qint32>(stream);
|
||||
auto userId = quint64();
|
||||
auto mainDcId = qint32();
|
||||
if (((uint64(legacyUserId) << 32) | uint64(legacyMainDcId))
|
||||
== kWideIdsTag) {
|
||||
userId = Serialize::read<quint64>(stream);
|
||||
mainDcId = Serialize::read<qint32>(stream);
|
||||
} else {
|
||||
userId = legacyUserId;
|
||||
mainDcId = legacyMainDcId;
|
||||
}
|
||||
if (stream.status() != QDataStream::Ok) {
|
||||
LOG(("MTP Error: "
|
||||
"Could not read main fields from mtp authorization."));
|
||||
|
Reference in New Issue
Block a user