Add td_api::quickReplyMessage.

This commit is contained in:
levlam 2024-02-21 22:43:29 +03:00
parent 768afb8815
commit 4fff9a0417
3 changed files with 72 additions and 9 deletions

View File

@ -3722,6 +3722,18 @@ storyInteraction actor_id:MessageSender interaction_date:int32 block_list:BlockL
storyInteractions total_count:int32 total_forward_count:int32 total_reaction_count:int32 interactions:vector<storyInteraction> next_offset:string = StoryInteractions; storyInteractions total_count:int32 total_forward_count:int32 total_reaction_count:int32 interactions:vector<storyInteraction> next_offset:string = StoryInteractions;
//@description Describes a message that can be used for quick reply
//@id Unique message identifier among all quick replies
//@sending_state The sending state of the message; may be null if the message isn't being sent and didn't fail to be sent
//@forward_info Information about the initial message sender; may be null if none or unknown
//@reply_to_message_id Information about the identifier of the quick reply message to which the message replies
//@self_destruct_type The message's self-destruct type; may be null if none
//@via_bot_user_id If non-zero, the user identifier of the bot through which this message was sent
//@media_album_id Unique identifier of an album this message belongs to. Only audios, documents, photos and videos can be grouped together in albums
//@content Content of the message
quickReplyMessage id:int53 sending_state:MessageSendingState forward_info:messageForwardInfo reply_to_message_id:int53 self_destruct_type:MessageSelfDestructType via_bot_user_id:int53 media_album_id:int64 content:MessageContent = QuickReplyMessage;
//@class PublicForward @description Describes a public forward or repost of a story //@class PublicForward @description Describes a public forward or repost of a story
//@description Contains a public forward as a message @message Information about the message //@description Contains a public forward as a message @message Information about the message

View File

@ -7,6 +7,7 @@
#include "td/telegram/QuickReplyManager.h" #include "td/telegram/QuickReplyManager.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h" #include "td/telegram/Dependencies.h"
#include "td/telegram/DialogManager.h" #include "td/telegram/DialogManager.h"
#include "td/telegram/MessageContent.h" #include "td/telegram/MessageContent.h"
@ -24,12 +25,6 @@ void QuickReplyManager::tear_down() {
parent_.reset(); parent_.reset();
} }
td_api::object_ptr<td_api::MessageContent> QuickReplyManager::get_quick_reply_message_message_content_object(
const QuickReplyMessage *m) const {
return get_message_content_object(m->content.get(), td_, DialogId(), 0, m->is_content_secret, true, -1,
m->invert_media, m->disable_web_page_preview);
}
unique_ptr<QuickReplyManager::QuickReplyMessage> QuickReplyManager::create_message( unique_ptr<QuickReplyManager::QuickReplyMessage> QuickReplyManager::create_message(
telegram_api::object_ptr<telegram_api::Message> message_ptr, const char *source) const { telegram_api::object_ptr<telegram_api::Message> message_ptr, const char *source) const {
LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr); LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr);
@ -162,4 +157,53 @@ void QuickReplyManager::add_quick_reply_message_dependencies(Dependencies &depen
add_message_content_dependencies(dependencies, m->content.get(), is_bot); add_message_content_dependencies(dependencies, m->content.get(), is_bot);
} }
bool QuickReplyManager::can_resend_message(const QuickReplyMessage *m) const {
if (m->send_error_code != 429) {
return false;
}
if (m->forward_info != nullptr || m->real_forward_from_dialog_id.is_valid()) {
return false;
}
if (m->via_bot_user_id.is_valid() || m->hide_via_bot) {
return false;
}
return true;
}
td_api::object_ptr<td_api::MessageSendingState> QuickReplyManager::get_message_sending_state_object(
const QuickReplyMessage *m) const {
CHECK(m != nullptr);
if (m->message_id.is_yet_unsent()) {
return td_api::make_object<td_api::messageSendingStatePending>(m->sending_id);
}
if (m->is_failed_to_send) {
auto can_retry = can_resend_message(m);
auto error_code = m->send_error_code > 0 ? m->send_error_code : 400;
auto need_another_reply_quote =
can_retry && error_code == 400 && m->send_error_message == CSlice("QUOTE_TEXT_INVALID");
return td_api::make_object<td_api::messageSendingStateFailed>(
td_api::make_object<td_api::error>(error_code, m->send_error_message), can_retry, false,
need_another_reply_quote, false, max(m->try_resend_at - Time::now(), 0.0));
}
return nullptr;
}
td_api::object_ptr<td_api::MessageContent> QuickReplyManager::get_quick_reply_message_message_content_object(
const QuickReplyMessage *m) const {
return get_message_content_object(m->content.get(), td_, DialogId(), 0, m->is_content_secret, true, -1,
m->invert_media, m->disable_web_page_preview);
}
td_api::object_ptr<td_api::quickReplyMessage> QuickReplyManager::get_quick_reply_message_object(
const QuickReplyMessage *m, const char *source) const {
CHECK(m != nullptr);
auto forward_info =
m->forward_info == nullptr ? nullptr : m->forward_info->get_message_forward_info_object(td_, false);
return td_api::make_object<td_api::quickReplyMessage>(
m->message_id.get(), get_message_sending_state_object(m), std::move(forward_info), m->reply_to_message_id.get(),
m->ttl.get_message_self_destruct_type_object(),
td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"), m->media_album_id,
get_quick_reply_message_message_content_object(m));
}
} // namespace td } // namespace td

View File

@ -81,14 +81,21 @@ class QuickReplyManager final : public Actor {
void tear_down() final; void tear_down() final;
td_api::object_ptr<td_api::MessageContent> get_quick_reply_message_message_content_object(
const QuickReplyMessage *m) const;
void add_quick_reply_message_dependencies(Dependencies &dependencies, const QuickReplyMessage *m) const; void add_quick_reply_message_dependencies(Dependencies &dependencies, const QuickReplyMessage *m) const;
unique_ptr<QuickReplyMessage> create_message(telegram_api::object_ptr<telegram_api::Message> message_ptr, unique_ptr<QuickReplyMessage> create_message(telegram_api::object_ptr<telegram_api::Message> message_ptr,
const char *source) const; const char *source) const;
bool can_resend_message(const QuickReplyMessage *m) const;
td_api::object_ptr<td_api::MessageSendingState> get_message_sending_state_object(const QuickReplyMessage *m) const;
td_api::object_ptr<td_api::MessageContent> get_quick_reply_message_message_content_object(
const QuickReplyMessage *m) const;
td_api::object_ptr<td_api::quickReplyMessage> get_quick_reply_message_object(const QuickReplyMessage *m,
const char *source) const;
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;
}; };