2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +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;
});
}

View File

@@ -1475,47 +1475,47 @@ EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
result.reserve(entities.size());
for_const (auto &entity, entities) {
switch (entity.type()) {
case mtpc_messageEntityUrl: { auto &d = entity.c_messageEntityUrl(); result.push_back({ EntityType::Url, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityTextUrl: { auto &d = entity.c_messageEntityTextUrl(); result.push_back({ EntityType::CustomUrl, d.voffset.v, d.vlength.v, Clean(qs(d.vurl)) }); } break;
case mtpc_messageEntityEmail: { auto &d = entity.c_messageEntityEmail(); result.push_back({ EntityType::Email, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityHashtag: { auto &d = entity.c_messageEntityHashtag(); result.push_back({ EntityType::Hashtag, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityCashtag: { auto &d = entity.c_messageEntityCashtag(); result.push_back({ EntityType::Cashtag, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityUrl: { auto &d = entity.c_messageEntityUrl(); result.push_back({ EntityType::Url, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityTextUrl: { auto &d = entity.c_messageEntityTextUrl(); result.push_back({ EntityType::CustomUrl, d.voffset().v, d.vlength().v, Clean(qs(d.vurl())) }); } break;
case mtpc_messageEntityEmail: { auto &d = entity.c_messageEntityEmail(); result.push_back({ EntityType::Email, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityHashtag: { auto &d = entity.c_messageEntityHashtag(); result.push_back({ EntityType::Hashtag, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityCashtag: { auto &d = entity.c_messageEntityCashtag(); result.push_back({ EntityType::Cashtag, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityPhone: break; // Skipping phones.
case mtpc_messageEntityMention: { auto &d = entity.c_messageEntityMention(); result.push_back({ EntityType::Mention, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityMention: { auto &d = entity.c_messageEntityMention(); result.push_back({ EntityType::Mention, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityMentionName: {
auto &d = entity.c_messageEntityMentionName();
auto data = [&d] {
if (auto user = Auth().data().userLoaded(d.vuser_id.v)) {
if (auto user = Auth().data().userLoaded(d.vuser_id().v)) {
return MentionNameDataFromFields({
d.vuser_id.v,
d.vuser_id().v,
user->accessHash() });
}
return MentionNameDataFromFields(d.vuser_id.v);
return MentionNameDataFromFields(d.vuser_id().v);
};
result.push_back({ EntityType::MentionName, d.voffset.v, d.vlength.v, data() });
result.push_back({ EntityType::MentionName, d.voffset().v, d.vlength().v, data() });
} break;
case mtpc_inputMessageEntityMentionName: {
auto &d = entity.c_inputMessageEntityMentionName();
auto data = ([&d]() -> QString {
if (d.vuser_id.type() == mtpc_inputUserSelf) {
if (d.vuser_id().type() == mtpc_inputUserSelf) {
return MentionNameDataFromFields(Auth().userId());
} else if (d.vuser_id.type() == mtpc_inputUser) {
auto &user = d.vuser_id.c_inputUser();
return MentionNameDataFromFields({ user.vuser_id.v, user.vaccess_hash.v });
} else if (d.vuser_id().type() == mtpc_inputUser) {
auto &user = d.vuser_id().c_inputUser();
return MentionNameDataFromFields({ user.vuser_id().v, user.vaccess_hash().v });
}
return QString();
})();
if (!data.isEmpty()) {
result.push_back({ EntityType::MentionName, d.voffset.v, d.vlength.v, data });
result.push_back({ EntityType::MentionName, d.voffset().v, d.vlength().v, data });
}
} break;
case mtpc_messageEntityBotCommand: { auto &d = entity.c_messageEntityBotCommand(); result.push_back({ EntityType::BotCommand, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityBold: { auto &d = entity.c_messageEntityBold(); result.push_back({ EntityType::Bold, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityItalic: { auto &d = entity.c_messageEntityItalic(); result.push_back({ EntityType::Italic, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityUnderline: { auto &d = entity.c_messageEntityUnderline(); result.push_back({ EntityType::Underline, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityStrike: { auto &d = entity.c_messageEntityStrike(); result.push_back({ EntityType::StrikeOut, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityCode: { auto &d = entity.c_messageEntityCode(); result.push_back({ EntityType::Code, d.voffset.v, d.vlength.v }); } break;
case mtpc_messageEntityPre: { auto &d = entity.c_messageEntityPre(); result.push_back({ EntityType::Pre, d.voffset.v, d.vlength.v, Clean(qs(d.vlanguage)) }); } break;
case mtpc_messageEntityBotCommand: { auto &d = entity.c_messageEntityBotCommand(); result.push_back({ EntityType::BotCommand, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityBold: { auto &d = entity.c_messageEntityBold(); result.push_back({ EntityType::Bold, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityItalic: { auto &d = entity.c_messageEntityItalic(); result.push_back({ EntityType::Italic, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityUnderline: { auto &d = entity.c_messageEntityUnderline(); result.push_back({ EntityType::Underline, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityStrike: { auto &d = entity.c_messageEntityStrike(); result.push_back({ EntityType::StrikeOut, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityCode: { auto &d = entity.c_messageEntityCode(); result.push_back({ EntityType::Code, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityPre: { auto &d = entity.c_messageEntityPre(); result.push_back({ EntityType::Pre, d.voffset().v, d.vlength().v, Clean(qs(d.vlanguage())) }); } break;
// #TODO entities
}
}