Add chatActionEnjoyingAnimations.

This commit is contained in:
levlam 2021-09-15 17:11:44 +03:00
parent dcd8f3bfd0
commit 499e903c95
5 changed files with 74 additions and 3 deletions

View File

@ -2069,6 +2069,9 @@ chatActionRecordingVideoNote = ChatAction;
//@description The user is uploading a video note @progress Upload progress, as a percentage //@description The user is uploading a video note @progress Upload progress, as a percentage
chatActionUploadingVideoNote progress:int32 = ChatAction; 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 //@description The user has canceled the previous action
chatActionCancel = ChatAction; chatActionCancel = ChatAction;

View File

@ -6,24 +6,53 @@
// //
#include "td/telegram/DialogAction.h" #include "td/telegram/DialogAction.h"
#include "td/telegram/misc.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
namespace td { 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) { void DialogAction::init(Type type) {
type_ = type; type_ = type;
progress_ = 0; progress_ = 0;
emoji_.clear();
} }
void DialogAction::init(Type type, int32 progress) { void DialogAction::init(Type type, int32 progress) {
type_ = type; type_ = type;
progress_ = clamp(progress, 0, 100); 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) { DialogAction::DialogAction(Type type, int32 progress) {
init(type, progress); init(type, progress);
} }
DialogAction::DialogAction(Type type, string emoji) {
init(type, std::move(emoji));
}
DialogAction::DialogAction(tl_object_ptr<td_api::ChatAction> &&action) { DialogAction::DialogAction(tl_object_ptr<td_api::ChatAction> &&action) {
if (action == nullptr) { if (action == nullptr) {
return; return;
@ -82,6 +111,11 @@ DialogAction::DialogAction(tl_object_ptr<td_api::ChatAction> &&action) {
case td_api::chatActionChoosingSticker::ID: case td_api::chatActionChoosingSticker::ID:
init(Type::ChoosingSticker); init(Type::ChoosingSticker);
break; break;
case td_api::chatActionEnjoyingAnimations::ID: {
auto enjoying_animations_action = move_tl_object_as<td_api::chatActionEnjoyingAnimations>(action);
init(Type::EnjoyingAnimations, std::move(enjoying_animations_action->emoji_));
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
break; break;
@ -95,7 +129,6 @@ DialogAction::DialogAction(tl_object_ptr<telegram_api::SendMessageAction> &&acti
break; break;
case telegram_api::sendMessageTypingAction::ID: case telegram_api::sendMessageTypingAction::ID:
case telegram_api::sendMessageEmojiInteraction::ID: case telegram_api::sendMessageEmojiInteraction::ID:
case telegram_api::sendMessageEmojiInteractionSeen::ID:
init(Type::Typing); init(Type::Typing);
break; break;
case telegram_api::sendMessageRecordVideoAction::ID: case telegram_api::sendMessageRecordVideoAction::ID:
@ -152,6 +185,11 @@ DialogAction::DialogAction(tl_object_ptr<telegram_api::SendMessageAction> &&acti
case telegram_api::sendMessageChooseStickerAction::ID: case telegram_api::sendMessageChooseStickerAction::ID:
init(Type::ChoosingSticker); init(Type::ChoosingSticker);
break; break;
case telegram_api::sendMessageEmojiInteractionSeen::ID: {
auto emoji_interaction_seen_action = move_tl_object_as<telegram_api::sendMessageEmojiInteractionSeen>(action);
init(Type::EnjoyingAnimations, std::move(emoji_interaction_seen_action->emoticon_));
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
break; break;
@ -192,6 +230,8 @@ tl_object_ptr<telegram_api::SendMessageAction> DialogAction::get_input_send_mess
return make_tl_object<telegram_api::sendMessageHistoryImportAction>(progress_); return make_tl_object<telegram_api::sendMessageHistoryImportAction>(progress_);
case Type::ChoosingSticker: case Type::ChoosingSticker:
return make_tl_object<telegram_api::sendMessageChooseStickerAction>(); return make_tl_object<telegram_api::sendMessageChooseStickerAction>();
case Type::EnjoyingAnimations:
return make_tl_object<telegram_api::sendMessageEmojiInteractionSeen>(emoji_);
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
@ -232,6 +272,8 @@ tl_object_ptr<secret_api::SendMessageAction> DialogAction::get_secret_input_send
return make_tl_object<secret_api::sendMessageTypingAction>(); return make_tl_object<secret_api::sendMessageTypingAction>();
case Type::ChoosingSticker: case Type::ChoosingSticker:
return make_tl_object<secret_api::sendMessageTypingAction>(); return make_tl_object<secret_api::sendMessageTypingAction>();
case Type::EnjoyingAnimations:
return make_tl_object<secret_api::sendMessageTypingAction>();
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
@ -268,6 +310,8 @@ tl_object_ptr<td_api::ChatAction> DialogAction::get_chat_action_object() const {
return td_api::make_object<td_api::chatActionUploadingVideoNote>(progress_); return td_api::make_object<td_api::chatActionUploadingVideoNote>(progress_);
case Type::ChoosingSticker: case Type::ChoosingSticker:
return td_api::make_object<td_api::chatActionChoosingSticker>(); return td_api::make_object<td_api::chatActionChoosingSticker>();
case Type::EnjoyingAnimations:
return td_api::make_object<td_api::chatActionEnjoyingAnimations>(emoji_);
case Type::ImportingMessages: case Type::ImportingMessages:
case Type::SpeakingInVoiceChat: case Type::SpeakingInVoiceChat:
default: default:
@ -418,6 +462,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &act
return "ImportingMessages"; return "ImportingMessages";
case DialogAction::Type::ChoosingSticker: case DialogAction::Type::ChoosingSticker:
return "ChoosingSticker"; return "ChoosingSticker";
case DialogAction::Type::EnjoyingAnimations:
return "EnjoyingAnimations";
default: default:
UNREACHABLE(); UNREACHABLE();
return "Cancel"; return "Cancel";
@ -427,6 +473,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &act
if (action.progress_ != 0) { if (action.progress_ != 0) {
string_builder << '(' << action.progress_ << "%)"; string_builder << '(' << action.progress_ << "%)";
} }
if (!action.emoji_.empty()) {
string_builder << '(' << action.emoji_ << ')';
}
return string_builder; return string_builder;
} }

View File

@ -33,17 +33,25 @@ class DialogAction {
UploadingVideoNote, UploadingVideoNote,
SpeakingInVoiceChat, SpeakingInVoiceChat,
ImportingMessages, ImportingMessages,
ChoosingSticker ChoosingSticker,
EnjoyingAnimations
}; };
Type type_ = Type::Cancel; Type type_ = Type::Cancel;
int32 progress_ = 0; int32 progress_ = 0;
string emoji_;
DialogAction(Type type, int32 progress); DialogAction(Type type, int32 progress);
DialogAction(Type type, string emoji);
void init(Type type); void init(Type type);
void init(Type type, int32 progress); void init(Type type, int32 progress);
void init(Type type, string emoji);
static bool is_valid_emoji(string &emoji);
public: public:
DialogAction() = default; DialogAction() = default;
@ -68,7 +76,7 @@ class DialogAction {
int32 get_importing_messages_action_progress() const; int32 get_importing_messages_action_progress() const;
friend bool operator==(const DialogAction &lhs, const DialogAction &rhs) { 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); friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &action);

View File

@ -2800,6 +2800,14 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty
CHECK(s->is_inited); CHECK(s->is_inited);
CHECK(s->is_loaded); 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 << ' ' LOG(INFO) << "Receive special sticker set " << type.type_ << ": " << sticker_set_id << ' ' << s->access_hash << ' '
<< s->short_name; << s->short_name;
auto &sticker_set = add_special_sticker_set(type.type_); auto &sticker_set = add_special_sticker_set(type.type_);

View File

@ -1321,6 +1321,9 @@ class CliClient final : public Actor {
if (action == "cs" || action == "choose_sticker") { if (action == "cs" || action == "choose_sticker") {
return td_api::make_object<td_api::chatActionChoosingSticker>(); return td_api::make_object<td_api::chatActionChoosingSticker>();
} }
if (begins_with(action, "ea")) {
return td_api::make_object<td_api::chatActionEnjoyingAnimations>(action.substr(2).str());
}
return td_api::make_object<td_api::chatActionTyping>(); return td_api::make_object<td_api::chatActionTyping>();
} }