Make MTPstring and MTPvector value types.

Also move MTPstring implementation to QByteArray.
This commit is contained in:
John Preston 2017-03-10 22:46:28 +03:00
parent 1df955e30a
commit f2465eba73
41 changed files with 268 additions and 307 deletions

View File

@ -175,9 +175,9 @@ void ApiWrap::processFullPeer(PeerData *peer, const MTPUserFull &result) {
} }
void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mtpRequestId req) { void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mtpRequestId req) {
const auto &d(result.c_messages_chatFull()); auto &d = result.c_messages_chatFull();
const auto &vc(d.vchats.c_vector().v); auto &vc = d.vchats.v;
bool badVersion = false; auto badVersion = false;
if (peer->isChat()) { if (peer->isChat()) {
badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version); badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version);
} else if (peer->isChannel()) { } else if (peer->isChannel()) {
@ -192,16 +192,15 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
LOG(("MTP Error: bad type in gotChatFull for chat: %1").arg(d.vfull_chat.type())); LOG(("MTP Error: bad type in gotChatFull for chat: %1").arg(d.vfull_chat.type()));
return; return;
} }
const auto &f(d.vfull_chat.c_chatFull()); auto &f = d.vfull_chat.c_chatFull();
App::feedParticipants(f.vparticipants, false, false); App::feedParticipants(f.vparticipants, false, false);
const auto &v(f.vbot_info.c_vector().v); auto &v = f.vbot_info.v;
for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) { for_const (auto &item, v) {
switch (i->type()) { switch (item.type()) {
case mtpc_botInfo: { case mtpc_botInfo: {
const auto &b(i->c_botInfo()); auto &b = item.c_botInfo();
UserData *user = App::userLoaded(b.vuser_id.v); if (auto user = App::userLoaded(b.vuser_id.v)) {
if (user) { user->setBotInfo(item);
user->setBotInfo(*i);
App::clearPeerUpdated(user); App::clearPeerUpdated(user);
emit fullPeerUpdated(user); emit fullPeerUpdated(user);
} }
@ -267,14 +266,13 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
App::main()->peerUpdated(cfrom); App::main()->peerUpdated(cfrom);
} }
} }
auto &v(f.vbot_info.c_vector().v); auto &v = f.vbot_info.v;
for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) { for_const (auto &item, v) {
switch (i->type()) { switch (item.type()) {
case mtpc_botInfo: { case mtpc_botInfo: {
const auto &b(i->c_botInfo()); auto &b = item.c_botInfo();
UserData *user = App::userLoaded(b.vuser_id.v); if (auto user = App::userLoaded(b.vuser_id.v)) {
if (user) { user->setBotInfo(item);
user->setBotInfo(*i);
App::clearPeerUpdated(user); App::clearPeerUpdated(user);
emit fullPeerUpdated(user); emit fullPeerUpdated(user);
} }
@ -428,7 +426,7 @@ void ApiWrap::gotChat(PeerData *peer, const MTPmessages_Chats &result) {
_peerRequests.remove(peer); _peerRequests.remove(peer);
if (auto chats = Api::getChatsFromMessagesChats(result)) { if (auto chats = Api::getChatsFromMessagesChats(result)) {
auto &v = chats->c_vector().v; auto &v = chats->v;
bool badVersion = false; bool badVersion = false;
if (peer->isChat()) { if (peer->isChat()) {
badVersion = (!v.isEmpty() && v.at(0).type() == mtpc_chat && v.at(0).c_chat().vversion.v < peer->asChat()->version); badVersion = (!v.isEmpty() && v.at(0).type() == mtpc_chat && v.at(0).c_chat().vversion.v < peer->asChat()->version);
@ -501,8 +499,8 @@ void ApiWrap::lastParticipantsDone(ChannelData *peer, const MTPchannels_ChannelP
peer->mgInfo->lastParticipantsStatus = MegagroupInfo::LastParticipantsUpToDate; peer->mgInfo->lastParticipantsStatus = MegagroupInfo::LastParticipantsUpToDate;
} }
const auto &d(result.c_channels_channelParticipants()); auto &d = result.c_channels_channelParticipants();
const auto &v(d.vparticipants.c_vector().v); auto &v = d.vparticipants.v;
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
bool added = false, needBotsInfos = false; bool added = false, needBotsInfos = false;
int32 botStatus = peer->mgInfo->botStatus; int32 botStatus = peer->mgInfo->botStatus;
@ -1050,7 +1048,7 @@ void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result)
it->flags = s.vflags.v | clientFlags; it->flags = s.vflags.v | clientFlags;
it->flags &= ~MTPDstickerSet_ClientFlag::f_not_loaded; it->flags &= ~MTPDstickerSet_ClientFlag::f_not_loaded;
const auto &d_docs(d.vdocuments.c_vector().v); auto &d_docs = d.vdocuments.v;
auto custom = sets.find(Stickers::CustomSetId); auto custom = sets.find(Stickers::CustomSetId);
StickerPack pack; StickerPack pack;
@ -1090,14 +1088,14 @@ void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result)
} else { } else {
it->stickers = pack; it->stickers = pack;
it->emoji.clear(); it->emoji.clear();
auto &v = d.vpacks.c_vector().v; auto &v = d.vpacks.v;
for (auto i = 0, l = v.size(); i != l; ++i) { for (auto i = 0, l = v.size(); i != l; ++i) {
if (v[i].type() != mtpc_stickerPack) continue; if (v[i].type() != mtpc_stickerPack) continue;
auto &pack = v[i].c_stickerPack(); auto &pack = v[i].c_stickerPack();
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) { if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
emoji = emoji->original(); emoji = emoji->original();
auto &stickers = pack.vdocuments.c_vector().v; auto &stickers = pack.vdocuments.v;
StickerPack p; StickerPack p;
p.reserve(stickers.size()); p.reserve(stickers.size());
@ -1227,14 +1225,14 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
auto &d = msgs.c_messages_messages(); auto &d = msgs.c_messages_messages();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
case mtpc_messages_messagesSlice: { case mtpc_messages_messagesSlice: {
auto &d = msgs.c_messages_messagesSlice(); auto &d = msgs.c_messages_messagesSlice();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
@ -1246,7 +1244,7 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
} }
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
} }

View File

@ -571,7 +571,7 @@ namespace {
UserData *feedUsers(const MTPVector<MTPUser> &users) { UserData *feedUsers(const MTPVector<MTPUser> &users) {
UserData *result = nullptr; UserData *result = nullptr;
for_const (auto &user, users.c_vector().v) { for_const (auto &user, users.v) {
if (auto feededUser = feedUser(user)) { if (auto feededUser = feedUser(user)) {
result = feededUser; result = feededUser;
} }
@ -793,7 +793,7 @@ namespace {
PeerData *feedChats(const MTPVector<MTPChat> &chats) { PeerData *feedChats(const MTPVector<MTPChat> &chats) {
PeerData *result = nullptr; PeerData *result = nullptr;
for_const (auto &chat, chats.c_vector().v) { for_const (auto &chat, chats.v) {
if (auto feededChat = feedChat(chat)) { if (auto feededChat = feedChat(chat)) {
result = feededChat; result = feededChat;
} }
@ -817,7 +817,7 @@ namespace {
auto canEdit = chat->canEdit(); auto canEdit = chat->canEdit();
if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result
chat->version = d.vversion.v; chat->version = d.vversion.v;
const auto &v(d.vparticipants.c_vector().v); auto &v = d.vparticipants.v;
chat->count = v.size(); chat->count = v.size();
int32 pversion = chat->participants.isEmpty() ? 1 : (chat->participants.begin().value() + 1); int32 pversion = chat->participants.isEmpty() ? 1 : (chat->participants.begin().value() + 1);
chat->invitedByMe = ChatData::InvitedByMe(); chat->invitedByMe = ChatData::InvitedByMe();
@ -1101,7 +1101,7 @@ namespace {
} }
if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) { if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) {
auto text = qs(m.vmessage); auto text = qs(m.vmessage);
auto entities = m.has_entities() ? entitiesFromMTP(m.ventities.c_vector().v) : EntitiesInText(); auto entities = m.has_entities() ? entitiesFromMTP(m.ventities.v) : EntitiesInText();
existing->setText({ text, entities }); existing->setText({ text, entities });
existing->updateMedia(m.has_media() ? (&m.vmedia) : nullptr); existing->updateMedia(m.has_media() ? (&m.vmedia) : nullptr);
existing->updateReplyMarkup(m.has_reply_markup() ? (&m.vreply_markup) : nullptr); existing->updateReplyMarkup(m.has_reply_markup() ? (&m.vreply_markup) : nullptr);
@ -1192,7 +1192,7 @@ namespace {
} }
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type) { void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type) {
return feedMsgs(msgs.c_vector().v, type); return feedMsgs(msgs.v, type);
} }
ImagePtr image(const MTPPhotoSize &size) { ImagePtr image(const MTPPhotoSize &size) {
@ -1422,19 +1422,19 @@ namespace {
} }
PhotoData *feedPhoto(const MTPDphoto &photo, PhotoData *convert) { PhotoData *feedPhoto(const MTPDphoto &photo, PhotoData *convert) {
const auto &sizes(photo.vsizes.c_vector().v); auto &sizes = photo.vsizes.v;
const MTPPhotoSize *thumb = 0, *medium = 0, *full = 0; const MTPPhotoSize *thumb = 0, *medium = 0, *full = 0;
int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1; int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1;
for (QVector<MTPPhotoSize>::const_iterator i = sizes.cbegin(), e = sizes.cend(); i != e; ++i) { for (QVector<MTPPhotoSize>::const_iterator i = sizes.cbegin(), e = sizes.cend(); i != e; ++i) {
char size = 0; char size = 0;
switch (i->type()) { switch (i->type()) {
case mtpc_photoSize: { case mtpc_photoSize: {
auto &s = i->c_photoSize().vtype.c_string().v; auto &s = i->c_photoSize().vtype.v;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
} break; } break;
case mtpc_photoCachedSize: { case mtpc_photoCachedSize: {
auto &s = i->c_photoCachedSize().vtype.c_string().v; auto &s = i->c_photoCachedSize().vtype.v;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
} break; } break;
} }
@ -1478,7 +1478,7 @@ namespace {
switch (document.type()) { switch (document.type()) {
case mtpc_document: { case mtpc_document: {
auto &d = document.c_document(); auto &d = document.c_document();
return App::documentSet(d.vid.v, 0, d.vaccess_hash.v, d.vversion.v, d.vdate.v, d.vattributes.c_vector().v, qs(d.vmime_type), ImagePtr(thumb, "JPG"), d.vdc_id.v, d.vsize.v, StorageImageLocation()); return App::documentSet(d.vid.v, 0, d.vaccess_hash.v, d.vversion.v, d.vdate.v, d.vattributes.v, qs(d.vmime_type), ImagePtr(thumb, "JPG"), d.vdc_id.v, d.vsize.v, StorageImageLocation());
} break; } break;
case mtpc_documentEmpty: return App::document(document.c_documentEmpty().vid.v); case mtpc_documentEmpty: return App::document(document.c_documentEmpty().vid.v);
} }
@ -1498,7 +1498,7 @@ namespace {
} }
DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert) { DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert) {
return App::documentSet(document.vid.v, convert, document.vaccess_hash.v, document.vversion.v, document.vdate.v, document.vattributes.c_vector().v, qs(document.vmime_type), App::image(document.vthumb), document.vdc_id.v, document.vsize.v, App::imageLocation(document.vthumb)); return App::documentSet(document.vid.v, convert, document.vaccess_hash.v, document.vversion.v, document.vdate.v, document.vattributes.v, qs(document.vmime_type), App::image(document.vthumb), document.vdc_id.v, document.vsize.v, App::imageLocation(document.vthumb));
} }
WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert) { WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert) {

View File

@ -194,7 +194,7 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
auto &d = res.c_contacts_importedContacts(); auto &d = res.c_contacts_importedContacts();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
auto &v = d.vimported.c_vector().v; auto &v = d.vimported.v;
UserData *user = nullptr; UserData *user = nullptr;
if (!v.isEmpty()) { if (!v.isEmpty()) {
const auto &c(v.front().c_importedContact()); const auto &c(v.front().c_importedContact());
@ -352,8 +352,8 @@ void GroupInfoBox::creationDone(const MTPUpdates &updates) {
const QVector<MTPChat> *v = 0; const QVector<MTPChat> *v = 0;
switch (updates.type()) { switch (updates.type()) {
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break; case mtpc_updates: v = &updates.c_updates().vchats.v; break;
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break; case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.v; break;
default: LOG(("API Error: unexpected update cons %1 (GroupInfoBox::creationDone)").arg(updates.type())); break; default: LOG(("API Error: unexpected update cons %1 (GroupInfoBox::creationDone)").arg(updates.type())); break;
} }
@ -1218,7 +1218,7 @@ void RevokePublicLinkBox::paintChat(Painter &p, const ChatRow &row, bool selecte
void RevokePublicLinkBox::getPublicDone(const MTPmessages_Chats &result) { void RevokePublicLinkBox::getPublicDone(const MTPmessages_Chats &result) {
if (auto chats = Api::getChatsFromMessagesChats(result)) { if (auto chats = Api::getChatsFromMessagesChats(result)) {
for_const (auto &chat, chats->c_vector().v) { for_const (auto &chat, chats->v) {
if (auto peer = App::feedChat(chat)) { if (auto peer = App::feedChat(chat)) {
if (!peer->isChannel() || peer->userName().isEmpty()) continue; if (!peer->isChannel() || peer->userName().isEmpty()) continue;

View File

@ -108,12 +108,12 @@ void BackgroundBox::Inner::gotWallpapers(const MTPVector<MTPWallPaper> &result)
auto oldBackground = ImagePtr(qsl(":/gui/art/bg_initial.jpg")); auto oldBackground = ImagePtr(qsl(":/gui/art/bg_initial.jpg"));
wallpapers.push_back(App::WallPaper(Window::Theme::kInitialBackground, oldBackground, oldBackground)); wallpapers.push_back(App::WallPaper(Window::Theme::kInitialBackground, oldBackground, oldBackground));
auto &v = result.c_vector().v; auto &v = result.v;
for_const (auto &w, v) { for_const (auto &w, v) {
switch (w.type()) { switch (w.type()) {
case mtpc_wallPaper: { case mtpc_wallPaper: {
auto &d = w.c_wallPaper(); auto &d = w.c_wallPaper();
auto &sizes = d.vsizes.c_vector().v; auto &sizes = d.vsizes.v;
const MTPPhotoSize *thumb = 0, *full = 0; const MTPPhotoSize *thumb = 0, *full = 0;
int32 thumbLevel = -1, fullLevel = -1; int32 thumbLevel = -1, fullLevel = -1;
for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) { for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) {
@ -121,14 +121,14 @@ void BackgroundBox::Inner::gotWallpapers(const MTPVector<MTPWallPaper> &result)
int32 w = 0, h = 0; int32 w = 0, h = 0;
switch (j->type()) { switch (j->type()) {
case mtpc_photoSize: { case mtpc_photoSize: {
auto &s = j->c_photoSize().vtype.c_string().v; auto &s = j->c_photoSize().vtype.v;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
w = j->c_photoSize().vw.v; w = j->c_photoSize().vw.v;
h = j->c_photoSize().vh.v; h = j->c_photoSize().vh.v;
} break; } break;
case mtpc_photoCachedSize: { case mtpc_photoCachedSize: {
auto &s = j->c_photoCachedSize().vtype.c_string().v; auto &s = j->c_photoCachedSize().vtype.v;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
w = j->c_photoCachedSize().vw.v; w = j->c_photoCachedSize().vw.v;
h = j->c_photoCachedSize().vh.v; h = j->c_photoCachedSize().vh.v;

View File

@ -315,8 +315,8 @@ void ConvertToSupergroupBox::convertDone(const MTPUpdates &updates) {
App::main()->sentUpdatesReceived(updates); App::main()->sentUpdatesReceived(updates);
const QVector<MTPChat> *v = 0; const QVector<MTPChat> *v = 0;
switch (updates.type()) { switch (updates.type()) {
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break; case mtpc_updates: v = &updates.c_updates().vchats.v; break;
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break; case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.v; break;
default: LOG(("API Error: unexpected update cons %1 (ConvertToSupergroupBox::convertDone)").arg(updates.type())); break; default: LOG(("API Error: unexpected update cons %1 (ConvertToSupergroupBox::convertDone)").arg(updates.type())); break;
} }

View File

@ -240,7 +240,7 @@ void ContactsBox::peopleReceived(const MTPcontacts_Found &result, mtpRequestId r
case mtpc_contacts_found: { case mtpc_contacts_found: {
App::feedUsers(result.c_contacts_found().vusers); App::feedUsers(result.c_contacts_found().vusers);
App::feedChats(result.c_contacts_found().vchats); App::feedChats(result.c_contacts_found().vchats);
_inner->peopleReceived(q, result.c_contacts_found().vresults.c_vector().v); _inner->peopleReceived(q, result.c_contacts_found().vresults.v);
} break; } break;
} }
@ -487,8 +487,8 @@ void ContactsBox::creationDone(const MTPUpdates &updates) {
App::main()->sentUpdatesReceived(updates); App::main()->sentUpdatesReceived(updates);
const QVector<MTPChat> *v = 0; const QVector<MTPChat> *v = 0;
switch (updates.type()) { switch (updates.type()) {
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break; case mtpc_updates: v = &updates.c_updates().vchats.v; break;
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break; case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.v; break;
default: LOG(("API Error: unexpected update cons %1 (ContactsBox::creationDone)").arg(updates.type())); break; default: LOG(("API Error: unexpected update cons %1 (ContactsBox::creationDone)").arg(updates.type())); break;
} }

View File

@ -510,8 +510,8 @@ void MembersBox::Inner::membersReceived(const MTPchannels_ChannelParticipants &r
_loadingRequestId = 0; _loadingRequestId = 0;
if (result.type() == mtpc_channels_channelParticipants) { if (result.type() == mtpc_channels_channelParticipants) {
const auto &d(result.c_channels_channelParticipants()); auto &d = result.c_channels_channelParticipants();
const auto &v(d.vparticipants.c_vector().v); auto &v = d.vparticipants.v;
_rows.reserve(v.size()); _rows.reserve(v.size());
_datas.reserve(v.size()); _datas.reserve(v.size());
_dates.reserve(v.size()); _dates.reserve(v.size());

View File

@ -774,7 +774,7 @@ void EditCaptionBox::onSave(bool ctrlShiftEnter) {
flags |= MTPmessages_EditMessage::Flag::f_no_webpage; flags |= MTPmessages_EditMessage::Flag::f_no_webpage;
} }
MTPVector<MTPMessageEntity> sentEntities; MTPVector<MTPMessageEntity> sentEntities;
if (!sentEntities.c_vector().v.isEmpty()) { if (!sentEntities.v.isEmpty()) {
flags |= MTPmessages_EditMessage::Flag::f_entities; flags |= MTPmessages_EditMessage::Flag::f_entities;
} }
auto text = prepareText(_field->getLastText(), true); auto text = prepareText(_field->getLastText(), true);

View File

@ -91,7 +91,7 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
if (result.type() != mtpc_account_authorizations) { if (result.type() != mtpc_account_authorizations) {
return; return;
} }
auto &v = result.c_account_authorizations().vauthorizations.c_vector().v; auto &v = result.c_account_authorizations().vauthorizations.v;
_list.reserve(v.size()); _list.reserve(v.size());
const CountriesByISO2 &countries(countriesByISO2()); const CountriesByISO2 &countries(countriesByISO2());

View File

@ -143,7 +143,7 @@ void ShareBox::peopleReceived(const MTPcontacts_Found &result, mtpRequestId requ
auto &found = result.c_contacts_found(); auto &found = result.c_contacts_found();
App::feedUsers(found.vusers); App::feedUsers(found.vusers);
App::feedChats(found.vchats); App::feedChats(found.vchats);
_inner->peopleReceived(query, found.vresults.c_vector().v); _inner->peopleReceived(query, found.vresults.v);
} break; } break;
} }

View File

@ -171,7 +171,7 @@ void StickersBox::getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedSti
auto addedSet = false; auto addedSet = false;
auto changedSets = false; auto changedSets = false;
auto &v = stickers.vsets.c_vector().v; auto &v = stickers.vsets.v;
for_const (auto &stickerSet, v) { for_const (auto &stickerSet, v) {
const MTPDstickerSet *setData = nullptr; const MTPDstickerSet *setData = nullptr;
switch (stickerSet.type()) { switch (stickerSet.type()) {

View File

@ -126,7 +126,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
setCursor(style::cur_default); setCursor(style::cur_default);
if (set.type() == mtpc_messages_stickerSet) { if (set.type() == mtpc_messages_stickerSet) {
auto &d = set.c_messages_stickerSet(); auto &d = set.c_messages_stickerSet();
auto &v = d.vdocuments.c_vector().v; auto &v = d.vdocuments.v;
_pack.reserve(v.size()); _pack.reserve(v.size());
_packOvers.reserve(v.size()); _packOvers.reserve(v.size());
for (int i = 0, l = v.size(); i < l; ++i) { for (int i = 0, l = v.size(); i < l; ++i) {
@ -136,13 +136,13 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
_pack.push_back(doc); _pack.push_back(doc);
_packOvers.push_back(Animation()); _packOvers.push_back(Animation());
} }
auto &packs = d.vpacks.c_vector().v; auto &packs = d.vpacks.v;
for (auto i = 0, l = packs.size(); i != l; ++i) { for (auto i = 0, l = packs.size(); i != l; ++i) {
if (packs.at(i).type() != mtpc_stickerPack) continue; if (packs.at(i).type() != mtpc_stickerPack) continue;
auto &pack = packs.at(i).c_stickerPack(); auto &pack = packs.at(i).c_stickerPack();
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) { if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
emoji = emoji->original(); emoji = emoji->original();
auto &stickers = pack.vdocuments.c_vector().v; auto &stickers = pack.vdocuments.v;
StickerPack p; StickerPack p;
p.reserve(stickers.size()); p.reserve(stickers.size());

View File

@ -40,7 +40,7 @@ Draft::Draft(const Ui::FlatTextarea *field, MsgId msgId, bool previewCancelled,
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
auto history = App::history(peerId); auto history = App::history(peerId);
auto text = qs(draft.vmessage); auto text = qs(draft.vmessage);
auto entities = draft.has_entities() ? entitiesFromMTP(draft.ventities.c_vector().v) : EntitiesInText(); auto entities = draft.has_entities() ? entitiesFromMTP(draft.ventities.v) : EntitiesInText();
TextWithTags textWithTags = { textApplyEntities(text, entities), textTagsFromEntities(entities) }; TextWithTags textWithTags = { textApplyEntities(text, entities), textTagsFromEntities(entities) };
MsgId replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : 0; MsgId replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : 0;
auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage()); auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage());

View File

@ -2477,16 +2477,16 @@ void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpReque
auto &data = dialogs.c_messages_dialogs(); auto &data = dialogs.c_messages_dialogs();
App::feedUsers(data.vusers); App::feedUsers(data.vusers);
App::feedChats(data.vchats); App::feedChats(data.vchats);
messagesList = &data.vmessages.c_vector().v; messagesList = &data.vmessages.v;
dialogsList = &data.vdialogs.c_vector().v; dialogsList = &data.vdialogs.v;
_dialogsFull = true; _dialogsFull = true;
} break; } break;
case mtpc_messages_dialogsSlice: { case mtpc_messages_dialogsSlice: {
auto &data = dialogs.c_messages_dialogsSlice(); auto &data = dialogs.c_messages_dialogsSlice();
App::feedUsers(data.vusers); App::feedUsers(data.vusers);
App::feedChats(data.vchats); App::feedChats(data.vchats);
messagesList = &data.vmessages.c_vector().v; messagesList = &data.vmessages.v;
dialogsList = &data.vdialogs.c_vector().v; dialogsList = &data.vdialogs.v;
} break; } break;
} }
@ -2557,7 +2557,7 @@ void DialogsWidget::pinnedDialogsReceived(const MTPmessages_PeerDialogs &dialogs
auto &dialogsData = dialogs.c_messages_peerDialogs(); auto &dialogsData = dialogs.c_messages_peerDialogs();
App::feedUsers(dialogsData.vusers); App::feedUsers(dialogsData.vusers);
App::feedChats(dialogsData.vchats); App::feedChats(dialogsData.vchats);
auto &list = dialogsData.vdialogs.c_vector().v; auto &list = dialogsData.vdialogs.v;
for (auto i = list.size(); i > 0;) { for (auto i = list.size(); i > 0;) {
auto &dialog = list[--i]; auto &dialog = list[--i];
if (dialog.type() != mtpc_dialog) { if (dialog.type() != mtpc_dialog) {
@ -2741,7 +2741,7 @@ void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &result) {
if (result.type() == mtpc_contacts_contacts) { if (result.type() == mtpc_contacts_contacts) {
auto &d = result.c_contacts_contacts(); auto &d = result.c_contacts_contacts();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
_inner->contactsReceived(d.vcontacts.c_vector().v); _inner->contactsReceived(d.vcontacts.v);
} }
if (App::main()) App::main()->contactsReceived(); if (App::main()) App::main()->contactsReceived();
} }
@ -2755,7 +2755,7 @@ bool DialogsWidget::contactsFailed(const RPCError &error) {
void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessages_Messages &result, mtpRequestId req) { void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessages_Messages &result, mtpRequestId req) {
if (_inner->state() == DialogsInner::FilteredState || _inner->state() == DialogsInner::SearchedState) { if (_inner->state() == DialogsInner::FilteredState || _inner->state() == DialogsInner::SearchedState) {
if (type == DialogsSearchFromStart || type == DialogsSearchPeerFromStart) { if (type == DialogsSearchFromStart || type == DialogsSearchPeerFromStart) {
SearchQueries::iterator i = _searchQueries.find(req); auto i = _searchQueries.find(req);
if (i != _searchQueries.cend()) { if (i != _searchQueries.cend()) {
_searchCache[i.value()] = result; _searchCache[i.value()] = result;
_searchQueries.erase(i); _searchQueries.erase(i);
@ -2766,10 +2766,10 @@ void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessa
if (_searchRequest == req) { if (_searchRequest == req) {
switch (result.type()) { switch (result.type()) {
case mtpc_messages_messages: { case mtpc_messages_messages: {
auto &d(result.c_messages_messages()); auto &d = result.c_messages_messages();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
auto &msgs(d.vmessages.c_vector().v); auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, msgs.size())) { if (!_inner->searchReceived(msgs, type, msgs.size())) {
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) { if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
_searchFullMigrated = true; _searchFullMigrated = true;
@ -2780,10 +2780,10 @@ void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessa
} break; } break;
case mtpc_messages_messagesSlice: { case mtpc_messages_messagesSlice: {
auto &d(result.c_messages_messagesSlice()); auto &d = result.c_messages_messagesSlice();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
auto &msgs(d.vmessages.c_vector().v); auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, d.vcount.v)) { if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) { if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
_searchFullMigrated = true; _searchFullMigrated = true;
@ -2794,7 +2794,7 @@ void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessa
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
auto &d(result.c_messages_channelMessages()); auto &d = result.c_messages_channelMessages();
if (_searchInPeer && _searchInPeer->isChannel()) { if (_searchInPeer && _searchInPeer->isChannel()) {
_searchInPeer->asChannel()->ptsReceived(d.vpts.v); _searchInPeer->asChannel()->ptsReceived(d.vpts.v);
} else { } else {
@ -2802,7 +2802,7 @@ void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessa
} }
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
auto &msgs(d.vmessages.c_vector().v); auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, d.vcount.v)) { if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) { if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
_searchFullMigrated = true; _searchFullMigrated = true;
@ -2835,7 +2835,7 @@ void DialogsWidget::peerSearchReceived(const MTPcontacts_Found &result, mtpReque
auto &d = result.c_contacts_found(); auto &d = result.c_contacts_found();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
_inner->peerSearchReceived(q, d.vresults.c_vector().v); _inner->peerSearchReceived(q, d.vresults.v);
} break; } break;
} }

View File

@ -840,7 +840,7 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction,
case mtpc_messageActionChatAddUser: { case mtpc_messageActionChatAddUser: {
auto &d = action.c_messageActionChatAddUser(); auto &d = action.c_messageActionChatAddUser();
if (peer->isMegagroup()) { if (peer->isMegagroup()) {
auto &v = d.vusers.c_vector().v; auto &v = d.vusers.v;
for (auto i = 0, l = v.size(); i != l; ++i) { for (auto i = 0, l = v.size(); i != l; ++i) {
if (auto user = App::userLoaded(peerFromUser(v[i]))) { if (auto user = App::userLoaded(peerFromUser(v[i]))) {
if (peer->asChannel()->mgInfo->lastParticipants.indexOf(user) < 0) { if (peer->asChannel()->mgInfo->lastParticipants.indexOf(user) < 0) {
@ -920,13 +920,14 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction,
} break; } break;
case mtpc_messageActionChatEditPhoto: { case mtpc_messageActionChatEditPhoto: {
const auto &d(action.c_messageActionChatEditPhoto()); auto &d = action.c_messageActionChatEditPhoto();
if (d.vphoto.type() == mtpc_photo) { if (d.vphoto.type() == mtpc_photo) {
const auto &sizes(d.vphoto.c_photo().vsizes.c_vector().v); auto &sizes = d.vphoto.c_photo().vsizes.v;
if (!sizes.isEmpty()) { if (!sizes.isEmpty()) {
PhotoData *photo = App::feedPhoto(d.vphoto.c_photo()); auto photo = App::feedPhoto(d.vphoto.c_photo());
if (photo) photo->peer = peer; if (photo) photo->peer = peer;
const auto &smallSize(sizes.front()), &bigSize(sizes.back()); auto &smallSize = sizes.front();
auto &bigSize = sizes.back();
const MTPFileLocation *smallLoc = 0, *bigLoc = 0; const MTPFileLocation *smallLoc = 0, *bigLoc = 0;
switch (smallSize.type()) { switch (smallSize.type()) {
case mtpc_photoSize: smallLoc = &smallSize.c_photoSize().vlocation; break; case mtpc_photoSize: smallLoc = &smallSize.c_photoSize().vlocation; break;
@ -2121,7 +2122,7 @@ void History::overviewSliceDone(int32 overviewIndex, const MTPmessages_Messages
auto &d(result.c_messages_messages()); auto &d(result.c_messages_messages());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
overviewCountData[overviewIndex] = 0; overviewCountData[overviewIndex] = 0;
} break; } break;
@ -2130,7 +2131,7 @@ void History::overviewSliceDone(int32 overviewIndex, const MTPmessages_Messages
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
overviewCountData[overviewIndex] = d.vcount.v; overviewCountData[overviewIndex] = d.vcount.v;
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
@ -2143,7 +2144,7 @@ void History::overviewSliceDone(int32 overviewIndex, const MTPmessages_Messages
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
overviewCountData[overviewIndex] = d.vcount.v; overviewCountData[overviewIndex] = d.vcount.v;
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
default: return; default: return;

View File

@ -401,7 +401,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector<MTPKeyboardBu
switch (row.type()) { switch (row.type()) {
case mtpc_keyboardButtonRow: { case mtpc_keyboardButtonRow: {
auto &r = row.c_keyboardButtonRow(); auto &r = row.c_keyboardButtonRow();
auto &b = r.vbuttons.c_vector().v; auto &b = r.vbuttons.v;
if (!b.isEmpty()) { if (!b.isEmpty()) {
ButtonRow buttonRow; ButtonRow buttonRow;
buttonRow.reserve(b.size()); buttonRow.reserve(b.size());
@ -457,14 +457,14 @@ void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
auto &d = markup.c_replyKeyboardMarkup(); auto &d = markup.c_replyKeyboardMarkup();
flags = d.vflags.v; flags = d.vflags.v;
createFromButtonRows(d.vrows.c_vector().v); createFromButtonRows(d.vrows.v);
} break; } break;
case mtpc_replyInlineMarkup: { case mtpc_replyInlineMarkup: {
auto &d = markup.c_replyInlineMarkup(); auto &d = markup.c_replyInlineMarkup();
flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline; flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline;
createFromButtonRows(d.vrows.c_vector().v); createFromButtonRows(d.vrows.v);
} break; } break;
case mtpc_replyKeyboardHide: { case mtpc_replyKeyboardHide: {

View File

@ -510,7 +510,7 @@ void HistoryPhoto::updateSentMedia(const MTPMessageMedia &media) {
App::feedPhoto(photo, _data); App::feedPhoto(photo, _data);
if (photo.type() == mtpc_photo) { if (photo.type() == mtpc_photo) {
auto &sizes = photo.c_photo().vsizes.c_vector().v; auto &sizes = photo.c_photo().vsizes.v;
int32 max = 0; int32 max = 0;
const MTPDfileLocation *maxLocation = 0; const MTPDfileLocation *maxLocation = 0;
for (int32 i = 0, l = sizes.size(); i < l; ++i) { for (int32 i = 0, l = sizes.size(); i < l; ++i) {
@ -518,13 +518,13 @@ void HistoryPhoto::updateSentMedia(const MTPMessageMedia &media) {
const MTPFileLocation *loc = 0; const MTPFileLocation *loc = 0;
switch (sizes.at(i).type()) { switch (sizes.at(i).type()) {
case mtpc_photoSize: { case mtpc_photoSize: {
auto &s = sizes.at(i).c_photoSize().vtype.c_string().v; auto &s = sizes.at(i).c_photoSize().vtype.v;
loc = &sizes.at(i).c_photoSize().vlocation; loc = &sizes.at(i).c_photoSize().vlocation;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
} break; } break;
case mtpc_photoCachedSize: { case mtpc_photoCachedSize: {
auto &s = sizes.at(i).c_photoCachedSize().vtype.c_string().v; auto &s = sizes.at(i).c_photoCachedSize().vtype.v;
loc = &sizes.at(i).c_photoCachedSize().vlocation; loc = &sizes.at(i).c_photoCachedSize().vlocation;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
} break; } break;

View File

@ -415,7 +415,7 @@ HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg)
TextWithEntities textWithEntities = { TextWithEntities textWithEntities = {
textClean(qs(msg.vmessage)), textClean(qs(msg.vmessage)),
msg.has_entities() ? entitiesFromMTP(msg.ventities.c_vector().v) : EntitiesInText(), msg.has_entities() ? entitiesFromMTP(msg.ventities.v) : EntitiesInText(),
}; };
setText(textWithEntities); setText(textWithEntities);
} }
@ -895,7 +895,7 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
TextWithEntities textWithEntities = { qs(message.vmessage), EntitiesInText() }; TextWithEntities textWithEntities = { qs(message.vmessage), EntitiesInText() };
if (message.has_entities()) { if (message.has_entities()) {
textWithEntities.entities = entitiesFromMTP(message.ventities.c_vector().v); textWithEntities.entities = entitiesFromMTP(message.ventities.v);
} }
setText(textWithEntities); setText(textWithEntities);
setMedia(message.has_media() ? (&message.vmedia) : nullptr); setMedia(message.has_media() ? (&message.vmedia) : nullptr);
@ -1850,7 +1850,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
switch (action.type()) { switch (action.type()) {
case mtpc_messageActionChatAddUser: { case mtpc_messageActionChatAddUser: {
auto &d = action.c_messageActionChatAddUser(); auto &d = action.c_messageActionChatAddUser();
auto &v = d.vusers.c_vector().v; auto &v = d.vusers.v;
bool foundSelf = false; bool foundSelf = false;
for (int i = 0, l = v.size(); i < l; ++i) { for (int i = 0, l = v.size(); i < l; ++i) {
if (v.at(i).v == AuthSession::CurrentUserId()) { if (v.at(i).v == AuthSession::CurrentUserId()) {

View File

@ -3835,9 +3835,9 @@ void HistoryWidget::stickersGot(const MTPmessages_AllStickers &stickers) {
_stickersUpdateRequest = 0; _stickersUpdateRequest = 0;
if (stickers.type() != mtpc_messages_allStickers) return; if (stickers.type() != mtpc_messages_allStickers) return;
const auto &d(stickers.c_messages_allStickers()); auto &d = stickers.c_messages_allStickers();
const auto &d_sets(d.vsets.c_vector().v); auto &d_sets = d.vsets.v;
auto &setsOrder = Global::RefStickerSetsOrder(); auto &setsOrder = Global::RefStickerSetsOrder();
setsOrder.clear(); setsOrder.clear();
@ -3921,7 +3921,7 @@ void HistoryWidget::recentStickersGot(const MTPmessages_RecentStickers &stickers
auto &sets = Global::RefStickerSets(); auto &sets = Global::RefStickerSets();
auto it = sets.find(Stickers::CloudRecentSetId); auto it = sets.find(Stickers::CloudRecentSetId);
auto &d_docs = d.vstickers.c_vector().v; auto &d_docs = d.vstickers.v;
if (d_docs.isEmpty()) { if (d_docs.isEmpty()) {
if (it != sets.cend()) { if (it != sets.cend()) {
sets.erase(it); sets.erase(it);
@ -4005,11 +4005,11 @@ void HistoryWidget::featuredStickersGot(const MTPmessages_FeaturedStickers &stic
auto &d = stickers.c_messages_featuredStickers(); auto &d = stickers.c_messages_featuredStickers();
OrderedSet<uint64> unread; OrderedSet<uint64> unread;
for_const (auto &unreadSetId, d.vunread.c_vector().v) { for_const (auto &unreadSetId, d.vunread.v) {
unread.insert(unreadSetId.v); unread.insert(unreadSetId.v);
} }
auto &d_sets = d.vsets.c_vector().v; auto &d_sets = d.vsets.v;
auto &setsOrder = Global::RefFeaturedStickerSetsOrder(); auto &setsOrder = Global::RefFeaturedStickerSetsOrder();
setsOrder.clear(); setsOrder.clear();
@ -4122,9 +4122,9 @@ void HistoryWidget::savedGifsGot(const MTPmessages_SavedGifs &gifs) {
_savedGifsUpdateRequest = 0; _savedGifsUpdateRequest = 0;
if (gifs.type() != mtpc_messages_savedGifs) return; if (gifs.type() != mtpc_messages_savedGifs) return;
const auto &d(gifs.c_messages_savedGifs()); auto &d = gifs.c_messages_savedGifs();
const auto &d_gifs(d.vgifs.c_vector().v); auto &d_gifs = d.vgifs.v;
SavedGifs &saved(cRefSavedGifs()); SavedGifs &saved(cRefSavedGifs());
saved.clear(); saved.clear();
@ -4965,14 +4965,14 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
auto &d(messages.c_messages_messages()); auto &d(messages.c_messages_messages());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
histList = &d.vmessages.c_vector().v; histList = &d.vmessages.v;
count = histList->size(); count = histList->size();
} break; } break;
case mtpc_messages_messagesSlice: { case mtpc_messages_messagesSlice: {
auto &d(messages.c_messages_messagesSlice()); auto &d(messages.c_messages_messagesSlice());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
histList = &d.vmessages.c_vector().v; histList = &d.vmessages.v;
count = d.vcount.v; count = d.vcount.v;
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
@ -4984,7 +4984,7 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
} }
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
histList = &d.vmessages.c_vector().v; histList = &d.vmessages.v;
count = d.vcount.v; count = d.vcount.v;
} break; } break;
} }
@ -5321,8 +5321,9 @@ void HistoryWidget::saveEditMsg() {
if (webPageId == CancelledWebPageId) { if (webPageId == CancelledWebPageId) {
sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage; sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage;
} }
MTPVector<MTPMessageEntity> localEntities = linksToMTP(sendingEntities), sentEntities = linksToMTP(sendingEntities, true); auto localEntities = linksToMTP(sendingEntities);
if (!sentEntities.c_vector().v.isEmpty()) { auto sentEntities = linksToMTP(sendingEntities, true);
if (!sentEntities.v.isEmpty()) {
sendFlags |= MTPmessages_EditMessage::Flag::f_entities; sendFlags |= MTPmessages_EditMessage::Flag::f_entities;
} }
_saveEditMsgRequestId = MTP::send(MTPmessages_EditMessage(MTP_flags(sendFlags), _history->peer->input, MTP_int(_editMsgId), MTP_string(sendingText), MTPnullMarkup, sentEntities), rpcDone(&HistoryWidget::saveEditMsgDone, _history), rpcFail(&HistoryWidget::saveEditMsgFail, _history)); _saveEditMsgRequestId = MTP::send(MTPmessages_EditMessage(MTP_flags(sendFlags), _history->peer->input, MTP_int(_editMsgId), MTP_string(sendingText), MTPnullMarkup, sentEntities), rpcDone(&HistoryWidget::saveEditMsgDone, _history), rpcFail(&HistoryWidget::saveEditMsgFail, _history));

View File

@ -136,7 +136,7 @@ std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult
case mtpc_botInlineMessageText: { case mtpc_botInlineMessageText: {
auto &r = message->c_botInlineMessageText(); auto &r = message->c_botInlineMessageText();
EntitiesInText entities = r.has_entities() ? entitiesFromMTP(r.ventities.c_vector().v) : EntitiesInText(); auto entities = r.has_entities() ? entitiesFromMTP(r.ventities.v) : EntitiesInText();
result->sendData.reset(new internal::SendText(qs(r.vmessage), entities, r.is_no_webpage())); result->sendData.reset(new internal::SendText(qs(r.vmessage), entities, r.is_no_webpage()));
if (result->_type == Type::Photo) { if (result->_type == Type::Photo) {
result->createPhoto(); result->createPhoto();

View File

@ -37,8 +37,8 @@ QString SendData::getLayoutDescription(const Result *owner) const {
void SendDataCommon::addToHistory(const Result *owner, History *history, void SendDataCommon::addToHistory(const Result *owner, History *history,
MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate,
UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const { UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const {
SentMTPMessageFields fields = getSentMessageFields(); auto fields = getSentMessageFields();
if (!fields.entities.c_vector().v.isEmpty()) { if (!fields.entities.v.isEmpty()) {
flags |= MTPDmessage::Flag::f_entities; flags |= MTPDmessage::Flag::f_entities;
} }
history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(msgId), MTP_int(fromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTP_int(viaBotId), MTP_int(replyToId), mtpDate, fields.text, fields.media, markup, fields.entities, MTP_int(1), MTPint()), NewMessageUnread); history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(msgId), MTP_int(fromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTP_int(viaBotId), MTP_int(replyToId), mtpDate, fields.text, fields.media, markup, fields.entities, MTP_int(1), MTPint()), NewMessageUnread);

View File

@ -180,7 +180,7 @@ void CodeWidget::finished() {
void CodeWidget::cancelled() { void CodeWidget::cancelled() {
MTP::cancel(base::take(_sentRequest)); MTP::cancel(base::take(_sentRequest));
MTP::cancel(base::take(_callRequestId)); MTP::cancel(base::take(_callRequestId));
MTP::send(MTPauth_CancelCode(MTP_string(getData()->phone), MTP_string(getData()->phoneHash))); MTP::send(MTPauth_CancelCode(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash)));
} }
void CodeWidget::stopCheck() { void CodeWidget::stopCheck() {
@ -263,7 +263,7 @@ void CodeWidget::onSendCall() {
if (--_callTimeout <= 0) { if (--_callTimeout <= 0) {
_callStatus = Widget::Data::CallStatus::Calling; _callStatus = Widget::Data::CallStatus::Calling;
_callTimer->stop(); _callTimer->stop();
_callRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_string(getData()->phoneHash)), rpcDone(&CodeWidget::callDone)); _callRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash)), rpcDone(&CodeWidget::callDone));
} else { } else {
getData()->callStatus = _callStatus; getData()->callStatus = _callStatus;
getData()->callTimeout = _callTimeout; getData()->callTimeout = _callTimeout;
@ -314,12 +314,12 @@ void CodeWidget::submit() {
getData()->pwdSalt = QByteArray(); getData()->pwdSalt = QByteArray();
getData()->hasRecovery = false; getData()->hasRecovery = false;
getData()->pwdHint = QString(); getData()->pwdHint = QString();
_sentRequest = MTP::send(MTPauth_SignIn(MTP_string(getData()->phone), MTP_string(getData()->phoneHash), MTP_string(_sentCode)), rpcDone(&CodeWidget::codeSubmitDone), rpcFail(&CodeWidget::codeSubmitFail)); _sentRequest = MTP::send(MTPauth_SignIn(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash), MTP_string(_sentCode)), rpcDone(&CodeWidget::codeSubmitDone), rpcFail(&CodeWidget::codeSubmitFail));
} }
void CodeWidget::onNoTelegramCode() { void CodeWidget::onNoTelegramCode() {
if (_noTelegramCodeRequestId) return; if (_noTelegramCodeRequestId) return;
_noTelegramCodeRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_string(getData()->phoneHash)), rpcDone(&CodeWidget::noTelegramCodeDone), rpcFail(&CodeWidget::noTelegramCodeFail)); _noTelegramCodeRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash)), rpcDone(&CodeWidget::noTelegramCodeDone), rpcFail(&CodeWidget::noTelegramCodeFail));
} }
void CodeWidget::noTelegramCodeDone(const MTPauth_SentCode &result) { void CodeWidget::noTelegramCodeDone(const MTPauth_SentCode &result) {

View File

@ -180,7 +180,7 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) {
auto &d = result.c_auth_sentCode(); auto &d = result.c_auth_sentCode();
fillSentCodeData(d.vtype); fillSentCodeData(d.vtype);
getData()->phone = _sentPhone; getData()->phone = _sentPhone;
getData()->phoneHash = d.vphone_code_hash.c_string().v.c_str(); getData()->phoneHash = qba(d.vphone_code_hash);
getData()->phoneIsRegistered = d.is_phone_registered(); getData()->phoneIsRegistered = d.is_phone_registered();
if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) { if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) {
getData()->callStatus = Widget::Data::CallStatus::Waiting; getData()->callStatus = Widget::Data::CallStatus::Waiting;

View File

@ -223,7 +223,7 @@ void SignupWidget::submit() {
_firstName = _first->getLastText().trimmed(); _firstName = _first->getLastText().trimmed();
_lastName = _last->getLastText().trimmed(); _lastName = _last->getLastText().trimmed();
_sentRequest = MTP::send(MTPauth_SignUp(MTP_string(getData()->phone), MTP_string(getData()->phoneHash), MTP_string(getData()->code), MTP_string(_firstName), MTP_string(_lastName)), rpcDone(&SignupWidget::nameSubmitDone), rpcFail(&SignupWidget::nameSubmitFail)); _sentRequest = MTP::send(MTPauth_SignUp(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash), MTP_string(getData()->code), MTP_string(_firstName), MTP_string(_lastName)), rpcDone(&SignupWidget::nameSubmitDone), rpcFail(&SignupWidget::nameSubmitFail));
} }
QString SignupWidget::nextButtonText() const { QString SignupWidget::nextButtonText() const {

View File

@ -263,7 +263,7 @@ bool Widget::resetFail(const RPCError &error) {
void Widget::gotNearestDC(const MTPNearestDc &result) { void Widget::gotNearestDC(const MTPNearestDc &result) {
auto &nearest = result.c_nearestDc(); auto &nearest = result.c_nearestDc();
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(nearest.vcountry.c_string().v.c_str()).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v)); DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(qs(nearest.vcountry)).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v));
Messenger::Instance().suggestMainDcId(nearest.vnearest_dc.v); Messenger::Instance().suggestMainDcId(nearest.vnearest_dc.v);
auto nearestCountry = qs(nearest.vcountry); auto nearestCountry = qs(nearest.vcountry);
if (getData()->country != nearestCountry) { if (getData()->country != nearestCountry) {

View File

@ -63,7 +63,7 @@ public:
struct Data { struct Data {
QString country; QString country;
QString phone; QString phone;
QString phoneHash; QByteArray phoneHash;
bool phoneIsRegistered = false; bool phoneIsRegistered = false;
enum class CallStatus { enum class CallStatus {

View File

@ -1015,14 +1015,14 @@ void MainWidget::checkedHistory(PeerData *peer, const MTPmessages_Messages &resu
auto &d(result.c_messages_messages()); auto &d(result.c_messages_messages());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
case mtpc_messages_messagesSlice: { case mtpc_messages_messagesSlice: {
auto &d(result.c_messages_messagesSlice()); auto &d(result.c_messages_messagesSlice());
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
@ -1034,19 +1034,19 @@ void MainWidget::checkedHistory(PeerData *peer, const MTPmessages_Messages &resu
} }
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
v = &d.vmessages.c_vector().v; v = &d.vmessages.v;
} break; } break;
} }
if (!v) return; if (!v) return;
if (v->isEmpty()) { if (v->isEmpty()) {
if (peer->isChat() && !peer->asChat()->haveLeft()) { if (peer->isChat() && !peer->asChat()->haveLeft()) {
History *h = App::historyLoaded(peer->id); auto h = App::historyLoaded(peer->id);
if (h) Local::addSavedPeer(peer, h->lastMsgDate); if (h) Local::addSavedPeer(peer, h->lastMsgDate);
} else if (peer->isChannel()) { } else if (peer->isChannel()) {
if (peer->asChannel()->inviter > 0 && peer->asChannel()->amIn()) { if (peer->asChannel()->inviter > 0 && peer->asChannel()->amIn()) {
if (UserData *from = App::userLoaded(peer->asChannel()->inviter)) { if (auto from = App::userLoaded(peer->asChannel()->inviter)) {
History *h = App::history(peer->id); auto h = App::history(peer->id);
h->clear(true); h->clear(true);
h->addNewerSlice(QVector<MTPMessage>()); h->addNewerSlice(QVector<MTPMessage>());
h->asChannelHistory()->insertJoinedMessage(true); h->asChannelHistory()->insertJoinedMessage(true);
@ -1244,8 +1244,9 @@ void MainWidget::sendMessage(const MessageToSend &message) {
if (silentPost) { if (silentPost) {
sendFlags |= MTPmessages_SendMessage::Flag::f_silent; sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
} }
MTPVector<MTPMessageEntity> localEntities = linksToMTP(sendingEntities), sentEntities = linksToMTP(sendingEntities, true); auto localEntities = linksToMTP(sendingEntities);
if (!sentEntities.c_vector().v.isEmpty()) { auto sentEntities = linksToMTP(sendingEntities, true);
if (!sentEntities.v.isEmpty()) {
sendFlags |= MTPmessages_SendMessage::Flag::f_entities; sendFlags |= MTPmessages_SendMessage::Flag::f_entities;
} }
if (message.clearDraft) { if (message.clearDraft) {
@ -2123,7 +2124,7 @@ void MainWidget::onViewsIncrement() {
} }
void MainWidget::viewsIncrementDone(QVector<MTPint> ids, const MTPVector<MTPint> &result, mtpRequestId req) { void MainWidget::viewsIncrementDone(QVector<MTPint> ids, const MTPVector<MTPint> &result, mtpRequestId req) {
const auto &v(result.c_vector().v); auto &v = result.v;
if (ids.size() == v.size()) { if (ids.size() == v.size()) {
for (ViewsIncrementRequests::iterator i = _viewsIncrementRequests.begin(); i != _viewsIncrementRequests.cend(); ++i) { for (ViewsIncrementRequests::iterator i = _viewsIncrementRequests.begin(); i != _viewsIncrementRequests.cend(); ++i) {
if (i.value() == req) { if (i.value() == req) {
@ -2820,7 +2821,7 @@ void MainWidget::jumpToDate(PeerData *peer, const QDate &date) {
auto handleMessages = [](auto &messages) { auto handleMessages = [](auto &messages) {
App::feedUsers(messages.vusers); App::feedUsers(messages.vusers);
App::feedChats(messages.vchats); App::feedChats(messages.vchats);
return &messages.vmessages.c_vector().v; return &messages.vmessages.v;
}; };
switch (result.type()) { switch (result.type()) {
case mtpc_messages_messages: return handleMessages(result.c_messages_messages()); case mtpc_messages_messages: return handleMessages(result.c_messages_messages());
@ -3359,18 +3360,16 @@ void MainWidget::onUpdateNotifySettings() {
} }
void MainWidget::feedUpdateVector(const MTPVector<MTPUpdate> &updates, bool skipMessageIds) { void MainWidget::feedUpdateVector(const MTPVector<MTPUpdate> &updates, bool skipMessageIds) {
const auto &v(updates.c_vector().v); for_const (auto &update, updates.v) {
for (QVector<MTPUpdate>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) { if (skipMessageIds && update.type() == mtpc_updateMessageID) continue;
if (skipMessageIds && i->type() == mtpc_updateMessageID) continue; feedUpdate(update);
feedUpdate(*i);
} }
} }
void MainWidget::feedMessageIds(const MTPVector<MTPUpdate> &updates) { void MainWidget::feedMessageIds(const MTPVector<MTPUpdate> &updates) {
const auto &v(updates.c_vector().v); for_const (auto &update, updates.v) {
for (QVector<MTPUpdate>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) { if (update.type() == mtpc_updateMessageID) {
if (i->type() == mtpc_updateMessageID) { feedUpdate(update);
feedUpdate(*i);
} }
} }
} }
@ -3463,7 +3462,7 @@ void MainWidget::gotChannelDifference(ChannelData *channel, const MTPupdates_Cha
// feed messages and groups, copy from App::feedMsgs // feed messages and groups, copy from App::feedMsgs
auto h = App::history(channel->id); auto h = App::history(channel->id);
auto &vmsgs = d.vnew_messages.c_vector().v; auto &vmsgs = d.vnew_messages.v;
QMap<uint64, int> msgsIds; QMap<uint64, int> msgsIds;
for (int i = 0, l = vmsgs.size(); i < l; ++i) { for (int i = 0, l = vmsgs.size(); i < l; ++i) {
auto &msg = vmsgs[i]; auto &msg = vmsgs[i];
@ -4054,7 +4053,7 @@ void MainWidget::inviteCheckDone(QString hash, const MTPChatInvite &invite) {
QVector<UserData*> participants; QVector<UserData*> participants;
if (d.has_participants()) { if (d.has_participants()) {
auto &v = d.vparticipants.c_vector().v; auto &v = d.vparticipants.v;
participants.reserve(v.size()); participants.reserve(v.size());
for_const (auto &user, v) { for_const (auto &user, v) {
if (auto feededUser = App::feedUser(user)) { if (auto feededUser = App::feedUser(user)) {
@ -4096,8 +4095,8 @@ void MainWidget::inviteImportDone(const MTPUpdates &updates) {
Ui::hideLayer(); Ui::hideLayer();
const QVector<MTPChat> *v = 0; const QVector<MTPChat> *v = 0;
switch (updates.type()) { switch (updates.type()) {
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break; case mtpc_updates: v = &updates.c_updates().vchats.v; break;
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break; case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.v; break;
default: LOG(("API Error: unexpected update cons %1 (MainWidget::inviteImportDone)").arg(updates.type())); break; default: LOG(("API Error: unexpected update cons %1 (MainWidget::inviteImportDone)").arg(updates.type())); break;
} }
if (v && !v->isEmpty()) { if (v && !v->isEmpty()) {
@ -4122,7 +4121,7 @@ bool MainWidget::inviteImportFail(const RPCError &error) {
} }
void MainWidget::startWithSelf(const MTPVector<MTPUser> &users) { void MainWidget::startWithSelf(const MTPVector<MTPUser> &users) {
auto &v = users.c_vector().v; auto &v = users.v;
if (v.isEmpty()) { if (v.isEmpty()) {
LOG(("Auth Error: self user not received.")); LOG(("Auth Error: self user not received."));
return App::logOutDelayed(); return App::logOutDelayed();
@ -4174,11 +4173,12 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti
} }
if (setTo == UnknownNotifySettings) break; if (setTo == UnknownNotifySettings) break;
changed = (setTo->flags != d.vflags.v) || (setTo->mute != d.vmute_until.v) || (setTo->sound != d.vsound.c_string().v); auto sound = qs(d.vsound);
changed = (setTo->flags != d.vflags.v) || (setTo->mute != d.vmute_until.v) || (setTo->sound != sound);
if (changed) { if (changed) {
setTo->flags = d.vflags.v; setTo->flags = d.vflags.v;
setTo->mute = d.vmute_until.v; setTo->mute = d.vmute_until.v;
setTo->sound = d.vsound.c_string().v; setTo->sound = sound;
if (updatePeer) { if (updatePeer) {
if (!h) h = App::history(updatePeer->id); if (!h) h = App::history(updatePeer->id);
int32 changeIn = 0; int32 changeIn = 0;
@ -4514,7 +4514,7 @@ bool fwdInfoDataLoaded(const MTPMessageFwdHeader &header) {
} }
bool mentionUsersLoaded(const MTPVector<MTPMessageEntity> &entities) { bool mentionUsersLoaded(const MTPVector<MTPMessageEntity> &entities) {
for_const (auto &entity, entities.c_vector().v) { for_const (auto &entity, entities.v) {
auto type = entity.type(); auto type = entity.type();
if (type == mtpc_messageEntityMentionName) { if (type == mtpc_messageEntityMentionName) {
if (!App::userLoaded(peerFromUser(entity.c_messageEntityMentionName().vuser_id))) { if (!App::userLoaded(peerFromUser(entity.c_messageEntityMentionName().vuser_id))) {
@ -4568,7 +4568,7 @@ DataIsLoadedResult allDataLoadedForMessage(const MTPMessage &msg) {
} }
switch (d.vaction.type()) { switch (d.vaction.type()) {
case mtpc_messageActionChatAddUser: { case mtpc_messageActionChatAddUser: {
for_const (const MTPint &userId, d.vaction.c_messageActionChatAddUser().vusers.c_vector().v) { for_const (const MTPint &userId, d.vaction.c_messageActionChatAddUser().vusers.v) {
if (!App::userLoaded(peerFromUser(userId))) { if (!App::userLoaded(peerFromUser(userId))) {
return DataIsLoadedResult::NotLoaded; return DataIsLoadedResult::NotLoaded;
} }
@ -4701,7 +4701,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
if (d.has_entities() && !mentionUsersLoaded(d.ventities)) { if (d.has_entities() && !mentionUsersLoaded(d.ventities)) {
api()->requestMessageData(item->history()->peer->asChannel(), item->id, ApiWrap::RequestMessageDataCallback()); api()->requestMessageData(item->history()->peer->asChannel(), item->id, ApiWrap::RequestMessageDataCallback());
} }
auto entities = d.has_entities() ? entitiesFromMTP(d.ventities.c_vector().v) : EntitiesInText(); auto entities = d.has_entities() ? entitiesFromMTP(d.ventities.v) : EntitiesInText();
item->setText({ text, entities }); item->setText({ text, entities });
item->updateMedia(d.has_media() ? (&d.vmedia) : nullptr); item->updateMedia(d.has_media() ? (&d.vmedia) : nullptr);
item->addToOverview(AddToOverviewNew); item->addToOverview(AddToOverviewNew);
@ -4796,9 +4796,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} }
// update before applying skipped // update before applying skipped
auto &v = d.vmessages.c_vector().v; auto &v = d.vmessages.v;
for (int32 i = 0, l = v.size(); i < l; ++i) { for (int32 i = 0, l = v.size(); i < l; ++i) {
if (HistoryItem *item = App::histItemById(NoChannel, v.at(i).v)) { if (auto item = App::histItemById(NoChannel, v.at(i).v)) {
if (item->isMediaUnread()) { if (item->isMediaUnread()) {
item->markMediaRead(); item->markMediaRead();
Ui::repaintHistoryItem(item); Ui::repaintHistoryItem(item);
@ -4867,7 +4867,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} }
// update before applying skipped // update before applying skipped
App::feedWereDeleted(NoChannel, d.vmessages.c_vector().v); App::feedWereDeleted(NoChannel, d.vmessages.v);
_history->peerMessagesUpdated(); _history->peerMessagesUpdated();
ptsApplySkippedUpdates(); ptsApplySkippedUpdates();
@ -5053,7 +5053,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
if (d.is_popup()) { if (d.is_popup()) {
Ui::show(Box<InformBox>(qs(d.vmessage))); Ui::show(Box<InformBox>(qs(d.vmessage)));
} else { } else {
App::wnd()->serviceNotification({ qs(d.vmessage), entitiesFromMTP(d.ventities.c_vector().v) }, d.vmedia); App::wnd()->serviceNotification({ qs(d.vmessage), entitiesFromMTP(d.ventities.v) }, d.vmedia);
emit App::wnd()->checkNewAuthorization(); emit App::wnd()->checkNewAuthorization();
} }
} break; } break;
@ -5066,7 +5066,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
auto &d = update.c_updatePinnedDialogs(); auto &d = update.c_updatePinnedDialogs();
if (d.has_order()) { if (d.has_order()) {
auto allLoaded = true; auto allLoaded = true;
auto &order = d.vorder.c_vector().v; auto &order = d.vorder.v;
for_const (auto &peer, order) { for_const (auto &peer, order) {
auto peerId = peerFromMTP(peer); auto peerId = peerFromMTP(peer);
if (!App::historyLoaded(peerId)) { if (!App::historyLoaded(peerId)) {
@ -5258,7 +5258,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} }
// update before applying skipped // update before applying skipped
App::feedWereDeleted(d.vchannel_id.v, d.vmessages.c_vector().v); App::feedWereDeleted(d.vchannel_id.v, d.vmessages.v);
_history->peerMessagesUpdated(); _history->peerMessagesUpdated();
if (channel && !_handlingChannelDifference) { if (channel && !_handlingChannelDifference) {
@ -5303,7 +5303,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} }
} }
auto inputSet = MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)); auto inputSet = MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access));
auto &v = set.vdocuments.c_vector().v; auto &v = set.vdocuments.v;
it->stickers.clear(); it->stickers.clear();
it->stickers.reserve(v.size()); it->stickers.reserve(v.size());
for (int i = 0, l = v.size(); i < l; ++i) { for (int i = 0, l = v.size(); i < l; ++i) {
@ -5316,13 +5316,13 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} }
} }
it->emoji.clear(); it->emoji.clear();
auto &packs = set.vpacks.c_vector().v; auto &packs = set.vpacks.v;
for (auto i = 0, l = packs.size(); i != l; ++i) { for (auto i = 0, l = packs.size(); i != l; ++i) {
if (packs[i].type() != mtpc_stickerPack) continue; if (packs[i].type() != mtpc_stickerPack) continue;
auto &pack = packs.at(i).c_stickerPack(); auto &pack = packs.at(i).c_stickerPack();
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) { if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
emoji = emoji->original(); emoji = emoji->original();
auto &stickers = pack.vdocuments.c_vector().v; auto &stickers = pack.vdocuments.v;
StickerPack p; StickerPack p;
p.reserve(stickers.size()); p.reserve(stickers.size());
@ -5366,7 +5366,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateStickerSetsOrder: { case mtpc_updateStickerSetsOrder: {
auto &d = update.c_updateStickerSetsOrder(); auto &d = update.c_updateStickerSetsOrder();
if (!d.is_masks()) { if (!d.is_masks()) {
auto &order = d.vorder.c_vector().v; auto &order = d.vorder.v;
auto &sets = Global::StickerSets(); auto &sets = Global::StickerSets();
Stickers::Order result; Stickers::Order result;
for (int i = 0, l = order.size(); i < l; ++i) { for (int i = 0, l = order.size(); i < l; ++i) {

View File

@ -2813,20 +2813,20 @@ void MediaView::userPhotosLoaded(UserData *u, const MTPphotos_Photos &photos, mt
_loadRequest = 0; _loadRequest = 0;
} }
const QVector<MTPPhoto> *v = 0; const QVector<MTPPhoto> *v = nullptr;
switch (photos.type()) { switch (photos.type()) {
case mtpc_photos_photos: { case mtpc_photos_photos: {
const auto &d(photos.c_photos_photos()); auto &d = photos.c_photos_photos();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
v = &d.vphotos.c_vector().v; v = &d.vphotos.v;
u->photosCount = 0; u->photosCount = 0;
} break; } break;
case mtpc_photos_photosSlice: { case mtpc_photos_photosSlice: {
const auto &d(photos.c_photos_photosSlice()); auto &d = photos.c_photos_photosSlice();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
u->photosCount = d.vcount.v; u->photosCount = d.vcount.v;
v = &d.vphotos.c_vector().v; v = &d.vphotos.v;
} break; } break;
default: return; default: return;

View File

@ -66,11 +66,11 @@ void wrapInvokeAfter(mtpRequest &to, const mtpRequest &from, const mtpRequestMap
} }
} }
bool parsePQ(const string &pqStr, string &pStr, string &qStr) { bool parsePQ(const QByteArray &pqStr, QByteArray &pStr, QByteArray &qStr) {
if (pqStr.length() > 8) return false; // more than 64 bit pq if (pqStr.length() > 8) return false; // more than 64 bit pq
uint64 pq = 0, p, q; uint64 pq = 0, p, q;
const uchar *pqChars = (const uchar*)&pqStr[0]; const uchar *pqChars = (const uchar*)pqStr.constData();
for (uint32 i = 0, l = pqStr.length(); i < l; ++i) { for (uint32 i = 0, l = pqStr.length(); i < l; ++i) {
pq <<= 8; pq <<= 8;
pq |= (uint64)pqChars[i]; pq |= (uint64)pqChars[i];
@ -92,14 +92,14 @@ bool parsePQ(const string &pqStr, string &pStr, string &qStr) {
if (p > q) std::swap(p, q); if (p > q) std::swap(p, q);
pStr.resize(4); pStr.resize(4);
uchar *pChars = (uchar*)&pStr[0]; uchar *pChars = (uchar*)pStr.data();
for (uint32 i = 0; i < 4; ++i) { for (uint32 i = 0; i < 4; ++i) {
*(pChars + 3 - i) = (uchar)(p & 0xFF); *(pChars + 3 - i) = (uchar)(p & 0xFF);
p >>= 8; p >>= 8;
} }
qStr.resize(4); qStr.resize(4);
uchar *qChars = (uchar*)&qStr[0]; uchar *qChars = (uchar*)qStr.data();
for (uint32 i = 0; i < 4; ++i) { for (uint32 i = 0; i < 4; ++i) {
*(qChars + 3 - i) = (uchar)(q & 0xFF); *(qChars + 3 - i) = (uchar)(q & 0xFF);
q >>= 8; q >>= 8;
@ -1570,7 +1570,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
case mtpc_msgs_ack: { case mtpc_msgs_ack: {
MTPMsgsAck msg; MTPMsgsAck msg;
msg.read(from, end); msg.read(from, end);
const auto &ids(msg.c_msgs_ack().vmsg_ids.c_vector().v); auto &ids = msg.c_msgs_ack().vmsg_ids.v;
uint32 idsCount = ids.size(); uint32 idsCount = ids.size();
DEBUG_LOG(("Message Info: acks received, ids: %1").arg(Logs::vector(ids))); DEBUG_LOG(("Message Info: acks received, ids: %1").arg(Logs::vector(ids)));
@ -1701,8 +1701,8 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
} }
MTPMsgsStateReq msg; MTPMsgsStateReq msg;
msg.read(from, end); msg.read(from, end);
const auto &ids(msg.c_msgs_state_req().vmsg_ids.c_vector().v); auto &ids = msg.c_msgs_state_req().vmsg_ids.v;
uint32 idsCount = ids.size(); auto idsCount = ids.size();
DEBUG_LOG(("Message Info: msgs_state_req received, ids: %1").arg(Logs::vector(ids))); DEBUG_LOG(("Message Info: msgs_state_req received, ids: %1").arg(Logs::vector(ids)));
if (!idsCount) return HandleResult::Success; if (!idsCount) return HandleResult::Success;
@ -1749,10 +1749,10 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
case mtpc_msgs_state_info: { case mtpc_msgs_state_info: {
MTPMsgsStateInfo msg; MTPMsgsStateInfo msg;
msg.read(from, end); msg.read(from, end);
const auto &data(msg.c_msgs_state_info()); auto &data = msg.c_msgs_state_info();
uint64 reqMsgId = data.vreq_msg_id.v; auto reqMsgId = data.vreq_msg_id.v;
const auto &states(data.vinfo.c_string().v); auto &states = data.vinfo.v;
DEBUG_LOG(("Message Info: msg state received, msgId %1, reqMsgId: %2, HEX states %3").arg(msgId).arg(reqMsgId).arg(Logs::mb(states.data(), states.length()).str())); DEBUG_LOG(("Message Info: msg state received, msgId %1, reqMsgId: %2, HEX states %3").arg(msgId).arg(reqMsgId).arg(Logs::mb(states.data(), states.length()).str()));
mtpRequest requestBuffer; mtpRequest requestBuffer;
@ -1786,11 +1786,11 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
if (mtpTypeId(*rFrom) == mtpc_msgs_state_req) { if (mtpTypeId(*rFrom) == mtpc_msgs_state_req) {
MTPMsgsStateReq request; MTPMsgsStateReq request;
request.read(rFrom, rEnd); request.read(rFrom, rEnd);
handleMsgsStates(request.c_msgs_state_req().vmsg_ids.c_vector().v, states, toAck); handleMsgsStates(request.c_msgs_state_req().vmsg_ids.v, states, toAck);
} else { } else {
MTPMsgResendReq request; MTPMsgResendReq request;
request.read(rFrom, rEnd); request.read(rFrom, rEnd);
handleMsgsStates(request.c_msg_resend_req().vmsg_ids.c_vector().v, states, toAck); handleMsgsStates(request.c_msg_resend_req().vmsg_ids.v, states, toAck);
} }
} catch(Exception &) { } catch(Exception &) {
LOG(("Message Error: could not parse sent msgs_state_req")); LOG(("Message Error: could not parse sent msgs_state_req"));
@ -1808,9 +1808,9 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
MTPMsgsAllInfo msg; MTPMsgsAllInfo msg;
msg.read(from, end); msg.read(from, end);
const auto &data(msg.c_msgs_all_info()); auto &data = msg.c_msgs_all_info();
const auto &ids(data.vmsg_ids.c_vector().v); auto &ids = data.vmsg_ids.v;
const auto &states(data.vinfo.c_string().v); auto &states = data.vinfo.v;
QVector<MTPlong> toAck; QVector<MTPlong> toAck;
@ -1880,9 +1880,9 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
case mtpc_msg_resend_req: { case mtpc_msg_resend_req: {
MTPMsgResendReq msg; MTPMsgResendReq msg;
msg.read(from, end); msg.read(from, end);
const auto &ids(msg.c_msg_resend_req().vmsg_ids.c_vector().v); auto &ids = msg.c_msg_resend_req().vmsg_ids.v;
uint32 idsCount = ids.size(); auto idsCount = ids.size();
DEBUG_LOG(("Message Info: resend of msgs requested, ids: %1").arg(Logs::vector(ids))); DEBUG_LOG(("Message Info: resend of msgs requested, ids: %1").arg(Logs::vector(ids)));
if (!idsCount) return (badTime ? HandleResult::Ignored : HandleResult::Success); if (!idsCount) return (badTime ? HandleResult::Ignored : HandleResult::Success);
@ -2045,7 +2045,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
mtpBuffer ConnectionPrivate::ungzip(const mtpPrime *from, const mtpPrime *end) const { mtpBuffer ConnectionPrivate::ungzip(const mtpPrime *from, const mtpPrime *end) const {
MTPstring packed; MTPstring packed;
packed.read(from, end); // read packed string as serialized mtp string type packed.read(from, end); // read packed string as serialized mtp string type
uint32 packedLen = packed.c_string().v.size(), unpackedChunk = packedLen, unpackedLen = 0; uint32 packedLen = packed.v.size(), unpackedChunk = packedLen, unpackedLen = 0;
mtpBuffer result; // * 4 because of mtpPrime type mtpBuffer result; // * 4 because of mtpPrime type
result.resize(0); result.resize(0);
@ -2061,7 +2061,7 @@ mtpBuffer ConnectionPrivate::ungzip(const mtpPrime *from, const mtpPrime *end) c
return result; return result;
} }
stream.avail_in = packedLen; stream.avail_in = packedLen;
stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(packed.c_string().v.data())); stream.next_in = reinterpret_cast<Bytef*>(packed.v.data());
stream.avail_out = 0; stream.avail_out = 0;
while (!stream.avail_out) { while (!stream.avail_out) {
@ -2072,7 +2072,7 @@ mtpBuffer ConnectionPrivate::ungzip(const mtpPrime *from, const mtpPrime *end) c
if (res != Z_OK && res != Z_STREAM_END) { if (res != Z_OK && res != Z_STREAM_END) {
inflateEnd(&stream); inflateEnd(&stream);
LOG(("RPC Error: could not unpack gziped data, code: %1").arg(res)); LOG(("RPC Error: could not unpack gziped data, code: %1").arg(res));
DEBUG_LOG(("RPC Error: bad gzip: %1").arg(Logs::mb(&packed.c_string().v[0], packedLen).str())); DEBUG_LOG(("RPC Error: bad gzip: %1").arg(Logs::mb(&packed.v[0], packedLen).str()));
return mtpBuffer(); return mtpBuffer();
} }
} }
@ -2202,15 +2202,18 @@ void ConnectionPrivate::requestsAcked(const QVector<MTPlong> &ids, bool byRespon
} }
} }
void ConnectionPrivate::handleMsgsStates(const QVector<MTPlong> &ids, const string &states, QVector<MTPlong> &acked) { void ConnectionPrivate::handleMsgsStates(const QVector<MTPlong> &ids, const QByteArray &states, QVector<MTPlong> &acked) {
uint32 idsCount = ids.size(); uint32 idsCount = ids.size();
if (!idsCount) { if (!idsCount) {
DEBUG_LOG(("Message Info: void ids vector in handleMsgsStates()")); DEBUG_LOG(("Message Info: void ids vector in handleMsgsStates()"));
return; return;
} }
if (states.size() < idsCount) {
LOG(("Message Error: got less states than required ids count."));
return;
}
acked.reserve(acked.size() + idsCount); acked.reserve(acked.size() + idsCount);
for (uint32 i = 0, count = idsCount; i < count; ++i) { for (uint32 i = 0, count = idsCount; i < count; ++i) {
char state = states[i]; char state = states[i];
uint64 requestMsgId = ids[i].v; uint64 requestMsgId = ids[i].v;
@ -2410,7 +2413,7 @@ void ConnectionPrivate::pqAnswered() {
static MTP::internal::RSAPublicKeys RSAKeys = MTP::internal::InitRSAPublicKeys(); static MTP::internal::RSAPublicKeys RSAKeys = MTP::internal::InitRSAPublicKeys();
const MTP::internal::RSAPublicKey *rsaKey = nullptr; const MTP::internal::RSAPublicKey *rsaKey = nullptr;
auto &fingerPrints = res_pq.c_resPQ().vserver_public_key_fingerprints.c_vector().v; auto &fingerPrints = res_pq.c_resPQ().vserver_public_key_fingerprints.v;
for (auto &fingerPrint : fingerPrints) { for (auto &fingerPrint : fingerPrints) {
auto it = RSAKeys.constFind(static_cast<uint64>(fingerPrint.v)); auto it = RSAKeys.constFind(static_cast<uint64>(fingerPrint.v));
if (it != RSAKeys.cend()) { if (it != RSAKeys.cend()) {
@ -2433,16 +2436,16 @@ void ConnectionPrivate::pqAnswered() {
_authKeyData->server_nonce = res_pq_data.vserver_nonce; _authKeyData->server_nonce = res_pq_data.vserver_nonce;
_authKeyData->new_nonce = rand_value<MTPint256>(); _authKeyData->new_nonce = rand_value<MTPint256>();
auto &pq = res_pq_data.vpq.c_string().v; auto &pq = res_pq_data.vpq.v;
auto p = std::string(); auto p = QByteArray();
auto q = std::string(); auto q = QByteArray();
if (!MTP::internal::parsePQ(pq, p, q)) { if (!MTP::internal::parsePQ(pq, p, q)) {
LOG(("AuthKey Error: could not factor pq!")); LOG(("AuthKey Error: could not factor pq!"));
DEBUG_LOG(("AuthKey Error: problematic pq: %1").arg(Logs::mb(&pq[0], pq.length()).str())); DEBUG_LOG(("AuthKey Error: problematic pq: %1").arg(Logs::mb(pq.constData(), pq.length()).str()));
return restart(); return restart();
} }
auto p_q_inner = MTP_p_q_inner_data(res_pq_data.vpq, MTP_string(std::move(p)), MTP_string(std::move(q)), _authKeyData->nonce, _authKeyData->server_nonce, _authKeyData->new_nonce); auto p_q_inner = MTP_p_q_inner_data(res_pq_data.vpq, MTP_bytes(std::move(p)), MTP_bytes(std::move(q)), _authKeyData->nonce, _authKeyData->server_nonce, _authKeyData->new_nonce);
auto dhEncString = encryptPQInnerRSA(p_q_inner, rsaKey); auto dhEncString = encryptPQInnerRSA(p_q_inner, rsaKey);
if (dhEncString.empty()) { if (dhEncString.empty()) {
return restart(); return restart();
@ -2516,11 +2519,11 @@ void ConnectionPrivate::dhParamsAnswered() {
return restart(); return restart();
} }
const string &encDHStr(encDH.vencrypted_answer.c_string().v); auto &encDHStr = encDH.vencrypted_answer.v;
uint32 encDHLen = encDHStr.length(), encDHBufLen = encDHLen >> 2; uint32 encDHLen = encDHStr.length(), encDHBufLen = encDHLen >> 2;
if ((encDHLen & 0x03) || encDHBufLen < 6) { if ((encDHLen & 0x03) || encDHBufLen < 6) {
LOG(("AuthKey Error: bad encrypted data length %1 (in server_DH_params_ok)!").arg(encDHLen)); LOG(("AuthKey Error: bad encrypted data length %1 (in server_DH_params_ok)!").arg(encDHLen));
DEBUG_LOG(("AuthKey Error: received encrypted data %1").arg(Logs::mb(&encDHStr[0], encDHLen).str())); DEBUG_LOG(("AuthKey Error: received encrypted data %1").arg(Logs::mb(encDHStr.constData(), encDHLen).str()));
return restart(); return restart();
} }
@ -2543,7 +2546,7 @@ void ConnectionPrivate::dhParamsAnswered() {
memcpy(_authKeyData->aesIV + 8, sha1nn, 20); memcpy(_authKeyData->aesIV + 8, sha1nn, 20);
memcpy(_authKeyData->aesIV + 28, &_authKeyData->new_nonce, 4); memcpy(_authKeyData->aesIV + 28, &_authKeyData->new_nonce, 4);
aesIgeDecrypt(&encDHStr[0], &decBuffer[0], encDHLen, _authKeyData->aesKey, _authKeyData->aesIV); aesIgeDecrypt(encDHStr.constData(), &decBuffer[0], encDHLen, _authKeyData->aesKey, _authKeyData->aesIV);
const mtpPrime *from(&decBuffer[5]), *to(from), *end(from + (encDHBufLen - 5)); const mtpPrime *from(&decBuffer[5]), *to(from), *end(from + (encDHBufLen - 5));
MTPServer_DH_inner_data dh_inner; MTPServer_DH_inner_data dh_inner;
@ -2562,23 +2565,24 @@ void ConnectionPrivate::dhParamsAnswered() {
uchar sha1Buffer[20]; uchar sha1Buffer[20];
if (memcmp(&decBuffer[0], hashSha1(&decBuffer[5], (to - from) * sizeof(mtpPrime), sha1Buffer), 20)) { if (memcmp(&decBuffer[0], hashSha1(&decBuffer[5], (to - from) * sizeof(mtpPrime), sha1Buffer), 20)) {
LOG(("AuthKey Error: sha1 hash of encrypted part did not match!")); LOG(("AuthKey Error: sha1 hash of encrypted part did not match!"));
DEBUG_LOG(("AuthKey Error: sha1 did not match, server_nonce: %1, new_nonce %2, encrypted data %3").arg(Logs::mb(&_authKeyData->server_nonce, 16).str()).arg(Logs::mb(&_authKeyData->new_nonce, 16).str()).arg(Logs::mb(&encDHStr[0], encDHLen).str())); DEBUG_LOG(("AuthKey Error: sha1 did not match, server_nonce: %1, new_nonce %2, encrypted data %3").arg(Logs::mb(&_authKeyData->server_nonce, 16).str()).arg(Logs::mb(&_authKeyData->new_nonce, 16).str()).arg(Logs::mb(encDHStr.constData(), encDHLen).str()));
return restart(); return restart();
} }
unixtimeSet(dh_inner_data.vserver_time.v); unixtimeSet(dh_inner_data.vserver_time.v);
const string &dhPrime(dh_inner_data.vdh_prime.c_string().v), &g_a(dh_inner_data.vg_a.c_string().v); auto &dhPrime = dh_inner_data.vdh_prime.v;
auto &g_a = dh_inner_data.vg_a.v;
if (dhPrime.length() != 256 || g_a.length() != 256) { if (dhPrime.length() != 256 || g_a.length() != 256) {
LOG(("AuthKey Error: bad dh_prime len (%1) or g_a len (%2)").arg(dhPrime.length()).arg(g_a.length())); LOG(("AuthKey Error: bad dh_prime len (%1) or g_a len (%2)").arg(dhPrime.length()).arg(g_a.length()));
DEBUG_LOG(("AuthKey Error: dh_prime %1, g_a %2").arg(Logs::mb(&dhPrime[0], dhPrime.length()).str()).arg(Logs::mb(&g_a[0], g_a.length()).str())); DEBUG_LOG(("AuthKey Error: dh_prime %1, g_a %2").arg(Logs::mb(dhPrime.constData(), dhPrime.length()).str()).arg(Logs::mb(g_a.constData(), g_a.length()).str()));
return restart(); return restart();
} }
// check that dhPrime and (dhPrime - 1) / 2 are really prime using openssl BIGNUM methods // check that dhPrime and (dhPrime - 1) / 2 are really prime using openssl BIGNUM methods
MTP::internal::BigNumPrimeTest bnPrimeTest; MTP::internal::BigNumPrimeTest bnPrimeTest;
if (!bnPrimeTest.isPrimeAndGood(&dhPrime[0], MTPMillerRabinIterCount, dh_inner_data.vg.v)) { if (!bnPrimeTest.isPrimeAndGood(dhPrime.constData(), MTPMillerRabinIterCount, dh_inner_data.vg.v)) {
LOG(("AuthKey Error: bad dh_prime primality!").arg(dhPrime.length()).arg(g_a.length())); LOG(("AuthKey Error: bad dh_prime primality!").arg(dhPrime.length()).arg(g_a.length()));
DEBUG_LOG(("AuthKey Error: dh_prime %1").arg(Logs::mb(&dhPrime[0], dhPrime.length()).str())); DEBUG_LOG(("AuthKey Error: dh_prime %1").arg(Logs::mb(dhPrime.constData(), dhPrime.length()).str()));
return restart(); return restart();
} }

View File

@ -174,7 +174,7 @@ private:
}; };
HandleResult handleOneReceived(const mtpPrime *from, const mtpPrime *end, uint64 msgId, int32 serverTime, uint64 serverSalt, bool badTime); HandleResult handleOneReceived(const mtpPrime *from, const mtpPrime *end, uint64 msgId, int32 serverTime, uint64 serverSalt, bool badTime);
mtpBuffer ungzip(const mtpPrime *from, const mtpPrime *end) const; mtpBuffer ungzip(const mtpPrime *from, const mtpPrime *end) const;
void handleMsgsStates(const QVector<MTPlong> &ids, const std::string &states, QVector<MTPlong> &acked); void handleMsgsStates(const QVector<MTPlong> &ids, const QByteArray &states, QVector<MTPlong> &acked);
void clearMessages(); void clearMessages();

View File

@ -63,8 +63,8 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
case mtpc_string: { case mtpc_string: {
MTPstring value; MTPstring value;
value.read(from, end, cons); value.read(from, end, cons);
QByteArray strUtf8(value.c_string().v.c_str(), value.c_string().v.length()); auto strUtf8 = value.v;
QString str = QString::fromUtf8(strUtf8); auto str = QString::fromUtf8(strUtf8);
if (str.toUtf8() == strUtf8) { if (str.toUtf8() == strUtf8) {
to.add("\"").add(str.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n")).add("\" [STRING]"); to.add("\"").add(str.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n")).add("\" [STRING]");
} else if (strUtf8.size() < 64) { } else if (strUtf8.size() < 64) {
@ -96,7 +96,7 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
case mtpc_gzip_packed: { case mtpc_gzip_packed: {
MTPstring packed; MTPstring packed;
packed.read(from, end); // read packed string as serialized mtp string type packed.read(from, end); // read packed string as serialized mtp string type
uint32 packedLen = packed.c_string().v.size(), unpackedChunk = packedLen; uint32 packedLen = packed.v.size(), unpackedChunk = packedLen;
mtpBuffer result; // * 4 because of mtpPrime type mtpBuffer result; // * 4 because of mtpPrime type
result.resize(0); result.resize(0);
@ -111,7 +111,7 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
throw Exception(QString("ungzip init, code: %1").arg(res)); throw Exception(QString("ungzip init, code: %1").arg(res));
} }
stream.avail_in = packedLen; stream.avail_in = packedLen;
stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(packed.c_string().v.data())); stream.next_in = reinterpret_cast<Bytef*>(packed.v.data());
stream.avail_out = 0; stream.avail_out = 0;
while (!stream.avail_out) { while (!stream.avail_out) {
result.resize(result.size() + unpackedChunk); result.resize(result.size() + unpackedChunk);

View File

@ -99,7 +99,6 @@ public:
static bool needAckByType(mtpTypeId type); static bool needAckByType(mtpTypeId type);
private: private:
static uint32 _padding(uint32 requestSize) { static uint32 _padding(uint32 requestSize) {
return ((8 + requestSize) & 0x03) ? (4 - ((8 + requestSize) & 0x03)) : 0; return ((8 + requestSize) & 0x03) ? (4 - ((8 + requestSize) & 0x03)) : 0;
} }
@ -542,36 +541,15 @@ inline bool operator!=(const MTPdouble &a, const MTPdouble &b) {
return a.v != b.v; return a.v != b.v;
} }
class MTPDstring : public mtpData { class MTPstring;
public: using MTPbytes = MTPstring;
MTPDstring() {
}
MTPDstring(const std::string &val) : v(val) {
}
MTPDstring(std::string &&val) : v(std::move(val)) {
}
MTPDstring(const QString &val) : v(val.toUtf8().constData()) {
}
MTPDstring(const QByteArray &val) : v(val.constData(), val.size()) {
}
MTPDstring(const char *val) : v(val) {
}
std::string v; class MTPstring {
};
class MTPstring : private mtpDataOwner {
public: public:
MTPstring() = default; MTPstring() = default;
const MTPDstring &c_string() const {
t_assert(data != nullptr);
return static_cast<const MTPDstring&>(*data);
}
uint32 innerLength() const { uint32 innerLength() const {
uint32 l = c_string().v.length(); uint32 l = v.length();
if (l < 254) { if (l < 254) {
l += 1; l += 1;
} else { } else {
@ -601,11 +579,10 @@ public:
} }
if (from > end) throw mtpErrorInsufficient(); if (from > end) throw mtpErrorInsufficient();
auto string = std::string(reinterpret_cast<const char*>(buf), l); v = QByteArray(reinterpret_cast<const char*>(buf), l);
data = std::make_shared<MTPDstring>(std::move(string));
} }
void write(mtpBuffer &to) const { void write(mtpBuffer &to) const {
uint32 l = c_string().v.length(), s = l + ((l < 254) ? 1 : 4), was = to.size(); uint32 l = v.length(), s = l + ((l < 254) ? 1 : 4), was = to.size();
if (s & 0x03) { if (s & 0x03) {
s += 4; s += 4;
} }
@ -621,89 +598,67 @@ public:
*(buf++) = (char)((l >> 8) & 0xFF); *(buf++) = (char)((l >> 8) & 0xFF);
*(buf++) = (char)((l >> 16) & 0xFF); *(buf++) = (char)((l >> 16) & 0xFF);
} }
memcpy(buf, c_string().v.c_str(), l); memcpy(buf, v.constData(), l);
} }
QByteArray v;
private: private:
explicit MTPstring(std::shared_ptr<const MTPDstring> &&data) : mtpDataOwner(std::move(data)) { explicit MTPstring(QByteArray &&data) : v(std::move(data)) {
} }
friend MTPstring MTP_string(const std::string &v); friend MTPstring MTP_string(const std::string &v);
friend MTPstring MTP_string(std::string &&v);
friend MTPstring MTP_string(const QString &v); friend MTPstring MTP_string(const QString &v);
friend MTPstring MTP_string(const char *v); friend MTPstring MTP_string(const char *v);
friend MTPstring MTP_bytes(const QByteArray &v); friend MTPbytes MTP_bytes(const QByteArray &v);
friend MTPbytes MTP_bytes(QByteArray &&v);
}; };
inline MTPstring MTP_string(const std::string &v) {
return MTPstring(std::make_shared<MTPDstring>(v));
}
inline MTPstring MTP_string(std::string &&v) {
return MTPstring(std::make_shared<MTPDstring>(std::move(v)));
}
inline MTPstring MTP_string(const QString &v) {
return MTPstring(std::make_shared<MTPDstring>(v));
}
inline MTPstring MTP_string(const char *v) {
return MTPstring(std::make_shared<MTPDstring>(v));
}
MTPstring MTP_string(const QByteArray &v) = delete;
using MTPString = MTPBoxed<MTPstring>; using MTPString = MTPBoxed<MTPstring>;
using MTPbytes = MTPstring;
using MTPBytes = MTPBoxed<MTPbytes>; using MTPBytes = MTPBoxed<MTPbytes>;
inline MTPstring MTP_string(const std::string &v) {
return MTPstring(QByteArray(v.data(), v.size()));
}
inline MTPstring MTP_string(const QString &v) {
return MTPstring(v.toUtf8());
}
inline MTPstring MTP_string(const char *v) {
return MTPstring(QByteArray(v, strlen(v)));
}
MTPstring MTP_string(const QByteArray &v) = delete;
inline MTPbytes MTP_bytes(const QByteArray &v) { inline MTPbytes MTP_bytes(const QByteArray &v) {
return MTPbytes(std::make_shared<MTPDstring>(v)); return MTPbytes(QByteArray(v));
}
inline MTPbytes MTP_bytes(QByteArray &&v) {
return MTPbytes(std::move(v));
} }
inline bool operator==(const MTPstring &a, const MTPstring &b) { inline bool operator==(const MTPstring &a, const MTPstring &b) {
return a.c_string().v == b.c_string().v; return a.v == b.v;
} }
inline bool operator!=(const MTPstring &a, const MTPstring &b) { inline bool operator!=(const MTPstring &a, const MTPstring &b) {
return a.c_string().v != b.c_string().v; return a.v != b.v;
} }
inline QString qs(const MTPstring &v) { inline QString qs(const MTPstring &v) {
auto &d = v.c_string().v; return QString::fromUtf8(v.v);
return QString::fromUtf8(d.data(), d.length());
} }
inline QByteArray qba(const MTPstring &v) { inline QByteArray qba(const MTPstring &v) {
auto &d = v.c_string().v; return v.v;
return QByteArray(d.data(), d.length());
} }
template <typename T> template <typename T>
class MTPDvector : public mtpData { class MTPvector {
public:
MTPDvector() {
}
MTPDvector(uint32 count) : v(count) {
}
MTPDvector(uint32 count, const T &value) : v(count, value) {
}
MTPDvector(const QVector<T> &vec) : v(vec) {
}
using VType = QVector<T>;
VType v;
};
template <typename T>
class MTPvector : private mtpDataOwner {
public: public:
MTPvector() = default; MTPvector() = default;
const MTPDvector<T> &c_vector() const {
t_assert(data != nullptr);
return static_cast<const MTPDvector<T>&>(*data);
}
uint32 innerLength() const { uint32 innerLength() const {
uint32 result(sizeof(uint32)); uint32 result(sizeof(uint32));
for_const (auto &item, c_vector().v) { for_const (auto &item, v) {
result += item.innerLength(); result += item.innerLength();
} }
return result; return result;
@ -720,17 +675,19 @@ public:
for (auto &item : vector) { for (auto &item : vector) {
item.read(from, end); item.read(from, end);
} }
data = std::make_shared<MTPDvector<T>>(std::move(vector)); v = std::move(vector);
} }
void write(mtpBuffer &to) const { void write(mtpBuffer &to) const {
to.push_back(c_vector().v.size()); to.push_back(v.size());
for_const (auto &item, c_vector().v) { for_const (auto &item, v) {
item.write(to); item.write(to);
} }
} }
QVector<T> v;
private: private:
explicit MTPvector(std::shared_ptr<MTPDvector<T>> &&data) : mtpDataOwner(std::move(data)) { explicit MTPvector(QVector<T> &&data) : v(std::move(data)) {
} }
template <typename U> template <typename U>
@ -745,19 +702,19 @@ private:
}; };
template <typename T> template <typename T>
inline MTPvector<T> MTP_vector(uint32 count) { inline MTPvector<T> MTP_vector(uint32 count) {
return MTPvector<T>(std::make_shared<MTPDvector<T>>(count)); return MTPvector<T>(QVector<T>(count));
} }
template <typename T> template <typename T>
inline MTPvector<T> MTP_vector(uint32 count, const T &value) { inline MTPvector<T> MTP_vector(uint32 count, const T &value) {
return MTPvector<T>(std::make_shared<MTPDvector<T>>(count, value)); return MTPvector<T>(QVector<T>(count, value));
} }
template <typename T> template <typename T>
inline MTPvector<T> MTP_vector(const QVector<T> &v) { inline MTPvector<T> MTP_vector(const QVector<T> &v) {
return MTPvector<T>(std::make_shared<MTPDvector<T>>(v)); return MTPvector<T>(QVector<T>(v));
} }
template <typename T> template <typename T>
inline MTPvector<T> MTP_vector(QVector<T> &&v) { inline MTPvector<T> MTP_vector(QVector<T> &&v) {
return MTPvector<T>(std::make_shared<MTPDvector<T>>(std::move(v))); return MTPvector<T>(std::move(v));
} }
template <typename T> template <typename T>
using MTPVector = MTPBoxed<MTPvector<T>>; using MTPVector = MTPBoxed<MTPvector<T>>;

View File

@ -72,7 +72,7 @@ void DcOptions::processFromList(const QVector<MTPDcOption> &options, bool overwr
} }
shiftedIdsProcessed.push_back(dcIdWithShift); shiftedIdsProcessed.push_back(dcIdWithShift);
auto &ip = option.vip_address.c_string().v; auto &ip = std::string(option.vip_address.v.constData(), option.vip_address.v.size());
auto port = option.vport.v; auto port = option.vport.v;
if (applyOneGuarded(dcId, flags, ip, port)) { if (applyOneGuarded(dcId, flags, ip, port)) {
if (!base::contains(idsChanged, dcId)) { if (!base::contains(idsChanged, dcId)) {
@ -100,11 +100,11 @@ void DcOptions::processFromList(const QVector<MTPDcOption> &options, bool overwr
} }
void DcOptions::setFromList(const MTPVector<MTPDcOption> &options) { void DcOptions::setFromList(const MTPVector<MTPDcOption> &options) {
processFromList(options.c_vector().v, true); processFromList(options.v, true);
} }
void DcOptions::addFromList(const MTPVector<MTPDcOption> &options) { void DcOptions::addFromList(const MTPVector<MTPDcOption> &options) {
processFromList(options.c_vector().v, false); processFromList(options.v, false);
} }
void DcOptions::addFromOther(const DcOptions &options) { void DcOptions::addFromOther(const DcOptions &options) {

View File

@ -536,9 +536,9 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
} }
auto &data = result.c_config(); auto &data = result.c_config();
DEBUG_LOG(("MTP Info: got config, chat_size_max: %1, date: %2, test_mode: %3, this_dc: %4, dc_options.length: %5").arg(data.vchat_size_max.v).arg(data.vdate.v).arg(mtpIsTrue(data.vtest_mode)).arg(data.vthis_dc.v).arg(data.vdc_options.c_vector().v.size())); DEBUG_LOG(("MTP Info: got config, chat_size_max: %1, date: %2, test_mode: %3, this_dc: %4, dc_options.length: %5").arg(data.vchat_size_max.v).arg(data.vdate.v).arg(mtpIsTrue(data.vtest_mode)).arg(data.vthis_dc.v).arg(data.vdc_options.v.size()));
if (data.vdc_options.c_vector().v.empty()) { if (data.vdc_options.v.empty()) {
LOG(("MTP Error: config with empty dc_options received!")); LOG(("MTP Error: config with empty dc_options received!"));
} else { } else {
_dcOptions->setFromList(data.vdc_options); _dcOptions->setFromList(data.vdc_options);

View File

@ -204,26 +204,26 @@ void OverviewInner::searchReceived(SearchRequestType type, const MTPmessages_Mes
} }
if (_searchRequest == req) { if (_searchRequest == req) {
const QVector<MTPMessage> *messages = 0; const QVector<MTPMessage> *messages = nullptr;
switch (result.type()) { switch (result.type()) {
case mtpc_messages_messages: { case mtpc_messages_messages: {
auto &d(result.c_messages_messages()); auto &d = result.c_messages_messages();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
messages = &d.vmessages.c_vector().v; messages = &d.vmessages.v;
_searchedCount = messages->size(); _searchedCount = messages->size();
} break; } break;
case mtpc_messages_messagesSlice: { case mtpc_messages_messagesSlice: {
auto &d(result.c_messages_messagesSlice()); auto &d = result.c_messages_messagesSlice();
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
messages = &d.vmessages.c_vector().v; messages = &d.vmessages.v;
_searchedCount = d.vcount.v; _searchedCount = d.vcount.v;
} break; } break;
case mtpc_messages_channelMessages: { case mtpc_messages_channelMessages: {
auto &d(result.c_messages_channelMessages()); auto &d = result.c_messages_channelMessages();
if (_peer && _peer->isChannel()) { if (_peer && _peer->isChannel()) {
_peer->asChannel()->ptsReceived(d.vpts.v); _peer->asChannel()->ptsReceived(d.vpts.v);
} else { } else {
@ -231,7 +231,7 @@ void OverviewInner::searchReceived(SearchRequestType type, const MTPmessages_Mes
} }
App::feedUsers(d.vusers); App::feedUsers(d.vusers);
App::feedChats(d.vchats); App::feedChats(d.vchats);
messages = &d.vmessages.c_vector().v; messages = &d.vmessages.v;
_searchedCount = d.vcount.v; _searchedCount = d.vcount.v;
} break; } break;
} }

View File

@ -159,7 +159,7 @@ void InnerWidget::preloadMore() {
_preloadGroupId = 0; _preloadGroupId = 0;
_allLoaded = true; _allLoaded = true;
if (auto chats = Api::getChatsFromMessagesChats(result)) { if (auto chats = Api::getChatsFromMessagesChats(result)) {
auto &list = chats->c_vector().v; auto &list = chats->v;
if (!list.empty()) { if (!list.empty()) {
_items.reserve(_items.size() + list.size()); _items.reserve(_items.size() + list.size());
for_const (auto &chatData, list) { for_const (auto &chatData, list) {

View File

@ -3799,9 +3799,9 @@ void EmojiPan::inlineResultsDone(const MTPmessages_BotResults &result) {
bool adding = (it != _inlineCache.cend()); bool adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) { if (result.type() == mtpc_messages_botResults) {
const auto &d(result.c_messages_botResults()); auto &d = result.c_messages_botResults();
const auto &v(d.vresults.c_vector().v); auto &v = d.vresults.v;
uint64 queryId(d.vquery_id.v); auto queryId = d.vquery_id.v;
if (!adding) { if (!adding) {
it = _inlineCache.insert(_inlineQuery, new internal::InlineCacheEntry()); it = _inlineCache.insert(_inlineQuery, new internal::InlineCacheEntry());

View File

@ -39,7 +39,7 @@ internal::FeaturedReader *FeaturedReaderInstance = nullptr;
} // namespace } // namespace
void applyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) { void applyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
auto &v = d.vsets.c_vector().v; auto &v = d.vsets.v;
auto &order = Global::RefStickerSetsOrder(); auto &order = Global::RefStickerSetsOrder();
Stickers::Order archived; Stickers::Order archived;
archived.reserve(v.size()); archived.reserve(v.size());

View File

@ -473,7 +473,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
_requests.erase(i); _requests.erase(i);
auto &d = result.c_upload_file(); auto &d = result.c_upload_file();
auto &bytes = d.vbytes.c_string().v; auto &bytes = d.vbytes.v;
if (DebugLogging::FileLoader() && _id) { if (DebugLogging::FileLoader() && _id) {
DEBUG_LOG(("FileLoader(%1): got part with offset=%2, bytes=%3, _queue->queries=%4, _nextRequestOffset=%5, _requests=%6").arg(_id).arg(offset).arg(bytes.size()).arg(_queue->queries).arg(_nextRequestOffset).arg(serializereqs(_requests))); DEBUG_LOG(("FileLoader(%1): got part with offset=%2, bytes=%3, _queue->queries=%4, _nextRequestOffset=%5, _requests=%6").arg(_id).arg(offset).arg(bytes.size()).arg(_queue->queries).arg(_nextRequestOffset).arg(serializereqs(_requests)));

View File

@ -514,9 +514,9 @@ void UserData::setBotInfo(const MTPBotInfo &info) {
botInfo->text = Text(st::msgMinWidth); botInfo->text = Text(st::msgMinWidth);
} }
const auto &v(d.vcommands.c_vector().v); auto &v = d.vcommands.v;
botInfo->commands.reserve(v.size()); botInfo->commands.reserve(v.size());
bool changedCommands = false; auto changedCommands = false;
int32 j = 0; int32 j = 0;
for (int32 i = 0, l = v.size(); i < l; ++i) { for (int32 i = 0, l = v.size(); i < l; ++i) {
if (v.at(i).type() != mtpc_botCommand) continue; if (v.at(i).type() != mtpc_botCommand) continue;

View File

@ -195,11 +195,11 @@ constexpr const MsgId ServerMaxMsgId = 0x3FFFFFFF;
constexpr const MsgId ShowAtUnreadMsgId = 0; constexpr const MsgId ShowAtUnreadMsgId = 0;
struct NotifySettings { struct NotifySettings {
NotifySettings() : flags(MTPDpeerNotifySettings::Flag::f_show_previews), mute(0), sound("default") { NotifySettings() : flags(MTPDpeerNotifySettings::Flag::f_show_previews), sound(qsl("default")) {
} }
MTPDpeerNotifySettings::Flags flags; MTPDpeerNotifySettings::Flags flags;
TimeId mute; TimeId mute = 0;
std::string sound; QString sound;
bool previews() const { bool previews() const {
return flags & MTPDpeerNotifySettings::Flag::f_show_previews; return flags & MTPDpeerNotifySettings::Flag::f_show_previews;
} }