From dba677dcc7e60dd782da096bfcea5a537a242220 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 29 Mar 2019 15:25:10 +0400 Subject: [PATCH] Filter emoji languages by server. --- .../chat_helpers/emoji_keywords.cpp | 25 +++++++++++++++---- .../SourceFiles/chat_helpers/emoji_keywords.h | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index d4ab0a696..4be4d8d44 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -426,7 +426,7 @@ void EmojiKeywords::apiChanged(ApiWrap *api) { refresh(); }, _suggestedChangeLifetime); } else { - _remoteListRequestId = 0; + _langsRequestId = 0; _suggestedChangeLifetime.destroy(); } for (const auto &[language, item] : _data) { @@ -484,10 +484,25 @@ void EmojiKeywords::refreshRemoteList() { setRemoteList({}); return; } - _api->request(base::take(_remoteListRequestId)).cancel(); - //_remoteListRequestId = _api->request() // #TODO emoji - setRemoteList(base::duplicate(_localList)); - auto list = _localList; + _api->request(base::take(_langsRequestId)).cancel(); + auto languages = QVector(); + for (const auto &id : _localList) { + languages.push_back(MTP_string(id)); + } + _langsRequestId = _api->request(MTPmessages_GetEmojiKeywordsLanguages( + MTP_vector(languages) + )).done([=](const MTPVector &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 &&list) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.h b/Telegram/SourceFiles/chat_helpers/emoji_keywords.h index 9fe5791d7..bdd03822f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.h @@ -60,7 +60,7 @@ private: ApiWrap *_api = nullptr; std::vector _localList; std::vector _remoteList; - mtpRequestId _remoteListRequestId = 0; + mtpRequestId _langsRequestId = 0; base::flat_map> _data; rpl::event_stream<> _refreshed;