2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Use getters in MTP classes.

This commit is contained in:
John Preston
2019-07-05 15:38:38 +02:00
parent 3ca28c0cf9
commit 567bf60644
100 changed files with 2807 additions and 2672 deletions

View File

@@ -233,24 +233,24 @@ ImagePtr CreateFromPhotoSize(
const MTPPhotoSize &size,
Method method = Method()) {
return size.match([&](const MTPDphotoSize &data) {
const auto &location = data.vlocation.c_fileLocationToBeDeprecated();
const auto &location = data.vlocation().c_fileLocationToBeDeprecated();
return method(
StorageImageLocation(
createLocation(data.vtype, location),
data.vw.v,
data.vh.v),
data.vsize.v);
createLocation(data.vtype(), location),
data.vw().v,
data.vh().v),
data.vsize().v);
}, [&](const MTPDphotoCachedSize &data) {
const auto bytes = qba(data.vbytes);
const auto &location = data.vlocation.c_fileLocationToBeDeprecated();
const auto bytes = qba(data.vbytes());
const auto &location = data.vlocation().c_fileLocationToBeDeprecated();
return method(
StorageImageLocation(
createLocation(data.vtype, location),
data.vw.v,
data.vh.v),
createLocation(data.vtype(), location),
data.vw().v,
data.vh().v),
bytes);
}, [&](const MTPDphotoStrippedSize &data) {
const auto bytes = qba(data.vbytes);
const auto bytes = qba(data.vbytes());
if (bytes.size() < 3 || bytes[0] != '\x01') {
return ImagePtr();
}
@@ -307,18 +307,21 @@ ImagePtr CreateFromPhotoSize(
}
ImagePtr Create(const MTPDstickerSet &set, const MTPPhotoSize &size) {
const auto thumbDcId = set.vthumb_dc_id();
const auto create = [&](
const MTPstring &thumbSize,
const MTPDfileLocationToBeDeprecated &location) {
return StorageFileLocation(
set.vthumb_dc_id.v,
thumbDcId->v,
Auth().userId(),
MTP_inputStickerSetThumb(
MTP_inputStickerSetID(set.vid, set.vaccess_hash),
location.vvolume_id,
location.vlocal_id));
MTP_inputStickerSetID(set.vid(), set.vaccess_hash()),
location.vvolume_id(),
location.vlocal_id()));
};
return CreateFromPhotoSize(create, size, CreateSetThumbnail());
return thumbDcId
? CreateFromPhotoSize(create, size, CreateSetThumbnail())
: ImagePtr();
}
ImagePtr CreateStickerSetThumbnail(const StorageImageLocation &location) {
@@ -330,12 +333,12 @@ ImagePtr Create(const MTPDphoto &photo, const MTPPhotoSize &size) {
const MTPstring &thumbSize,
const MTPDfileLocationToBeDeprecated &location) {
return StorageFileLocation(
photo.vdc_id.v,
photo.vdc_id().v,
Auth().userId(),
MTP_inputPhotoFileLocation(
photo.vid,
photo.vaccess_hash,
photo.vfile_reference,
photo.vid(),
photo.vaccess_hash(),
photo.vfile_reference(),
thumbSize));
};
return CreateFromPhotoSize(create, size);
@@ -346,12 +349,12 @@ ImagePtr Create(const MTPDdocument &document, const MTPPhotoSize &size) {
const MTPstring &thumbSize,
const MTPDfileLocationToBeDeprecated &location) {
return StorageFileLocation(
document.vdc_id.v,
document.vdc_id().v,
Auth().userId(),
MTP_inputDocumentFileLocation(
document.vid,
document.vaccess_hash,
document.vfile_reference,
document.vid(),
document.vaccess_hash(),
document.vfile_reference(),
thumbSize));
};
return CreateFromPhotoSize(create, size);
@@ -361,63 +364,63 @@ QSize getImageSize(const QVector<MTPDocumentAttribute> &attributes) {
for (const auto &attribute : attributes) {
if (attribute.type() == mtpc_documentAttributeImageSize) {
auto &size = attribute.c_documentAttributeImageSize();
return QSize(size.vw.v, size.vh.v);
return QSize(size.vw().v, size.vh().v);
}
}
return QSize();
}
ImagePtr Create(const MTPDwebDocument &document) {
const auto size = getImageSize(document.vattributes.v);
const auto size = getImageSize(document.vattributes().v);
if (size.isEmpty()) {
return ImagePtr();
}
// We don't use size from WebDocument, because it is not reliable.
// It can be > 0 and different from the real size that we get in upload.WebFile result.
auto filesize = 0; // document.vsize.v;
auto filesize = 0; // document.vsize().v;
return Create(
WebFileLocation(
document.vurl.v,
document.vaccess_hash.v),
document.vurl().v,
document.vaccess_hash().v),
size.width(),
size.height(),
filesize);
}
ImagePtr Create(const MTPDwebDocumentNoProxy &document) {
const auto size = getImageSize(document.vattributes.v);
const auto size = getImageSize(document.vattributes().v);
if (size.isEmpty()) {
return ImagePtr();
}
return Create(qs(document.vurl), size.width(), size.height());
return Create(qs(document.vurl()), size.width(), size.height());
}
ImagePtr Create(const MTPDwebDocument &document, QSize box) {
//const auto size = getImageSize(document.vattributes.v);
//const auto size = getImageSize(document.vattributes().v);
//if (size.isEmpty()) {
// return ImagePtr();
//}
// We don't use size from WebDocument, because it is not reliable.
// It can be > 0 and different from the real size that we get in upload.WebFile result.
auto filesize = 0; // document.vsize.v;
auto filesize = 0; // document.vsize().v;
return Create(
WebFileLocation(
document.vurl.v,
document.vaccess_hash.v),
document.vurl().v,
document.vaccess_hash().v),
box,
filesize);
}
ImagePtr Create(const MTPDwebDocumentNoProxy &document, QSize box) {
//const auto size = getImageSize(document.vattributes.v);
//const auto size = getImageSize(document.vattributes().v);
//if (size.isEmpty()) {
// return ImagePtr();
//}
return Create(qs(document.vurl), box);
return Create(qs(document.vurl()), box);
}
ImagePtr Create(const MTPWebDocument &document) {

View File

@@ -84,36 +84,36 @@ StorageFileLocation::StorageFileLocation(
: _dcId(dcId) {
tl.match([&](const MTPDinputFileLocation &data) {
_type = Type::Legacy;
_volumeId = data.vvolume_id.v;
_localId = data.vlocal_id.v;
_accessHash = data.vsecret.v;
_fileReference = data.vfile_reference.v;
_volumeId = data.vvolume_id().v;
_localId = data.vlocal_id().v;
_accessHash = data.vsecret().v;
_fileReference = data.vfile_reference().v;
}, [&](const MTPDinputEncryptedFileLocation &data) {
_type = Type::Encrypted;
_id = data.vid.v;
_accessHash = data.vaccess_hash.v;
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
}, [&](const MTPDinputDocumentFileLocation &data) {
_type = Type::Document;
_id = data.vid.v;
_accessHash = data.vaccess_hash.v;
_fileReference = data.vfile_reference.v;
_sizeLetter = data.vthumb_size.v.isEmpty()
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
_fileReference = data.vfile_reference().v;
_sizeLetter = data.vthumb_size().v.isEmpty()
? uint8(0)
: uint8(data.vthumb_size.v[0]);
: uint8(data.vthumb_size().v[0]);
}, [&](const MTPDinputSecureFileLocation &data) {
_type = Type::Secure;
_id = data.vid.v;
_accessHash = data.vaccess_hash.v;
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
}, [&](const MTPDinputTakeoutFileLocation &data) {
_type = Type::Takeout;
}, [&](const MTPDinputPhotoFileLocation &data) {
_type = Type::Photo;
_id = data.vid.v;
_accessHash = data.vaccess_hash.v;
_fileReference = data.vfile_reference.v;
_sizeLetter = data.vthumb_size.v.isEmpty()
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
_fileReference = data.vfile_reference().v;
_sizeLetter = data.vthumb_size().v.isEmpty()
? char(0)
: data.vthumb_size.v[0];
: data.vthumb_size().v[0];
}, [&](const MTPDinputPeerPhotoFileLocation &data) {
_type = Type::PeerPhoto;
const auto fillPeer = base::overload([&](
@@ -122,45 +122,45 @@ StorageFileLocation::StorageFileLocation(
}, [&](const MTPDinputPeerSelf & data) {
_id = peerFromUser(self);
}, [&](const MTPDinputPeerChat & data) {
_id = peerFromChat(data.vchat_id);
_id = peerFromChat(data.vchat_id());
}, [&](const MTPDinputPeerUser & data) {
_id = peerFromUser(data.vuser_id);
_accessHash = data.vaccess_hash.v;
_id = peerFromUser(data.vuser_id());
_accessHash = data.vaccess_hash().v;
}, [&](const MTPDinputPeerChannel & data) {
_id = peerFromChannel(data.vchannel_id);
_accessHash = data.vaccess_hash.v;
_id = peerFromChannel(data.vchannel_id());
_accessHash = data.vaccess_hash().v;
});
data.vpeer.match(fillPeer, [&](
data.vpeer().match(fillPeer, [&](
const MTPDinputPeerUserFromMessage &data) {
data.vpeer.match(fillPeer, [&](auto &&) {
data.vpeer().match(fillPeer, [&](auto &&) {
// Bad data provided.
_id = _accessHash = 0;
});
_inMessagePeerId = data.vuser_id.v;
_inMessageId = data.vmsg_id.v;
_inMessagePeerId = data.vuser_id().v;
_inMessageId = data.vmsg_id().v;
}, [&](const MTPDinputPeerChannelFromMessage &data) {
data.vpeer.match(fillPeer, [&](auto &&) {
data.vpeer().match(fillPeer, [&](auto &&) {
// Bad data provided.
_id = _accessHash = 0;
});
_inMessagePeerId = -data.vchannel_id.v;
_inMessageId = data.vmsg_id.v;
_inMessagePeerId = -data.vchannel_id().v;
_inMessageId = data.vmsg_id().v;
});
_volumeId = data.vvolume_id.v;
_localId = data.vlocal_id.v;
_volumeId = data.vvolume_id().v;
_localId = data.vlocal_id().v;
_sizeLetter = data.is_big() ? 'c' : 'a';
}, [&](const MTPDinputStickerSetThumb &data) {
_type = Type::StickerSetThumb;
data.vstickerset.match([&](const MTPDinputStickerSetEmpty &data) {
data.vstickerset().match([&](const MTPDinputStickerSetEmpty &data) {
_id = 0;
}, [&](const MTPDinputStickerSetID &data) {
_id = data.vid.v;
_accessHash = data.vaccess_hash.v;
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
}, [&](const MTPDinputStickerSetShortName &data) {
Unexpected("inputStickerSetShortName in StorageFileLocation().");
});
_volumeId = data.vvolume_id.v;
_localId = data.vlocal_id.v;
_volumeId = data.vvolume_id().v;
_localId = data.vlocal_id().v;
});
}