Add td_api::getEmojiSuggestionsUrl.

GitOrigin-RevId: 5e69942a3996e6e7354567b658eabcb32ccb1b4b
This commit is contained in:
levlam 2019-05-21 22:44:13 +03:00
parent e1d787c7d9
commit 0cdac3fd83
7 changed files with 110 additions and 2 deletions

View File

@ -3512,6 +3512,9 @@ getStickerEmojis sticker:InputFile = Emojis;
//@description Searches for emojis by a short text. Supported only if the file database is enabled @text Text to search for @exact_match True, if only emojis, which exactly match text needs to be returned
searchEmojis text:string exact_match:Bool = Emojis;
//@description Returns an HTTP URL which can be used to automatically log in into translation platform and suggest new emoji replacements. The URL will be valid for 30 seconds after generation @language_code Language code for which the emoji replacements will be suggested
getEmojiSuggestionsUrl language_code:string = HttpUrl;
//@description Returns saved animations
getSavedAnimations = Animations;
@ -3651,7 +3654,7 @@ getSupportUser = User;
//@description Returns backgrounds installed by the user
getBackgrounds = Backgrounds;
//@description Constructs persistent URL for a background @name Background name @type Background type
//@description Constructs a persistent HTTP URL for a background @name Background name @type Background type
getBackgroundUrl name:string type:BackgroundType = HttpUrl;
//@description Searches for a background by its name @name The name of the background
@ -3747,7 +3750,7 @@ changeChatReportSpamState chat_id:int53 is_spam_chat:Bool = Ok;
reportChat chat_id:int53 reason:ChatReportReason message_ids:vector<int53> = Ok;
//@description Returns URL with the chat statistics. Currently this method can be used only for channels @chat_id Chat identifier @parameters Parameters from "tg://statsrefresh?params=******" link @is_dark Pass true if a URL with the dark theme must be returned
//@description Returns an HTTP URL with the chat statistics. Currently this method can be used only for channels @chat_id Chat identifier @parameters Parameters from "tg://statsrefresh?params=******" link @is_dark Pass true if a URL with the dark theme must be returned
getChatStatisticsUrl chat_id:int53 parameters:string is_dark:Bool = HttpUrl;

Binary file not shown.

View File

@ -194,6 +194,32 @@ class GetEmojiKeywordsDifferenceQuery : public Td::ResultHandler {
}
};
class GetEmojiUrlQuery : public Td::ResultHandler {
Promise<telegram_api::object_ptr<telegram_api::emojiURL>> promise_;
public:
explicit GetEmojiUrlQuery(Promise<telegram_api::object_ptr<telegram_api::emojiURL>> &&promise)
: promise_(std::move(promise)) {
}
void send(const string &language_code) {
send_query(G()->net_query_creator().create(create_storer(telegram_api::messages_getEmojiURL(language_code))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_getEmojiURL>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
promise_.set_value(result_ptr.move_as_ok());
}
void on_error(uint64 id, Status status) override {
promise_.set_error(std::move(status));
}
};
class GetArchivedStickerSetsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
int64 offset_sticker_set_id_;
@ -5077,6 +5103,48 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
return result;
}
int64 StickersManager::get_emoji_suggestions_url(const string &language_code, Promise<Unit> &&promise) {
int64 random_id = 0;
do {
random_id = Random::secure_int64();
} while (random_id == 0 || emoji_suggestions_urls_.find(random_id) != emoji_suggestions_urls_.end());
emoji_suggestions_urls_[random_id]; // reserve place for result
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), random_id, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::emojiURL>> &&result) mutable {
send_closure(actor_id, &StickersManager::on_get_emoji_suggestions_url, random_id, std::move(promise),
std::move(result));
});
td_->create_handler<GetEmojiUrlQuery>(std::move(query_promise))->send(language_code);
return random_id;
}
void StickersManager::on_get_emoji_suggestions_url(
int64 random_id, Promise<Unit> &&promise, Result<telegram_api::object_ptr<telegram_api::emojiURL>> &&r_emoji_url) {
auto it = emoji_suggestions_urls_.find(random_id);
CHECK(it != emoji_suggestions_urls_.end());
auto &result = it->second;
CHECK(result.empty());
if (r_emoji_url.is_error()) {
emoji_suggestions_urls_.erase(it);
return promise.set_error(r_emoji_url.move_as_error());
}
auto emoji_url = r_emoji_url.move_as_ok();
result = std::move(emoji_url->url_);
promise.set_value(Unit());
}
td_api::object_ptr<td_api::httpUrl> StickersManager::get_emoji_suggestions_url_result(int64 random_id) {
auto it = emoji_suggestions_urls_.find(random_id);
CHECK(it != emoji_suggestions_urls_.end());
auto result = td_api::make_object<td_api::httpUrl>(it->second);
emoji_suggestions_urls_.erase(it);
return result;
}
string StickersManager::remove_emoji_modifiers(string emoji) {
static const Slice modifiers[] = {u8"\uFE0E" /* variation selector-15 */,
u8"\uFE0F" /* variation selector-16 */,

View File

@ -197,6 +197,10 @@ class StickersManager : public Actor {
vector<string> search_emojis(const string &text, bool exact_match, bool force, Promise<Unit> &&promise);
int64 get_emoji_suggestions_url(const string &language_code, Promise<Unit> &&promise);
td_api::object_ptr<td_api::httpUrl> get_emoji_suggestions_url_result(int64 random_id);
void reload_installed_sticker_sets(bool is_masks, bool force);
void reload_featured_sticker_sets(bool force);
@ -502,6 +506,9 @@ class StickersManager : public Actor {
const string &language_code, int32 from_version,
Result<telegram_api::object_ptr<telegram_api::emojiKeywordsDifference>> &&result);
void on_get_emoji_suggestions_url(int64 random_id, Promise<Unit> &&promise,
Result<telegram_api::object_ptr<telegram_api::emojiURL>> &&r_emoji_url);
static string remove_emoji_modifiers(string emoji);
Td *td_;
@ -586,6 +593,7 @@ class StickersManager : public Actor {
std::unordered_map<string, double> emoji_language_code_last_difference_times_;
std::unordered_map<string, vector<Promise<Unit>>> load_emoji_keywords_queries_;
std::unordered_map<string, vector<Promise<Unit>>> load_language_codes_queries_;
std::unordered_map<int64, string> emoji_suggestions_urls_;
};
} // namespace td

View File

@ -2628,6 +2628,25 @@ class SearchEmojisRequest : public RequestActor<> {
}
};
class GetEmojiSuggestionsUrlRequest : public RequestOnceActor {
string language_code_;
int64 random_id_;
void do_run(Promise<Unit> &&promise) override {
random_id_ = td->stickers_manager_->get_emoji_suggestions_url(language_code_, std::move(promise));
}
void do_send_result() override {
send_result(td->stickers_manager_->get_emoji_suggestions_url_result(random_id_));
}
public:
GetEmojiSuggestionsUrlRequest(ActorShared<Td> td, uint64 request_id, string &&language_code)
: RequestOnceActor(std::move(td), request_id), language_code_(std::move(language_code)) {
}
};
class GetSavedAnimationsRequest : public RequestActor<> {
vector<FileId> animation_ids_;
@ -6365,6 +6384,12 @@ void Td::on_request(uint64 id, td_api::searchEmojis &request) {
CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), request.exact_match_);
}
void Td::on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.language_code_);
CREATE_REQUEST(GetEmojiSuggestionsUrlRequest, std::move(request.language_code_));
}
void Td::on_request(uint64 id, const td_api::getSavedAnimations &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetSavedAnimationsRequest);

View File

@ -812,6 +812,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::searchEmojis &request);
void on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request);
void on_request(uint64 id, const td_api::getFavoriteStickers &request);
void on_request(uint64 id, td_api::addFavoriteSticker &request);

View File

@ -2214,6 +2214,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::searchEmojis>(args, false));
} else if (op == "see") {
send_request(td_api::make_object<td_api::searchEmojis>(args, true));
} else if (op == "gesu") {
send_request(td_api::make_object<td_api::getEmojiSuggestionsUrl>(args));
} else {
op_not_found_count++;
}