Add td_api::getMessageEffects.
This commit is contained in:
parent
84adb67a06
commit
7b7d60a394
@ -1392,6 +1392,17 @@ messageInteractionInfo view_count:int32 forward_count:int32 reply_info:messageRe
|
|||||||
unreadReaction type:ReactionType sender_id:MessageSender is_big:Bool = UnreadReaction;
|
unreadReaction type:ReactionType sender_id:MessageSender is_big:Bool = UnreadReaction;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Contains information about an effect added to a message
|
||||||
|
//@id Unique identifier of the effect
|
||||||
|
//@static_icon Static icon for the effect in WEBP format; may be null if none
|
||||||
|
//@emoji Emoji corresponding to the effect that can be used if static icon isn't available
|
||||||
|
//@is_premium True, if Telegram Premium subscription is required to use the effect
|
||||||
|
messageEffect id:int64 static_icon:sticker emoji:string is_premium:Bool = MessageEffect;
|
||||||
|
|
||||||
|
//@description Contains a list of message effects @effects List of available message effects
|
||||||
|
messageEffects effects:vector<messageEffect> = MessageEffects;
|
||||||
|
|
||||||
|
|
||||||
//@class MessageSendingState @description Contains information about the sending state of the message
|
//@class MessageSendingState @description Contains information about the sending state of the message
|
||||||
|
|
||||||
//@description The message is being sent now, but has not yet been delivered to the server @sending_id Non-persistent message sending identifier, specified by the application
|
//@description The message is being sent now, but has not yet been delivered to the server @sending_id Non-persistent message sending identifier, specified by the application
|
||||||
@ -8382,6 +8393,9 @@ getSavedMessagesTags saved_messages_topic_id:int53 = SavedMessagesTags;
|
|||||||
//@description Changes label of a Saved Messages tag; for Telegram Premium users only @tag The tag which label will be changed @label New label for the tag; 0-12 characters
|
//@description Changes label of a Saved Messages tag; for Telegram Premium users only @tag The tag which label will be changed @label New label for the tag; 0-12 characters
|
||||||
setSavedMessagesTagLabel tag:ReactionType label:string = Ok;
|
setSavedMessagesTagLabel tag:ReactionType label:string = Ok;
|
||||||
|
|
||||||
|
//@description Returns effects that can be added to a message sent in a private chat
|
||||||
|
getMessageEffects = MessageEffects;
|
||||||
|
|
||||||
|
|
||||||
//@description Searches for a given quote in a text. Returns found quote start position in UTF-16 code units. Returns a 404 error if the quote is not found. Can be called synchronously
|
//@description Searches for a given quote in a text. Returns found quote start position in UTF-16 code units. Returns a 404 error if the quote is not found. Can be called synchronously
|
||||||
//@text Text in which to search for the quote
|
//@text Text in which to search for the quote
|
||||||
|
@ -246,6 +246,35 @@ class UpdateSavedReactionTagQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GetMessageAvailableEffectsQuery final : public Td::ResultHandler {
|
||||||
|
Promise<telegram_api::object_ptr<telegram_api::messages_AvailableEffects>> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetMessageAvailableEffectsQuery(
|
||||||
|
Promise<telegram_api::object_ptr<telegram_api::messages_AvailableEffects>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send() {
|
||||||
|
send_query(G()->net_query_creator().create(telegram_api::messages_getAvailableEffects(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_getAvailableEffects>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ptr = result_ptr.move_as_ok();
|
||||||
|
LOG(INFO) << "Receive result for GetMessageAvailableEffectsQuery: " << to_string(ptr);
|
||||||
|
promise_.set_value(std::move(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ReactionManager::SavedReactionTag::SavedReactionTag(telegram_api::object_ptr<telegram_api::savedReactionTag> &&tag)
|
ReactionManager::SavedReactionTag::SavedReactionTag(telegram_api::object_ptr<telegram_api::savedReactionTag> &&tag)
|
||||||
: reaction_type_(tag->reaction_)
|
: reaction_type_(tag->reaction_)
|
||||||
, hash_(reaction_type_.get_hash())
|
, hash_(reaction_type_.get_hash())
|
||||||
@ -1169,6 +1198,112 @@ void ReactionManager::set_saved_messages_tag_title(ReactionType reaction_type, s
|
|||||||
td_->create_handler<UpdateSavedReactionTagQuery>(std::move(query_promise))->send(reaction_type, title);
|
td_->create_handler<UpdateSavedReactionTagQuery>(std::move(query_promise))->send(reaction_type, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageEffect> ReactionManager::get_message_effect_object(const Effect &effect) const {
|
||||||
|
return td_api::make_object<td_api::messageEffect>(effect.id_,
|
||||||
|
td_->stickers_manager_->get_sticker_object(effect.static_icon_id_),
|
||||||
|
effect.emoji_, effect.is_premium_);
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageEffects> ReactionManager::get_message_effects_object() const {
|
||||||
|
auto effects =
|
||||||
|
transform(message_effects_.effects_, [&](const Effect &effect) { return get_message_effect_object(effect); });
|
||||||
|
return td_api::make_object<td_api::messageEffects>(std::move(effects));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReactionManager::get_message_effects(Promise<td_api::object_ptr<td_api::messageEffects>> &&promise) {
|
||||||
|
auto query_promise = PromiseCreator::lambda(
|
||||||
|
[actor_id = actor_id(this), promise = std::move(promise)](
|
||||||
|
Result<telegram_api::object_ptr<telegram_api::messages_AvailableEffects>> r_effects) mutable {
|
||||||
|
send_closure(actor_id, &ReactionManager::on_get_message_effects, std::move(r_effects), std::move(promise));
|
||||||
|
});
|
||||||
|
td_->create_handler<GetMessageAvailableEffectsQuery>(std::move(query_promise))->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReactionManager::on_get_message_effects(
|
||||||
|
Result<telegram_api::object_ptr<telegram_api::messages_AvailableEffects>> r_effects,
|
||||||
|
Promise<td_api::object_ptr<td_api::messageEffects>> promise) {
|
||||||
|
G()->ignore_result_if_closing(r_effects);
|
||||||
|
if (r_effects.is_error()) {
|
||||||
|
return promise.set_error(r_effects.move_as_error());
|
||||||
|
}
|
||||||
|
auto message_effects = r_effects.move_as_ok();
|
||||||
|
|
||||||
|
switch (message_effects->get_id()) {
|
||||||
|
case telegram_api::messages_availableEffectsNotModified::ID:
|
||||||
|
break;
|
||||||
|
case telegram_api::messages_availableEffects::ID: {
|
||||||
|
auto effects = telegram_api::move_object_as<telegram_api::messages_availableEffects>(message_effects);
|
||||||
|
FlatHashMap<int64, FileId> stickers;
|
||||||
|
for (auto &document : effects->documents_) {
|
||||||
|
auto sticker = td_->stickers_manager_->on_get_sticker_document(std::move(document), StickerFormat::Unknown);
|
||||||
|
if (sticker.first != 0 && sticker.second.is_valid()) {
|
||||||
|
stickers.emplace(sticker.first, sticker.second);
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << "Receive " << sticker.first << ' ' << sticker.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vector<Effect> new_effects;
|
||||||
|
for (const auto &available_effect : effects->effects_) {
|
||||||
|
Effect effect;
|
||||||
|
effect.id_ = available_effect->id_;
|
||||||
|
effect.emoji_ = std::move(available_effect->emoticon_);
|
||||||
|
effect.is_premium_ = available_effect->premium_required_;
|
||||||
|
if (available_effect->static_icon_id_ != 0) {
|
||||||
|
auto it = stickers.find(available_effect->static_icon_id_);
|
||||||
|
if (it == stickers.end()) {
|
||||||
|
LOG(ERROR) << "Can't find " << available_effect->static_icon_id_;
|
||||||
|
} else {
|
||||||
|
auto sticker_id = it->second;
|
||||||
|
if (td_->stickers_manager_->get_sticker_format(sticker_id) != StickerFormat::Webp) {
|
||||||
|
LOG(ERROR) << "Receive static sticker in wrong format";
|
||||||
|
} else {
|
||||||
|
effect.static_icon_id_ = sticker_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (available_effect->effect_sticker_id_ != 0) {
|
||||||
|
auto it = stickers.find(available_effect->effect_sticker_id_);
|
||||||
|
if (it == stickers.end()) {
|
||||||
|
LOG(ERROR) << "Can't find " << available_effect->effect_sticker_id_;
|
||||||
|
} else {
|
||||||
|
auto sticker_id = it->second;
|
||||||
|
if (td_->stickers_manager_->get_sticker_format(sticker_id) != StickerFormat::Tgs) {
|
||||||
|
LOG(ERROR) << "Receive effect sticker in wrong format";
|
||||||
|
} else {
|
||||||
|
effect.effect_sticker_id_ = sticker_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (available_effect->effect_animation_id_ != 0) {
|
||||||
|
auto it = stickers.find(available_effect->effect_animation_id_);
|
||||||
|
if (it == stickers.end()) {
|
||||||
|
LOG(ERROR) << "Can't find " << available_effect->effect_animation_id_;
|
||||||
|
} else {
|
||||||
|
auto sticker_id = it->second;
|
||||||
|
if (td_->stickers_manager_->get_sticker_format(sticker_id) != StickerFormat::Tgs) {
|
||||||
|
LOG(ERROR) << "Receive effect animation in wrong format";
|
||||||
|
} else {
|
||||||
|
effect.effect_animation_id_ = sticker_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (effect.is_valid()) {
|
||||||
|
new_effects.push_back(std::move(effect));
|
||||||
|
} else {
|
||||||
|
// LOG(ERROR) << "Receive " << to_string(effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message_effects_.effects_ = std::move(new_effects);
|
||||||
|
message_effects_.hash_ = effects->hash_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
promise.set_value(get_message_effects_object());
|
||||||
|
}
|
||||||
|
|
||||||
void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
void ReactionManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||||
if (td_->auth_manager_->is_bot()) {
|
if (td_->auth_manager_->is_bot()) {
|
||||||
return;
|
return;
|
||||||
|
@ -81,6 +81,8 @@ class ReactionManager final : public Actor {
|
|||||||
|
|
||||||
void set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise<Unit> &&promise);
|
void set_saved_messages_tag_title(ReactionType reaction_type, string title, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void get_message_effects(Promise<td_api::object_ptr<td_api::messageEffects>> &&promise);
|
||||||
|
|
||||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -189,6 +191,24 @@ class ReactionManager final : public Actor {
|
|||||||
void parse(ParserT &parser);
|
void parse(ParserT &parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Effect {
|
||||||
|
int64 id_ = 0;
|
||||||
|
string emoji_;
|
||||||
|
FileId static_icon_id_;
|
||||||
|
FileId effect_sticker_id_;
|
||||||
|
FileId effect_animation_id_;
|
||||||
|
bool is_premium_ = false;
|
||||||
|
|
||||||
|
bool is_valid() const {
|
||||||
|
return id_ != 0 && effect_sticker_id_.is_valid();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Effects {
|
||||||
|
int32 hash_ = 0;
|
||||||
|
vector<Effect> effects_;
|
||||||
|
};
|
||||||
|
|
||||||
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji) const;
|
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji) const;
|
||||||
|
|
||||||
ReactionList &get_reaction_list(ReactionListType reaction_list_type);
|
ReactionList &get_reaction_list(ReactionListType reaction_list_type);
|
||||||
@ -233,6 +253,13 @@ class ReactionManager final : public Actor {
|
|||||||
void send_update_saved_messages_tags(SavedMessagesTopicId saved_messages_topic_id, const SavedReactionTags *tags,
|
void send_update_saved_messages_tags(SavedMessagesTopicId saved_messages_topic_id, const SavedReactionTags *tags,
|
||||||
bool from_database = false);
|
bool from_database = false);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageEffect> get_message_effect_object(const Effect &effect) const;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageEffects> get_message_effects_object() const;
|
||||||
|
|
||||||
|
void on_get_message_effects(Result<telegram_api::object_ptr<telegram_api::messages_AvailableEffects>> r_effects,
|
||||||
|
Promise<td_api::object_ptr<td_api::messageEffects>> promise);
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
|
|
||||||
@ -254,6 +281,8 @@ class ReactionManager final : public Actor {
|
|||||||
FlatHashMap<SavedMessagesTopicId, vector<Promise<td_api::object_ptr<td_api::savedMessagesTags>>>,
|
FlatHashMap<SavedMessagesTopicId, vector<Promise<td_api::object_ptr<td_api::savedMessagesTags>>>,
|
||||||
SavedMessagesTopicIdHash>
|
SavedMessagesTopicIdHash>
|
||||||
pending_get_topic_saved_reaction_tags_queries_;
|
pending_get_topic_saved_reaction_tags_queries_;
|
||||||
|
|
||||||
|
Effects message_effects_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -2027,6 +2027,12 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const {
|
|||||||
return sticker->type_;
|
return sticker->type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StickerFormat StickersManager::get_sticker_format(FileId file_id) const {
|
||||||
|
const auto *sticker = get_sticker(file_id);
|
||||||
|
CHECK(sticker != nullptr);
|
||||||
|
return sticker->format_;
|
||||||
|
}
|
||||||
|
|
||||||
bool StickersManager::is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const {
|
bool StickersManager::is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const {
|
||||||
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
|
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
|
||||||
if (!sticker_id.is_valid()) {
|
if (!sticker_id.is_valid()) {
|
||||||
@ -7786,7 +7792,7 @@ Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_sticker(td
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), sticker_type, false);
|
return prepare_input_file(sticker->sticker_, ::td::get_sticker_format(sticker->format_), sticker_type, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_file(
|
Result<std::tuple<FileId, bool, bool>> StickersManager::prepare_input_file(
|
||||||
|
@ -71,6 +71,8 @@ class StickersManager final : public Actor {
|
|||||||
|
|
||||||
StickerType get_sticker_type(FileId file_id) const;
|
StickerType get_sticker_type(FileId file_id) const;
|
||||||
|
|
||||||
|
StickerFormat get_sticker_format(FileId file_id) const;
|
||||||
|
|
||||||
bool is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const;
|
bool is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const;
|
||||||
|
|
||||||
bool have_sticker(StickerSetId sticker_set_id, int64 sticker_id);
|
bool have_sticker(StickerSetId sticker_set_id, int64 sticker_id);
|
||||||
|
@ -5503,6 +5503,12 @@ void Td::on_request(uint64 id, td_api::setSavedMessagesTagLabel &request) {
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, td_api::getMessageEffects &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_REQUEST_PROMISE();
|
||||||
|
reaction_manager_->get_message_effects(std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) {
|
void Td::on_request(uint64 id, td_api::getMessagePublicForwards &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CLEAN_INPUT_STRING(request.offset_);
|
CLEAN_INPUT_STRING(request.offset_);
|
||||||
|
@ -831,6 +831,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::setSavedMessagesTagLabel &request);
|
void on_request(uint64 id, td_api::setSavedMessagesTagLabel &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, td_api::getMessageEffects &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getMessagePublicForwards &request);
|
void on_request(uint64 id, td_api::getMessagePublicForwards &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getStoryPublicForwards &request);
|
void on_request(uint64 id, td_api::getStoryPublicForwards &request);
|
||||||
|
@ -2957,6 +2957,8 @@ class CliClient final : public Actor {
|
|||||||
string label;
|
string label;
|
||||||
get_args(args, reaction, label);
|
get_args(args, reaction, label);
|
||||||
send_request(td_api::make_object<td_api::setSavedMessagesTagLabel>(as_reaction_type(reaction), label));
|
send_request(td_api::make_object<td_api::setSavedMessagesTagLabel>(as_reaction_type(reaction), label));
|
||||||
|
} else if (op == "gme") {
|
||||||
|
send_request(td_api::make_object<td_api::getMessageEffects>());
|
||||||
} else if (op == "gmpf") {
|
} else if (op == "gmpf") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
MessageId message_id;
|
MessageId message_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user