Skip to content

Commit

Permalink
Allow to reply stories.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jun 8, 2023
1 parent 6116573 commit fa94aba
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 226 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ set(TDLIB_SOURCE
td/telegram/MessageEntity.cpp
td/telegram/MessageExtendedMedia.cpp
td/telegram/MessageId.cpp
td/telegram/MessageInputReplyTo.cpp
td/telegram/MessageReaction.cpp
td/telegram/MessageReplyHeader.cpp
td/telegram/MessageReplyInfo.cpp
Expand Down Expand Up @@ -659,6 +660,7 @@ set(TDLIB_SOURCE
td/telegram/MessageEntity.h
td/telegram/MessageExtendedMedia.h
td/telegram/MessageId.h
td/telegram/MessageInputReplyTo.h
td/telegram/MessageLinkInfo.h
td/telegram/MessageReaction.h
td/telegram/MessageReplyHeader.h
Expand Down
28 changes: 14 additions & 14 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -1131,12 +1131,12 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool n
//@class MessageReplyTo @description Contains information about the message or the story a message is replying to

//@description Describes a replied message
//@chat_id The identifier of the chat to which the replied message belongs. For example, messages in the Replies chat are replies to messages in different chats
//@chat_id The identifier of the chat to which the replied message belongs; ignored for outgoing replies. For example, messages in the Replies chat are replies to messages in different chats
//@message_id The identifier of the replied message
messageReplyToMessage chat_id:int53 message_id:int53 = MessageReplyTo;

//@description Describes a replied story @sender_user_id The identifier of the sender of the replied story @story_id The identifier of the replied story
messageReplyToStory sender_user_id:int53 story_id:int53 = MessageReplyTo;
//@description Describes a replied story @sender_user_id The identifier of the sender of the replied story. Currently, stories can be replied only in the corresponding private chats @story_id The identifier of the replied story
messageReplyToStory sender_user_id:int53 story_id:int32 = MessageReplyTo;


//@description Describes a message
Expand Down Expand Up @@ -4359,7 +4359,7 @@ notificationTypeNewSecretChat = NotificationType;
notificationTypeNewCall call_id:int32 = NotificationType;

//@description New message was received through a push notification
//@message_id The message identifier. The message will not be available in the chat history, but the ID can be used in viewMessages, or as reply_to_message_id
//@message_id The message identifier. The message will not be available in the chat history, but the ID can be used in viewMessages, or as a message to reply
//@sender_id Identifier of the sender of the message. Corresponding user or chat may be inaccessible
//@sender_name Name of the sender
//@is_outgoing True, if the message is outgoing
Expand Down Expand Up @@ -6376,20 +6376,20 @@ setChatMessageSender chat_id:int53 message_sender_id:MessageSender = Ok;
//@description Sends a message. Returns the sent message
//@chat_id Target chat
//@message_thread_id If not 0, a message thread identifier in which the message will be sent
//@reply_to_message_id Identifier of the replied message; 0 if none
//@reply_to Identifier of the replied message or story; pass null if none
//@options Options to be used to send the message; pass null to use default options
//@reply_markup Markup for replying to the message; pass null if none; for bots only
//@input_message_content The content of the message to be sent
sendMessage chat_id:int53 message_thread_id:int53 reply_to_message_id:int53 options:messageSendOptions reply_markup:ReplyMarkup input_message_content:InputMessageContent = Message;
sendMessage chat_id:int53 message_thread_id:int53 reply_to:MessageReplyTo options:messageSendOptions reply_markup:ReplyMarkup input_message_content:InputMessageContent = Message;

//@description Sends 2-10 messages grouped together into an album. Currently, only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages
//@chat_id Target chat
//@message_thread_id If not 0, a message thread identifier in which the messages will be sent
//@reply_to_message_id Identifier of a replied message; 0 if none
//@reply_to Identifier of the replied message or story; pass null if none
//@options Options to be used to send the messages; pass null to use default options
//@input_message_contents Contents of messages to be sent. At most 10 messages can be added to an album
//@only_preview Pass true to get fake messages instead of actually sending them
sendMessageAlbum chat_id:int53 message_thread_id:int53 reply_to_message_id:int53 options:messageSendOptions input_message_contents:vector<InputMessageContent> only_preview:Bool = Messages;
sendMessageAlbum chat_id:int53 message_thread_id:int53 reply_to:MessageReplyTo options:messageSendOptions input_message_contents:vector<InputMessageContent> only_preview:Bool = Messages;

//@description Invites a bot to a chat (if it is not yet a member) and sends it the /start command. Bots can't be invited to a private chat other than the chat with the bot. Bots can't be invited to channels (although they can be added as admins) and secret chats. Returns the sent message
//@bot_user_id Identifier of the bot
Expand All @@ -6400,12 +6400,12 @@ sendBotStartMessage bot_user_id:int53 chat_id:int53 parameter:string = Message;
//@description Sends the result of an inline query as a message. Returns the sent message. Always clears a chat draft message
//@chat_id Target chat
//@message_thread_id If not 0, a message thread identifier in which the message will be sent
//@reply_to_message_id Identifier of a replied message; 0 if none
//@reply_to Identifier of the replied message or story; pass null if none
//@options Options to be used to send the message; pass null to use default options
//@query_id Identifier of the inline query
//@result_id Identifier of the inline result
//@hide_via_bot Pass true to hide the bot, via which the message is sent. Can be used only for bots getOption("animation_search_bot_username"), getOption("photo_search_bot_username"), and getOption("venue_search_bot_username")
sendInlineQueryResultMessage chat_id:int53 message_thread_id:int53 reply_to_message_id:int53 options:messageSendOptions query_id:int64 result_id:string hide_via_bot:Bool = Message;
sendInlineQueryResultMessage chat_id:int53 message_thread_id:int53 reply_to:MessageReplyTo options:messageSendOptions query_id:int64 result_id:string hide_via_bot:Bool = Message;

//@description Forwards previously sent messages. Returns the forwarded messages in the same order as the message identifiers passed in message_ids. If a message can't be forwarded, null will be returned instead of the message
//@chat_id Identifier of the chat to which to forward messages
Expand All @@ -6427,10 +6427,10 @@ resendMessages chat_id:int53 message_ids:vector<int53> = Messages;
//@description Adds a local message to a chat. The message is persistent across application restarts only if the message database is used. Returns the added message
//@chat_id Target chat
//@sender_id Identifier of the sender of the message
//@reply_to_message_id Identifier of the replied message; 0 if none
//@reply_to Identifier of the replied message or story; pass null if none
//@disable_notification Pass true to disable notification for the message
//@input_message_content The content of the message to be added
addLocalMessage chat_id:int53 sender_id:MessageSender reply_to_message_id:int53 disable_notification:Bool input_message_content:InputMessageContent = Message;
addLocalMessage chat_id:int53 sender_id:MessageSender reply_to:MessageReplyTo disable_notification:Bool input_message_content:InputMessageContent = Message;

//@description Deletes messages @chat_id Chat identifier @message_ids Identifiers of the messages to be deleted @revoke Pass true to delete messages for all chat members. Always true for supergroups, channels and secret chats
deleteMessages chat_id:int53 message_ids:vector<int53> revoke:Bool = Ok;
Expand Down Expand Up @@ -6778,8 +6778,8 @@ sendWebAppData bot_user_id:int53 button_text:string data:string = Ok;
//@theme Preferred Web App theme; pass null to use the default theme
//@application_name Short name of the application; 0-64 English letters, digits, and underscores
//@message_thread_id If not 0, a message thread identifier in which the message will be sent
//@reply_to_message_id Identifier of the replied message for the message sent by the Web App; 0 if none
openWebApp chat_id:int53 bot_user_id:int53 url:string theme:themeParameters application_name:string message_thread_id:int53 reply_to_message_id:int53 = WebAppInfo;
//@reply_to Identifier of the replied message or story for the message sent by the Web App; pass null if none
openWebApp chat_id:int53 bot_user_id:int53 url:string theme:themeParameters application_name:string message_thread_id:int53 reply_to:MessageReplyTo = WebAppInfo;

//@description Informs TDLib that a previously opened Web App was closed @web_app_launch_id Identifier of Web App launch, received from openWebApp
closeWebApp web_app_launch_id:int64 = Ok;
Expand Down
30 changes: 14 additions & 16 deletions td/telegram/AttachMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
DialogId dialog_id_;
UserId bot_user_id_;
MessageId top_thread_message_id_;
MessageId reply_to_message_id_;
MessageInputReplyTo input_reply_to_;
DialogId as_dialog_id_;
bool from_attach_menu_ = false;

Expand All @@ -130,11 +130,11 @@ class RequestWebViewQuery final : public Td::ResultHandler {

void send(DialogId dialog_id, UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme, string &&platform, MessageId top_thread_message_id,
MessageId reply_to_message_id, bool silent, DialogId as_dialog_id) {
MessageInputReplyTo input_reply_to, bool silent, DialogId as_dialog_id) {
dialog_id_ = dialog_id;
bot_user_id_ = bot_user_id;
top_thread_message_id_ = top_thread_message_id;
reply_to_message_id_ = reply_to_message_id;
input_reply_to_ = input_reply_to;
as_dialog_id_ = as_dialog_id;

int32 flags = 0;
Expand Down Expand Up @@ -167,7 +167,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
flags |= telegram_api::messages_requestWebView::THEME_PARAMS_MASK;
}

auto reply_to = MessagesManager::get_input_reply_to(reply_to_message_id, top_thread_message_id);
auto reply_to = input_reply_to_.get_input_reply_to(td_, top_thread_message_id);
if (reply_to != nullptr) {
flags |= telegram_api::messages_requestWebView::REPLY_TO_MASK;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {

auto ptr = result_ptr.move_as_ok();
td_->attach_menu_manager_->open_web_view(ptr->query_id_, dialog_id_, bot_user_id_, top_thread_message_id_,
reply_to_message_id_, as_dialog_id_);
input_reply_to_, as_dialog_id_);
promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_));
}

Expand All @@ -216,7 +216,7 @@ class ProlongWebViewQuery final : public Td::ResultHandler {

public:
void send(DialogId dialog_id, UserId bot_user_id, int64 query_id, MessageId top_thread_message_id,
MessageId reply_to_message_id, bool silent, DialogId as_dialog_id) {
MessageInputReplyTo input_reply_to, bool silent, DialogId as_dialog_id) {
dialog_id_ = dialog_id;

auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
Expand All @@ -226,7 +226,7 @@ class ProlongWebViewQuery final : public Td::ResultHandler {
}

int32 flags = 0;
auto reply_to = MessagesManager::get_input_reply_to(reply_to_message_id, top_thread_message_id);
auto reply_to = input_reply_to.get_input_reply_to(td_, top_thread_message_id);
if (reply_to != nullptr) {
flags |= telegram_api::messages_prolongWebView::REPLY_TO_MASK;
}
Expand Down Expand Up @@ -673,7 +673,7 @@ void AttachMenuManager::ping_web_view() {
bool silent = td_->messages_manager_->get_dialog_silent_send_message(opened_web_view.dialog_id_);
td_->create_handler<ProlongWebViewQuery>()->send(
opened_web_view.dialog_id_, opened_web_view.bot_user_id_, it.first, opened_web_view.top_thread_message_id_,
opened_web_view.reply_to_message_id_, silent, opened_web_view.as_dialog_id_);
opened_web_view.input_reply_to_, silent, opened_web_view.as_dialog_id_);
}

schedule_ping_web_view();
Expand Down Expand Up @@ -753,7 +753,7 @@ void AttachMenuManager::request_app_web_view(DialogId dialog_id, UserId bot_user
}

void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId top_thread_message_id,
MessageId reply_to_message_id, string &&url,
td_api::object_ptr<td_api::MessageReplyTo> &&reply_to, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme, string &&platform,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise) {
TRY_STATUS_PROMISE(promise, td_->contacts_manager_->get_bot_data(bot_user_id));
Expand Down Expand Up @@ -781,26 +781,24 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
return promise.set_error(Status::Error(400, "Have no write access to the chat"));
}

if (!reply_to_message_id.is_valid() || !reply_to_message_id.is_server() ||
!td_->messages_manager_->have_message_force({dialog_id, reply_to_message_id}, "request_web_view")) {
reply_to_message_id = MessageId();
}
if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server() ||
dialog_id.get_type() != DialogType::Channel ||
!td_->contacts_manager_->is_megagroup_channel(dialog_id.get_channel_id())) {
top_thread_message_id = MessageId();
}
auto input_reply_to =
td_->messages_manager_->get_message_input_reply_to(dialog_id, top_thread_message_id, std::move(reply_to), false);

bool silent = td_->messages_manager_->get_dialog_silent_send_message(dialog_id);
DialogId as_dialog_id = td_->messages_manager_->get_dialog_default_send_message_as_dialog_id(dialog_id);

td_->create_handler<RequestWebViewQuery>(std::move(promise))
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), std::move(platform),
top_thread_message_id, reply_to_message_id, silent, as_dialog_id);
top_thread_message_id, input_reply_to, silent, as_dialog_id);
}

void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,
MessageId top_thread_message_id, MessageId reply_to_message_id,
MessageId top_thread_message_id, MessageInputReplyTo input_reply_to,
DialogId as_dialog_id) {
if (query_id == 0) {
LOG(ERROR) << "Receive Web App query identifier == 0";
Expand All @@ -814,7 +812,7 @@ void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId
opened_web_view.dialog_id_ = dialog_id;
opened_web_view.bot_user_id_ = bot_user_id;
opened_web_view.top_thread_message_id_ = top_thread_message_id;
opened_web_view.reply_to_message_id_ = reply_to_message_id;
opened_web_view.input_reply_to_ = std::move(input_reply_to);
opened_web_view.as_dialog_id_ = as_dialog_id;
opened_web_views_.emplace(query_id, std::move(opened_web_view));
}
Expand Down
7 changes: 4 additions & 3 deletions td/telegram/AttachMenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageInputReplyTo.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
Expand Down Expand Up @@ -42,12 +43,12 @@ class AttachMenuManager final : public Actor {
string &&platform, bool allow_write_access, Promise<string> &&promise);

void request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId top_thread_message_id,
MessageId reply_to_message_id, string &&url,
td_api::object_ptr<td_api::MessageReplyTo> &&reply_to, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme, string &&platform,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);

void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId top_thread_message_id,
MessageId reply_to_message_id, DialogId as_dialog_id);
MessageInputReplyTo input_reply_to, DialogId as_dialog_id);

void close_web_view(int64 query_id, Promise<Unit> &&promise);

Expand Down Expand Up @@ -175,7 +176,7 @@ class AttachMenuManager final : public Actor {
DialogId dialog_id_;
UserId bot_user_id_;
MessageId top_thread_message_id_;
MessageId reply_to_message_id_;
MessageInputReplyTo input_reply_to_;
DialogId as_dialog_id_;
};
FlatHashMap<int64, OpenedWebView> opened_web_views_;
Expand Down
8 changes: 6 additions & 2 deletions td/telegram/DraftMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ Result<unique_ptr<DraftMessage>> DraftMessage::get_draft_message(
if (result->reply_to_message_id_ != MessageId() && !result->reply_to_message_id_.is_valid()) {
return Status::Error(400, "Invalid reply_to_message_id specified");
}
result->reply_to_message_id_ = td->messages_manager_->get_reply_to_message_id(dialog_id, top_thread_message_id,
result->reply_to_message_id_, true);
result->reply_to_message_id_ =
td->messages_manager_
->get_message_input_reply_to(
dialog_id, top_thread_message_id,
td_api::make_object<td_api::messageReplyToMessage>(0, result->reply_to_message_id_.get()), true)
.message_id_;

auto input_message_content = std::move(draft_message->input_message_text_);
if (input_message_content != nullptr) {
Expand Down
9 changes: 5 additions & 4 deletions td/telegram/MessageCopyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageInputReplyTo.h"
#include "td/telegram/ReplyMarkup.h"

#include "td/utils/common.h"
Expand All @@ -19,7 +20,7 @@ struct MessageCopyOptions {
bool send_copy = false;
bool replace_caption = false;
FormattedText new_caption;
MessageId reply_to_message_id;
MessageInputReplyTo input_reply_to;
unique_ptr<ReplyMarkup> reply_markup;

MessageCopyOptions() = default;
Expand All @@ -30,7 +31,7 @@ struct MessageCopyOptions {
if (!send_copy) {
return true;
}
if ((replace_caption && !new_caption.text.empty()) || reply_to_message_id.is_valid() || reply_markup != nullptr) {
if ((replace_caption && !new_caption.text.empty()) || input_reply_to.is_valid() || reply_markup != nullptr) {
return false;
}
return true;
Expand All @@ -43,8 +44,8 @@ inline StringBuilder &operator<<(StringBuilder &string_builder, MessageCopyOptio
if (copy_options.replace_caption) {
string_builder << ", new_caption = " << copy_options.new_caption;
}
if (copy_options.reply_to_message_id.is_valid()) {
string_builder << ", in reply to " << copy_options.reply_to_message_id;
if (copy_options.input_reply_to.is_valid()) {
string_builder << ", in reply to " << copy_options.input_reply_to;
}
if (copy_options.reply_markup != nullptr) {
string_builder << ", with reply markup";
Expand Down
Loading

0 comments on commit fa94aba

Please sign in to comment.