Filter emoji languages by server.

This commit is contained in:
John Preston 2019-03-29 15:25:10 +04:00
parent 24dcde2f87
commit dba677dcc7
2 changed files with 21 additions and 6 deletions

View File

@ -426,7 +426,7 @@ void EmojiKeywords::apiChanged(ApiWrap *api) {
refresh(); refresh();
}, _suggestedChangeLifetime); }, _suggestedChangeLifetime);
} else { } else {
_remoteListRequestId = 0; _langsRequestId = 0;
_suggestedChangeLifetime.destroy(); _suggestedChangeLifetime.destroy();
} }
for (const auto &[language, item] : _data) { for (const auto &[language, item] : _data) {
@ -484,10 +484,25 @@ void EmojiKeywords::refreshRemoteList() {
setRemoteList({}); setRemoteList({});
return; return;
} }
_api->request(base::take(_remoteListRequestId)).cancel(); _api->request(base::take(_langsRequestId)).cancel();
//_remoteListRequestId = _api->request() // #TODO emoji auto languages = QVector<MTPstring>();
setRemoteList(base::duplicate(_localList)); for (const auto &id : _localList) {
auto list = _localList; languages.push_back(MTP_string(id));
}
_langsRequestId = _api->request(MTPmessages_GetEmojiKeywordsLanguages(
MTP_vector<MTPstring>(languages)
)).done([=](const MTPVector<MTPEmojiLanguage> &result) {
setRemoteList(ranges::view::all(
result.v
) | ranges::view::transform([](const MTPEmojiLanguage &language) {
return language.match([&](const MTPDemojiLanguage &language) {
return qs(language.vlang_code);
});
}) | ranges::to_vector);
_langsRequestId = 0;
}).fail([=](const RPCError &error) {
_langsRequestId = 0;
}).send();
} }
void EmojiKeywords::setRemoteList(std::vector<QString> &&list) { void EmojiKeywords::setRemoteList(std::vector<QString> &&list) {

View File

@ -60,7 +60,7 @@ private:
ApiWrap *_api = nullptr; ApiWrap *_api = nullptr;
std::vector<QString> _localList; std::vector<QString> _localList;
std::vector<QString> _remoteList; std::vector<QString> _remoteList;
mtpRequestId _remoteListRequestId = 0; mtpRequestId _langsRequestId = 0;
base::flat_map<QString, std::unique_ptr<LangPack>> _data; base::flat_map<QString, std::unique_ptr<LangPack>> _data;
rpl::event_stream<> _refreshed; rpl::event_stream<> _refreshed;