From 499e903c952b90b7b07c879cae579b32a3748bad Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 15 Sep 2021 17:11:44 +0300 Subject: [PATCH] Add chatActionEnjoyingAnimations. --- td/generate/scheme/td_api.tl | 3 ++ td/telegram/DialogAction.cpp | 51 ++++++++++++++++++++++++++++++++- td/telegram/DialogAction.h | 12 ++++++-- td/telegram/StickersManager.cpp | 8 ++++++ td/telegram/cli.cpp | 3 ++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 89a1e9d6e..558977306 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2069,6 +2069,9 @@ chatActionRecordingVideoNote = ChatAction; //@description The user is uploading a video note @progress Upload progress, as a percentage chatActionUploadingVideoNote progress:int32 = ChatAction; +//@description The user is viewing animations sent by the other party by clicking on animated emojies @emoji The animated emoji +chatActionEnjoyingAnimations emoji:string = ChatAction; + //@description The user has canceled the previous action chatActionCancel = ChatAction; diff --git a/td/telegram/DialogAction.cpp b/td/telegram/DialogAction.cpp index 763a9d0a3..041e13394 100644 --- a/td/telegram/DialogAction.cpp +++ b/td/telegram/DialogAction.cpp @@ -6,24 +6,53 @@ // #include "td/telegram/DialogAction.h" +#include "td/telegram/misc.h" + #include "td/utils/misc.h" namespace td { +bool DialogAction::is_valid_emoji(string &emoji) { + if (!clean_input_string(emoji)) { + return false; + } + emoji = remove_emoji_modifiers(emoji); + if (emoji.empty()) { + return false; + } + return true; +} + void DialogAction::init(Type type) { type_ = type; progress_ = 0; + emoji_.clear(); } void DialogAction::init(Type type, int32 progress) { type_ = type; progress_ = clamp(progress, 0, 100); + emoji_.clear(); +} + +void DialogAction::init(Type type, string emoji) { + if (is_valid_emoji(emoji)) { + type_ = type; + progress_ = 0; + emoji_ = std::move(emoji); + } else { + init(Type::Cancel); + } } DialogAction::DialogAction(Type type, int32 progress) { init(type, progress); } +DialogAction::DialogAction(Type type, string emoji) { + init(type, std::move(emoji)); +} + DialogAction::DialogAction(tl_object_ptr &&action) { if (action == nullptr) { return; @@ -82,6 +111,11 @@ DialogAction::DialogAction(tl_object_ptr &&action) { case td_api::chatActionChoosingSticker::ID: init(Type::ChoosingSticker); break; + case td_api::chatActionEnjoyingAnimations::ID: { + auto enjoying_animations_action = move_tl_object_as(action); + init(Type::EnjoyingAnimations, std::move(enjoying_animations_action->emoji_)); + break; + } default: UNREACHABLE(); break; @@ -95,7 +129,6 @@ DialogAction::DialogAction(tl_object_ptr &&acti break; case telegram_api::sendMessageTypingAction::ID: case telegram_api::sendMessageEmojiInteraction::ID: - case telegram_api::sendMessageEmojiInteractionSeen::ID: init(Type::Typing); break; case telegram_api::sendMessageRecordVideoAction::ID: @@ -152,6 +185,11 @@ DialogAction::DialogAction(tl_object_ptr &&acti case telegram_api::sendMessageChooseStickerAction::ID: init(Type::ChoosingSticker); break; + case telegram_api::sendMessageEmojiInteractionSeen::ID: { + auto emoji_interaction_seen_action = move_tl_object_as(action); + init(Type::EnjoyingAnimations, std::move(emoji_interaction_seen_action->emoticon_)); + break; + } default: UNREACHABLE(); break; @@ -192,6 +230,8 @@ tl_object_ptr DialogAction::get_input_send_mess return make_tl_object(progress_); case Type::ChoosingSticker: return make_tl_object(); + case Type::EnjoyingAnimations: + return make_tl_object(emoji_); default: UNREACHABLE(); return nullptr; @@ -232,6 +272,8 @@ tl_object_ptr DialogAction::get_secret_input_send return make_tl_object(); case Type::ChoosingSticker: return make_tl_object(); + case Type::EnjoyingAnimations: + return make_tl_object(); default: UNREACHABLE(); return nullptr; @@ -268,6 +310,8 @@ tl_object_ptr DialogAction::get_chat_action_object() const { return td_api::make_object(progress_); case Type::ChoosingSticker: return td_api::make_object(); + case Type::EnjoyingAnimations: + return td_api::make_object(emoji_); case Type::ImportingMessages: case Type::SpeakingInVoiceChat: default: @@ -418,6 +462,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &act return "ImportingMessages"; case DialogAction::Type::ChoosingSticker: return "ChoosingSticker"; + case DialogAction::Type::EnjoyingAnimations: + return "EnjoyingAnimations"; default: UNREACHABLE(); return "Cancel"; @@ -427,6 +473,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &act if (action.progress_ != 0) { string_builder << '(' << action.progress_ << "%)"; } + if (!action.emoji_.empty()) { + string_builder << '(' << action.emoji_ << ')'; + } return string_builder; } diff --git a/td/telegram/DialogAction.h b/td/telegram/DialogAction.h index 9b7962fe3..6cefea813 100644 --- a/td/telegram/DialogAction.h +++ b/td/telegram/DialogAction.h @@ -33,17 +33,25 @@ class DialogAction { UploadingVideoNote, SpeakingInVoiceChat, ImportingMessages, - ChoosingSticker + ChoosingSticker, + EnjoyingAnimations }; Type type_ = Type::Cancel; int32 progress_ = 0; + string emoji_; DialogAction(Type type, int32 progress); + DialogAction(Type type, string emoji); + void init(Type type); void init(Type type, int32 progress); + void init(Type type, string emoji); + + static bool is_valid_emoji(string &emoji); + public: DialogAction() = default; @@ -68,7 +76,7 @@ class DialogAction { int32 get_importing_messages_action_progress() const; friend bool operator==(const DialogAction &lhs, const DialogAction &rhs) { - return lhs.type_ == rhs.type_ && lhs.progress_ == rhs.progress_; + return lhs.type_ == rhs.type_ && lhs.progress_ == rhs.progress_ && lhs.emoji_ == rhs.emoji_; } friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &action); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 8ba79f5a9..1303a605e 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -2800,6 +2800,14 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty CHECK(s->is_inited); CHECK(s->is_loaded); + /* + if (type.type_ == SpecialStickerSetType::animated_emoji_click()) { + for (auto &sticker_id : s->sticker_ids) { + // TODO get supported emoji and their numbers + } + } + */ + LOG(INFO) << "Receive special sticker set " << type.type_ << ": " << sticker_set_id << ' ' << s->access_hash << ' ' << s->short_name; auto &sticker_set = add_special_sticker_set(type.type_); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index c5ed98eef..fc5bdb4ab 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1321,6 +1321,9 @@ class CliClient final : public Actor { if (action == "cs" || action == "choose_sticker") { return td_api::make_object(); } + if (begins_with(action, "ea")) { + return td_api::make_object(action.substr(2).str()); + } return td_api::make_object(); }