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

Use getters in MTP classes.

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

View File

@@ -218,13 +218,13 @@ void ApplyDifference(
data.version = version;
for (const auto &keyword : keywords) {
keyword.match([&](const MTPDemojiKeyword &keyword) {
const auto word = NormalizeKey(qs(keyword.vkeyword));
const auto word = NormalizeKey(qs(keyword.vkeyword()));
if (word.isEmpty()) {
return;
}
auto &list = data.emoji[word];
auto &&emoji = ranges::view::all(
keyword.vemoticons.v
keyword.vemoticons().v
) | ranges::view::transform([](const MTPstring &string) {
const auto text = qs(string);
const auto emoji = MustAddPostfix(text)
@@ -241,7 +241,7 @@ void ApplyDifference(
});
list.insert(end(list), emoji.begin(), emoji.end());
}, [&](const MTPDemojiKeywordDeleted &keyword) {
const auto word = NormalizeKey(qs(keyword.vkeyword));
const auto word = NormalizeKey(qs(keyword.vkeyword()));
if (word.isEmpty()) {
return;
}
@@ -250,7 +250,7 @@ void ApplyDifference(
return;
}
auto &list = i->second;
for (const auto &emoji : keyword.vemoticons.v) {
for (const auto &emoji : keyword.vemoticons().v) {
list.erase(
ranges::remove(list, qs(emoji), &LangPackEmoji::text),
end(list));
@@ -388,9 +388,9 @@ void EmojiKeywords::LangPack::refresh() {
void EmojiKeywords::LangPack::applyDifference(
const MTPEmojiKeywordsDifference &result) {
result.match([&](const MTPDemojiKeywordsDifference &data) {
const auto code = qs(data.vlang_code);
const auto version = data.vversion.v;
const auto &keywords = data.vkeywords.v;
const auto code = qs(data.vlang_code());
const auto version = data.vversion().v;
const auto &keywords = data.vkeywords().v;
if (code != _id) {
LOG(("API Error: Bad lang_code for emoji keywords %1 -> %2"
).arg(_id
@@ -634,7 +634,7 @@ void EmojiKeywords::refreshRemoteList() {
result.v
) | ranges::view::transform([](const MTPEmojiLanguage &language) {
return language.match([&](const MTPDemojiLanguage &language) {
return qs(language.vlang_code);
return qs(language.vlang_code());
});
}) | ranges::to_vector);
_langsRequestId = 0;

View File

@@ -228,16 +228,18 @@ void GifsListWidget::inlineResultsDone(const MTPmessages_BotResults &result) {
auto adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) {
auto &d = result.c_messages_botResults();
Auth().data().processUsers(d.vusers);
Auth().data().processUsers(d.vusers());
auto &v = d.vresults.v;
auto queryId = d.vquery_id.v;
auto &v = d.vresults().v;
auto queryId = d.vquery_id().v;
if (it == _inlineCache.cend()) {
it = _inlineCache.emplace(_inlineQuery, std::make_unique<InlineCacheEntry>()).first;
it = _inlineCache.emplace(
_inlineQuery,
std::make_unique<InlineCacheEntry>()).first;
}
auto entry = it->second.get();
entry->nextOffset = qs(d.vnext_offset);
entry->nextOffset = qs(d.vnext_offset().value_or_empty());
if (auto count = v.size()) {
entry->results.reserve(entry->results.size() + count);
}
@@ -853,9 +855,9 @@ void GifsListWidget::searchForGifs(const QString &query) {
Expects(result.type() == mtpc_contacts_resolvedPeer);
auto &data = result.c_contacts_resolvedPeer();
Auth().data().processUsers(data.vusers);
Auth().data().processChats(data.vchats);
if (auto peer = Auth().data().peerLoaded(peerFromMTP(data.vpeer))) {
Auth().data().processUsers(data.vusers());
Auth().data().processChats(data.vchats());
if (auto peer = Auth().data().peerLoaded(peerFromMTP(data.vpeer()))) {
if (auto user = peer->asUser()) {
_searchBot = user;
}

View File

@@ -31,7 +31,7 @@ constexpr auto kDontCacheLottieAfterArea = 512 * 512;
} // namespace
void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
auto &v = d.vsets.v;
auto &v = d.vsets().v;
auto &order = Auth().data().stickerSetsOrderRef();
Order archived;
archived.reserve(v.size());
@@ -41,14 +41,14 @@ void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
switch (stickerSet.type()) {
case mtpc_stickerSetCovered: {
auto &d = stickerSet.c_stickerSetCovered();
if (d.vset.type() == mtpc_stickerSet) {
setData = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
setData = &d.vset().c_stickerSet();
}
} break;
case mtpc_stickerSetMultiCovered: {
auto &d = stickerSet.c_stickerSetMultiCovered();
if (d.vset.type() == mtpc_stickerSet) {
setData = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
setData = &d.vset().c_stickerSet();
}
} break;
}
@@ -97,7 +97,7 @@ bool ApplyArchivedResultFake() {
MTP_long(set.access),
MTP_string(set.title),
MTP_string(set.shortName),
MTP_photoSizeEmpty(MTP_string(QString())),
MTP_photoSizeEmpty(MTP_string()),
MTP_int(0),
MTP_int(set.count),
MTP_int(set.hash));
@@ -298,13 +298,13 @@ void RequestSetToPushFaved(not_null<DocumentData*> document) {
Expects(result.type() == mtpc_messages_stickerSet);
auto list = std::vector<not_null<EmojiPtr>>();
auto &d = result.c_messages_stickerSet();
list.reserve(d.vpacks.v.size());
for_const (auto &mtpPack, d.vpacks.v) {
list.reserve(d.vpacks().v.size());
for_const (auto &mtpPack, d.vpacks().v) {
auto &pack = mtpPack.c_stickerPack();
for_const (auto &documentId, pack.vdocuments.v) {
for_const (auto &documentId, pack.vdocuments().v) {
if (documentId.v == document->id) {
if (auto emoji = Ui::Emoji::Find(qs(mtpPack.c_stickerPack().vemoticon))) {
list.push_back(emoji);
if (const auto emoji = Ui::Emoji::Find(qs(mtpPack.c_stickerPack().vemoticon()))) {
list.emplace_back(emoji);
}
break;
}
@@ -435,9 +435,9 @@ void SetPackAndEmoji(
for_const (auto &mtpPack, packs) {
Assert(mtpPack.type() == mtpc_stickerPack);
auto &pack = mtpPack.c_stickerPack();
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon()))) {
emoji = emoji->original();
auto &stickers = pack.vdocuments.v;
auto &stickers = pack.vdocuments().v;
auto p = Pack();
p.reserve(stickers.size());
@@ -584,49 +584,48 @@ void FeaturedSetsReceived(
switch (setData.type()) {
case mtpc_stickerSetCovered: {
auto &d = setData.c_stickerSetCovered();
if (d.vset.type() == mtpc_stickerSet) {
set = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
set = &d.vset().c_stickerSet();
}
} break;
case mtpc_stickerSetMultiCovered: {
auto &d = setData.c_stickerSetMultiCovered();
if (d.vset.type() == mtpc_stickerSet) {
set = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
set = &d.vset().c_stickerSet();
}
} break;
}
if (set) {
auto it = sets.find(set->vid.v);
auto it = sets.find(set->vid().v);
const auto title = GetSetTitle(*set);
const auto installDate = set->has_installed_date()
? set->vinstalled_date.v
: TimeId(0);
const auto thumbnail = set->has_thumb()
? Images::Create(*set, set->vthumb)
const auto installDate = set->vinstalled_date().value_or_empty();
const auto thumb = set->vthumb();
const auto thumbnail = thumb
? Images::Create(*set, *thumb)
: ImagePtr();
if (it == sets.cend()) {
auto setClientFlags = MTPDstickerSet_ClientFlag::f_featured
| MTPDstickerSet_ClientFlag::f_not_loaded;
if (unreadMap.contains(set->vid.v)) {
if (unreadMap.contains(set->vid().v)) {
setClientFlags |= MTPDstickerSet_ClientFlag::f_unread;
}
it = sets.insert(set->vid.v, Set(
set->vid.v,
set->vaccess_hash.v,
it = sets.insert(set->vid().v, Set(
set->vid().v,
set->vaccess_hash().v,
title,
qs(set->vshort_name),
set->vcount.v,
set->vhash.v,
set->vflags.v | setClientFlags,
qs(set->vshort_name()),
set->vcount().v,
set->vhash().v,
set->vflags().v | setClientFlags,
installDate,
thumbnail));
} else {
it->access = set->vaccess_hash.v;
it->access = set->vaccess_hash().v;
it->title = title;
it->shortName = qs(set->vshort_name);
it->shortName = qs(set->vshort_name());
auto clientFlags = it->flags & (MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_unread | MTPDstickerSet_ClientFlag::f_not_loaded | MTPDstickerSet_ClientFlag::f_special);
it->flags = set->vflags.v | clientFlags;
it->flags = set->vflags().v | clientFlags;
it->flags |= MTPDstickerSet_ClientFlag::f_featured;
it->installDate = installDate;
it->thumbnail = thumbnail;
@@ -635,15 +634,15 @@ void FeaturedSetsReceived(
} else {
it->flags &= ~MTPDstickerSet_ClientFlag::f_unread;
}
if (it->count != set->vcount.v || it->hash != set->vhash.v || it->emoji.isEmpty()) {
it->count = set->vcount.v;
it->hash = set->vhash.v;
if (it->count != set->vcount().v || it->hash != set->vhash().v || it->emoji.isEmpty()) {
it->count = set->vcount().v;
it->hash = set->vhash().v;
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded; // need to request this set
}
}
setsOrder.push_back(set->vid.v);
setsOrder.push_back(set->vid().v);
if (it->stickers.isEmpty() || (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
setsToRequest.emplace(set->vid.v, set->vaccess_hash.v);
setsToRequest.emplace(set->vid().v, set->vaccess_hash().v);
}
}
}
@@ -765,7 +764,7 @@ std::vector<not_null<DocumentData*>> GetListByEmoji(
const auto sticker = document->sticker();
if (sticker->set.type() == mtpc_inputStickerSetID) {
const auto setId = sticker->set.c_inputStickerSetID().vid.v;
const auto setId = sticker->set.c_inputStickerSetID().vid().v;
const auto setIt = sets.find(setId);
if (setIt != sets.end()) {
return InstallDateAdjusted(setIt->installDate, document);
@@ -874,7 +873,7 @@ std::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
return std::nullopt;
}
auto &sets = Auth().data().stickerSets();
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid().v);
if (it == sets.cend()) {
return std::nullopt;
}
@@ -894,43 +893,45 @@ std::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
Set *FeedSet(const MTPDstickerSet &set) {
auto &sets = Auth().data().stickerSetsRef();
auto it = sets.find(set.vid.v);
auto it = sets.find(set.vid().v);
auto title = GetSetTitle(set);
auto flags = MTPDstickerSet::Flags(0);
const auto thumb = set.vthumb();
const auto thumbnail = thumb ? Images::Create(set, *thumb) : ImagePtr();
if (it == sets.cend()) {
it = sets.insert(set.vid.v, Stickers::Set(
set.vid.v,
set.vaccess_hash.v,
it = sets.insert(set.vid().v, Stickers::Set(
set.vid().v,
set.vaccess_hash().v,
title,
qs(set.vshort_name),
set.vcount.v,
set.vhash.v,
set.vflags.v | MTPDstickerSet_ClientFlag::f_not_loaded,
set.has_installed_date() ? set.vinstalled_date.v : TimeId(0),
set.has_thumb() ? Images::Create(set, set.vthumb) : ImagePtr()));
qs(set.vshort_name()),
set.vcount().v,
set.vhash().v,
set.vflags().v | MTPDstickerSet_ClientFlag::f_not_loaded,
set.vinstalled_date().value_or_empty(),
thumbnail));
} else {
it->access = set.vaccess_hash.v;
it->access = set.vaccess_hash().v;
it->title = title;
it->shortName = qs(set.vshort_name);
it->shortName = qs(set.vshort_name());
flags = it->flags;
auto clientFlags = it->flags
& (MTPDstickerSet_ClientFlag::f_featured
| MTPDstickerSet_ClientFlag::f_unread
| MTPDstickerSet_ClientFlag::f_not_loaded
| MTPDstickerSet_ClientFlag::f_special);
it->flags = set.vflags.v | clientFlags;
it->installDate = set.has_installed_date()
? (set.vinstalled_date.v ? set.vinstalled_date.v : unixtime())
it->flags = set.vflags().v | clientFlags;
const auto installDate = set.vinstalled_date();
it->installDate = installDate
? (installDate->v ? installDate->v : unixtime())
: TimeId(0);
it->thumbnail = set.has_thumb()
? Images::Create(set, set.vthumb)
: ImagePtr();
if (it->count != set.vcount.v
|| it->hash != set.vhash.v
it->thumbnail = thumbnail;
if (it->count != set.vcount().v
|| it->hash != set.vhash().v
|| it->emoji.isEmpty()) {
it->count = set.vcount.v;
it->hash = set.vhash.v;
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded; // need to request this set
// Need to request this set.
it->count = set.vcount().v;
it->hash = set.vhash().v;
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded;
}
}
auto changedFlags = (flags ^ it->flags);
@@ -949,20 +950,20 @@ Set *FeedSet(const MTPDstickerSet &set) {
Set *FeedSetFull(const MTPmessages_StickerSet &data) {
Expects(data.type() == mtpc_messages_stickerSet);
Expects(data.c_messages_stickerSet().vset.type() == mtpc_stickerSet);
Expects(data.c_messages_stickerSet().vset().type() == mtpc_stickerSet);
const auto &d = data.c_messages_stickerSet();
const auto &s = d.vset.c_stickerSet();
const auto &s = d.vset().c_stickerSet();
auto &sets = Auth().data().stickerSetsRef();
auto it = sets.find(s.vid.v);
auto it = sets.find(s.vid().v);
const auto wasArchived = (it->flags & MTPDstickerSet::Flag::f_archived);
auto set = FeedSet(s);
set->flags &= ~MTPDstickerSet_ClientFlag::f_not_loaded;
auto &d_docs = d.vdocuments.v;
auto &d_docs = d.vdocuments().v;
auto custom = sets.find(Stickers::CustomSetId);
auto inputSet = MTP_inputStickerSetID(
MTP_long(set->id),
@@ -1009,14 +1010,14 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
} else {
set->stickers = pack;
set->emoji.clear();
auto &v = d.vpacks.v;
auto &v = d.vpacks().v;
for (auto i = 0, l = v.size(); i != l; ++i) {
if (v[i].type() != mtpc_stickerPack) continue;
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();
auto &stickers = pack.vdocuments.v;
auto &stickers = pack.vdocuments().v;
Pack p;
p.reserve(stickers.size());
@@ -1058,8 +1059,8 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
void NewSetReceived(const MTPmessages_StickerSet &data) {
bool writeArchived = false;
const auto &set = data.c_messages_stickerSet();
const auto &s = set.vset.c_stickerSet();
if (!s.has_installed_date()) {
const auto &s = set.vset().c_stickerSet();
if (!s.vinstalled_date()) {
LOG(("API Error: "
"updateNewStickerSet without install_date flag."));
return;
@@ -1071,20 +1072,20 @@ void NewSetReceived(const MTPmessages_StickerSet &data) {
return;
}
auto &order = Auth().data().stickerSetsOrderRef();
int32 insertAtIndex = 0, currentIndex = order.indexOf(s.vid.v);
int32 insertAtIndex = 0, currentIndex = order.indexOf(s.vid().v);
if (currentIndex != insertAtIndex) {
if (currentIndex > 0) {
order.removeAt(currentIndex);
}
order.insert(insertAtIndex, s.vid.v);
order.insert(insertAtIndex, s.vid().v);
}
FeedSetFull(data);
}
QString GetSetTitle(const MTPDstickerSet &s) {
auto title = qs(s.vtitle);
if ((s.vflags.v & MTPDstickerSet::Flag::f_official) && !title.compare(qstr("Great Minds"), Qt::CaseInsensitive)) {
auto title = qs(s.vtitle());
if ((s.vflags().v & MTPDstickerSet::Flag::f_official) && !title.compare(qstr("Great Minds"), Qt::CaseInsensitive)) {
return tr::lng_stickers_default_set(tr::now);
}
return title;

View File

@@ -1250,22 +1250,22 @@ void StickersListWidget::searchResultsDone(
std::vector<uint64>()).first;
}
auto &d = result.c_messages_foundStickerSets();
for (const auto &stickerSet : d.vsets.v) {
for (const auto &stickerSet : d.vsets().v) {
const MTPDstickerSet *setData = nullptr;
Stickers::Pack covers;
switch (stickerSet.type()) {
case mtpc_stickerSetCovered: {
auto &d = stickerSet.c_stickerSetCovered();
if (d.vset.type() == mtpc_stickerSet) {
setData = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
setData = &d.vset().c_stickerSet();
}
} break;
case mtpc_stickerSetMultiCovered: {
auto &d = stickerSet.c_stickerSetMultiCovered();
if (d.vset.type() == mtpc_stickerSet) {
setData = &d.vset.c_stickerSet();
if (d.vset().type() == mtpc_stickerSet) {
setData = &d.vset().c_stickerSet();
}
for (const auto &cover : d.vcovers.v) {
for (const auto &cover : d.vcovers().v) {
const auto document = Auth().data().processDocument(cover);
if (document->sticker()) {
covers.push_back(document);
@@ -2408,7 +2408,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
}
auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID();
auto &sets = Auth().data().stickerSets();
auto it = sets.constFind(set.vid.v);
auto it = sets.constFind(set.vid().v);
if (it != sets.cend()) {
auto isInstalled = (it->flags & MTPDstickerSet::Flag::f_installed_date)
&& !(it->flags & MTPDstickerSet::Flag::f_archived);
@@ -2430,10 +2430,10 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
}
return;
} else if (!isShownHere(hidden)
|| _megagroupSetIdRequested == set.vid.v) {
|| _megagroupSetIdRequested == set.vid().v) {
return;
}
_megagroupSetIdRequested = set.vid.v;
_megagroupSetIdRequested = set.vid().v;
request(MTPmessages_GetStickerSet(
_megagroupSet->mgInfo->stickerSet
)).done([=](const MTPmessages_StickerSet &result) {
@@ -2746,7 +2746,7 @@ void StickersListWidget::displaySet(uint64 setId) {
});
return;
} else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) {
setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid.v;
setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v;
} else {
return;
}