Check emoji in incoming chatActionEnjoyingAnimations.
This commit is contained in:
parent
db18baa503
commit
3883ffcc75
@ -444,6 +444,13 @@ int32 DialogAction::get_importing_messages_action_progress() const {
|
||||
return progress_;
|
||||
}
|
||||
|
||||
string DialogAction::get_enjoying_animations_emoji() const {
|
||||
if (type_ == Type::EnjoyingAnimations) {
|
||||
return emoji_;
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
DialogAction::ClickingAnimateEmojiInfo DialogAction::get_clicking_animated_emoji_action_info() const {
|
||||
ClickingAnimateEmojiInfo result;
|
||||
if (type_ == Type::ClickingAnimatedEmoji) {
|
||||
|
@ -76,6 +76,8 @@ class DialogAction {
|
||||
|
||||
int32 get_importing_messages_action_progress() const;
|
||||
|
||||
string get_enjoying_animations_emoji() const;
|
||||
|
||||
struct ClickingAnimateEmojiInfo {
|
||||
int32 message_id;
|
||||
string emoji;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "td/telegram/Contact.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/Dependencies.h"
|
||||
#include "td/telegram/DialogAction.h"
|
||||
#include "td/telegram/DialogParticipant.h"
|
||||
#include "td/telegram/Document.h"
|
||||
#include "td/telegram/DocumentsManager.h"
|
||||
@ -5556,6 +5557,14 @@ StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet
|
||||
return td->stickers_manager_->add_sticker_set(std::move(input_sticker_set));
|
||||
}
|
||||
|
||||
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action) {
|
||||
auto emoji = action.get_enjoying_animations_emoji();
|
||||
if (emoji.empty()) {
|
||||
return false;
|
||||
}
|
||||
return !td->stickers_manager_->is_sent_animated_emoji_click(dialog_id, emoji);
|
||||
}
|
||||
|
||||
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date) {
|
||||
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, date);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
namespace td {
|
||||
|
||||
struct Dependencies;
|
||||
class DialogAction;
|
||||
class Game;
|
||||
struct Photo;
|
||||
class Td;
|
||||
@ -245,6 +246,8 @@ void on_sent_message_content(Td *td, const MessageContent *content);
|
||||
|
||||
StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set);
|
||||
|
||||
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action);
|
||||
|
||||
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);
|
||||
|
||||
void update_used_hashtags(Td *td, const MessageContent *content);
|
||||
|
@ -7113,6 +7113,11 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, MessageId top_th
|
||||
}
|
||||
}
|
||||
|
||||
if (is_unsent_animated_emoji_click(td_, dialog_id, action)) {
|
||||
LOG(DEBUG) << "Ignore unsent " << action;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!td_->contacts_manager_->have_min_user(user_id)) {
|
||||
LOG(DEBUG) << "Ignore " << action << " of unknown " << user_id;
|
||||
return;
|
||||
|
@ -1124,12 +1124,15 @@ class DeleteStickerFromSetQuery final : public Td::ResultHandler {
|
||||
|
||||
class SendAnimatedEmojiClicksQuery final : public Td::ResultHandler {
|
||||
DialogId dialog_id_;
|
||||
string emoji_;
|
||||
|
||||
public:
|
||||
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
|
||||
tl_object_ptr<telegram_api::SendMessageAction> &&action) {
|
||||
tl_object_ptr<telegram_api::sendMessageEmojiInteraction> &&action) {
|
||||
dialog_id_ = dialog_id;
|
||||
CHECK(input_peer != nullptr);
|
||||
CHECK(action != nullptr);
|
||||
emoji_ = action->emoticon_;
|
||||
|
||||
int32 flags = 0;
|
||||
send_query(G()->net_query_creator().create(
|
||||
@ -1149,6 +1152,8 @@ class SendAnimatedEmojiClicksQuery final : public Td::ResultHandler {
|
||||
if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SendAnimatedEmojiClicksQuery")) {
|
||||
LOG(INFO) << "Receive error for send animated emoji clicks: " << status;
|
||||
}
|
||||
|
||||
td->stickers_manager_->on_send_animated_emoji_clicks(dialog_id_, emoji_);
|
||||
}
|
||||
};
|
||||
|
||||
@ -4153,7 +4158,8 @@ void StickersManager::flush_pending_animated_emoji_clicks() {
|
||||
// includes deleted full_message_id
|
||||
return;
|
||||
}
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(full_message_id.get_dialog_id(), AccessRights::Write);
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -4171,10 +4177,50 @@ void StickersManager::flush_pending_animated_emoji_clicks() {
|
||||
}));
|
||||
|
||||
td_->create_handler<SendAnimatedEmojiClicksQuery>()->send(
|
||||
full_message_id.get_dialog_id(), std::move(input_peer),
|
||||
dialog_id, std::move(input_peer),
|
||||
make_tl_object<telegram_api::sendMessageEmojiInteraction>(
|
||||
emoji, full_message_id.get_message_id().get_server_message_id().get(),
|
||||
make_tl_object<telegram_api::dataJSON>(data)));
|
||||
|
||||
on_send_animated_emoji_clicks(dialog_id, emoji);
|
||||
}
|
||||
|
||||
void StickersManager::on_send_animated_emoji_clicks(DialogId dialog_id, const string &emoji) {
|
||||
flush_sent_animated_emoji_clicks();
|
||||
|
||||
if (!sent_animated_emoji_clicks_.empty() && sent_animated_emoji_clicks_.back().dialog_id == dialog_id &&
|
||||
sent_animated_emoji_clicks_.back().emoji == emoji) {
|
||||
sent_animated_emoji_clicks_.back().send_time = Time::now();
|
||||
return;
|
||||
}
|
||||
|
||||
SentAnimatedEmojiClicks clicks;
|
||||
clicks.send_time = Time::now();
|
||||
clicks.dialog_id = dialog_id;
|
||||
clicks.emoji = emoji;
|
||||
sent_animated_emoji_clicks_.push_back(std::move(clicks));
|
||||
}
|
||||
|
||||
void StickersManager::flush_sent_animated_emoji_clicks() {
|
||||
if (sent_animated_emoji_clicks_.empty()) {
|
||||
return;
|
||||
}
|
||||
auto min_send_time = Time::now() - 30.0;
|
||||
auto it = sent_animated_emoji_clicks_.begin();
|
||||
while (it != sent_animated_emoji_clicks_.end() && it->send_time <= min_send_time) {
|
||||
++it;
|
||||
}
|
||||
sent_animated_emoji_clicks_.erase(sent_animated_emoji_clicks_.begin(), it);
|
||||
}
|
||||
|
||||
bool StickersManager::is_sent_animated_emoji_click(DialogId dialog_id, const string &emoji) {
|
||||
flush_sent_animated_emoji_clicks();
|
||||
for (const auto &click : sent_animated_emoji_clicks_) {
|
||||
if (click.dialog_id == dialog_id && click.emoji == emoji) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Status StickersManager::on_animated_emoji_message_clicked(const string &emoji, FullMessageId full_message_id,
|
||||
|
@ -71,6 +71,10 @@ class StickersManager final : public Actor {
|
||||
void get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
||||
|
||||
void on_send_animated_emoji_clicks(DialogId dialog_id, const string &emoji);
|
||||
|
||||
bool is_sent_animated_emoji_click(DialogId dialog_id, const string &emoji);
|
||||
|
||||
Status on_animated_emoji_message_clicked(const string &emoji, FullMessageId full_message_id, string data);
|
||||
|
||||
void create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions,
|
||||
@ -598,6 +602,8 @@ class StickersManager final : public Actor {
|
||||
FullMessageId full_message_id, double start_time,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
||||
|
||||
void flush_sent_animated_emoji_clicks();
|
||||
|
||||
void flush_pending_animated_emoji_clicks();
|
||||
|
||||
void schedule_update_animated_emoji_clicked(const StickerSet *sticker_set, const string &emoji,
|
||||
@ -765,6 +771,13 @@ class StickersManager final : public Actor {
|
||||
FullMessageId last_clicked_animated_emoji_full_message_id_;
|
||||
std::vector<std::pair<int, double>> pending_animated_emoji_clicks_;
|
||||
|
||||
struct SentAnimatedEmojiClicks {
|
||||
double send_time = 0.0;
|
||||
DialogId dialog_id;
|
||||
string emoji;
|
||||
};
|
||||
std::vector<SentAnimatedEmojiClicks> sent_animated_emoji_clicks_;
|
||||
|
||||
std::shared_ptr<UploadStickerFileCallback> upload_sticker_file_callback_;
|
||||
|
||||
std::unordered_map<FileId, std::pair<UserId, Promise<Unit>>, FileIdHash> being_uploaded_files_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user