mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Write serialized peer has_video correctly, versioned.
This commit is contained in:
parent
ce7b6fe17a
commit
7c2223e540
1 changed files with 35 additions and 14 deletions
|
@ -20,6 +20,8 @@ namespace Serialize {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kModernImageLocationTag = std::numeric_limits<qint32>::min();
|
constexpr auto kModernImageLocationTag = std::numeric_limits<qint32>::min();
|
||||||
|
constexpr auto kVersionTag = uint64(0x77FF'FFFF'FFFF'FFFFULL);
|
||||||
|
constexpr auto kVersion = 1;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -111,7 +113,10 @@ std::optional<ImageLocation> readImageLocation(
|
||||||
uint32 peerSize(not_null<PeerData*> peer) {
|
uint32 peerSize(not_null<PeerData*> peer) {
|
||||||
uint32 result = sizeof(quint64)
|
uint32 result = sizeof(quint64)
|
||||||
+ sizeof(quint64)
|
+ sizeof(quint64)
|
||||||
+ imageLocationSize(peer->userpicLocation());
|
+ sizeof(qint32)
|
||||||
|
+ sizeof(quint64)
|
||||||
|
+ imageLocationSize(peer->userpicLocation())
|
||||||
|
+ sizeof(qint32);
|
||||||
if (const auto user = peer->asUser()) {
|
if (const auto user = peer->asUser()) {
|
||||||
result += stringSize(user->firstName)
|
result += stringSize(user->firstName)
|
||||||
+ stringSize(user->lastName)
|
+ stringSize(user->lastName)
|
||||||
|
@ -144,7 +149,11 @@ uint32 peerSize(not_null<PeerData*> peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void writePeer(QDataStream &stream, not_null<PeerData*> peer) {
|
void writePeer(QDataStream &stream, not_null<PeerData*> peer) {
|
||||||
stream << SerializePeerId(peer->id) << quint64(peer->userpicPhotoId());
|
stream
|
||||||
|
<< SerializePeerId(peer->id)
|
||||||
|
<< quint64(kVersionTag)
|
||||||
|
<< qint32(kVersion)
|
||||||
|
<< quint64(peer->userpicPhotoId());
|
||||||
writeImageLocation(stream, peer->userpicLocation());
|
writeImageLocation(stream, peer->userpicLocation());
|
||||||
stream << qint32(peer->userpicHasVideo() ? 1 : 0);
|
stream << qint32(peer->userpicHasVideo() ? 1 : 0);
|
||||||
if (const auto user = peer->asUser()) {
|
if (const auto user = peer->asUser()) {
|
||||||
|
@ -190,20 +199,25 @@ PeerData *readPeer(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
int streamAppVersion,
|
int streamAppVersion,
|
||||||
QDataStream &stream) {
|
QDataStream &stream) {
|
||||||
quint64 peerIdSerialized = 0, photoId = 0;
|
quint64 peerIdSerialized = 0, versionTag = 0, photoId = 0;
|
||||||
qint32 photoHasVideo = 0;
|
qint32 version = 0, photoHasVideo = 0;
|
||||||
stream >> peerIdSerialized >> photoId;
|
stream >> peerIdSerialized >> versionTag;
|
||||||
const auto peerId = DeserializePeerId(peerIdSerialized);
|
const auto peerId = DeserializePeerId(peerIdSerialized);
|
||||||
if (!peerId) {
|
if (!peerId) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (versionTag == kVersionTag) {
|
||||||
|
stream >> version >> photoId;
|
||||||
|
} else {
|
||||||
|
photoId = versionTag;
|
||||||
|
}
|
||||||
|
|
||||||
const auto userpic = readImageLocation(streamAppVersion, stream);
|
const auto userpic = readImageLocation(streamAppVersion, stream);
|
||||||
auto userpicAccessHash = uint64(0);
|
auto userpicAccessHash = uint64(0);
|
||||||
if (!userpic) {
|
if (!userpic) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (streamAppVersion >= 4000000 || true AssertIsDebug()) {
|
if (version > 0) {
|
||||||
stream >> photoHasVideo;
|
stream >> photoHasVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,17 +449,24 @@ PeerData *readPeer(
|
||||||
}
|
}
|
||||||
|
|
||||||
QString peekUserPhone(int streamAppVersion, QDataStream &stream) {
|
QString peekUserPhone(int streamAppVersion, QDataStream &stream) {
|
||||||
quint64 peerIdSerialized = 0, photoId = 0;
|
quint64 peerIdSerialized = 0, versionTag = 0, photoId = 0;
|
||||||
stream >> peerIdSerialized >> photoId;
|
qint32 version = 0, photoHasVideo = 0;
|
||||||
|
stream >> peerIdSerialized >> versionTag;
|
||||||
const auto peerId = DeserializePeerId(peerIdSerialized);
|
const auto peerId = DeserializePeerId(peerIdSerialized);
|
||||||
DEBUG_LOG(("peekUserPhone.id: %1").arg(peerId.value));
|
DEBUG_LOG(("peekUserPhone.id: %1").arg(peerId.value));
|
||||||
if (!peerId
|
if (!peerId || !peerIsUser(peerId)) {
|
||||||
|| !peerIsUser(peerId)
|
return nullptr;
|
||||||
|| !readImageLocation(streamAppVersion, stream)) {
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
if (streamAppVersion >= 4000000 || true AssertIsDebug()) {
|
if (versionTag == kVersionTag) {
|
||||||
qint32 photoHasVideo = 0;
|
stream >> version >> photoId;
|
||||||
|
} else {
|
||||||
|
photoId = versionTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!readImageLocation(streamAppVersion, stream)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (version > 0) {
|
||||||
stream >> photoHasVideo;
|
stream >> photoHasVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue