Fix chat to send messages as from a web app.
This commit is contained in:
parent
447cfbfb1d
commit
2345933422
@ -39,6 +39,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
|
||||
DialogId dialog_id_;
|
||||
UserId bot_user_id_;
|
||||
MessageId reply_to_message_id_;
|
||||
DialogId as_dialog_id_;
|
||||
bool from_attach_menu_ = false;
|
||||
|
||||
public:
|
||||
@ -47,10 +48,12 @@ 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, MessageId reply_to_message_id, bool silent) {
|
||||
td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id, bool silent,
|
||||
DialogId as_dialog_id) {
|
||||
dialog_id_ = dialog_id;
|
||||
bot_user_id_ = bot_user_id;
|
||||
reply_to_message_id_ = reply_to_message_id;
|
||||
as_dialog_id_ = as_dialog_id;
|
||||
|
||||
int32 flags = 0;
|
||||
|
||||
@ -90,9 +93,17 @@ class RequestWebViewQuery final : public Td::ResultHandler {
|
||||
flags |= telegram_api::messages_requestWebView::SILENT_MASK;
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputPeer> as_input_peer;
|
||||
if (as_dialog_id.is_valid()) {
|
||||
as_input_peer = td_->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Write);
|
||||
if (as_input_peer != nullptr) {
|
||||
flags |= telegram_api::messages_requestWebView::SEND_AS_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_requestWebView(
|
||||
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), std::move(input_user), url, start_parameter,
|
||||
std::move(theme_parameters), reply_to_message_id.get_server_message_id().get(), nullptr)));
|
||||
std::move(theme_parameters), reply_to_message_id.get_server_message_id().get(), std::move(as_input_peer))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -102,7 +113,8 @@ 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_, reply_to_message_id_);
|
||||
td_->attach_menu_manager_->open_web_view(ptr->query_id_, dialog_id_, bot_user_id_, reply_to_message_id_,
|
||||
as_dialog_id_);
|
||||
promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_));
|
||||
}
|
||||
|
||||
@ -120,7 +132,8 @@ class ProlongWebViewQuery final : public Td::ResultHandler {
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
void send(DialogId dialog_id, UserId bot_user_id, int64 query_id, MessageId reply_to_message_id, bool silent) {
|
||||
void send(DialogId dialog_id, UserId bot_user_id, int64 query_id, MessageId reply_to_message_id, bool silent,
|
||||
DialogId as_dialog_id) {
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
@ -133,13 +146,22 @@ class ProlongWebViewQuery final : public Td::ResultHandler {
|
||||
if (reply_to_message_id.is_valid()) {
|
||||
flags |= telegram_api::messages_prolongWebView::REPLY_TO_MSG_ID_MASK;
|
||||
}
|
||||
|
||||
if (silent) {
|
||||
flags |= telegram_api::messages_prolongWebView::SILENT_MASK;
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputPeer> as_input_peer;
|
||||
if (as_dialog_id.is_valid()) {
|
||||
as_input_peer = td_->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Write);
|
||||
if (as_input_peer != nullptr) {
|
||||
flags |= telegram_api::messages_prolongWebView::SEND_AS_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_prolongWebView(
|
||||
flags, false /*ignored*/, std::move(input_peer), r_input_user.move_as_ok(), query_id,
|
||||
reply_to_message_id.get_server_message_id().get(), nullptr)));
|
||||
reply_to_message_id.get_server_message_id().get(), std::move(as_input_peer))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -493,7 +515,8 @@ void AttachMenuManager::ping_web_view() {
|
||||
const auto &opened_web_view = it.second;
|
||||
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.reply_to_message_id_, silent);
|
||||
opened_web_view.reply_to_message_id_, silent,
|
||||
opened_web_view.as_dialog_id_);
|
||||
}
|
||||
|
||||
schedule_ping_web_view();
|
||||
@ -538,14 +561,15 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
|
||||
}
|
||||
|
||||
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), reply_to_message_id,
|
||||
silent);
|
||||
silent, as_dialog_id);
|
||||
}
|
||||
|
||||
void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,
|
||||
MessageId reply_to_message_id) {
|
||||
MessageId reply_to_message_id, DialogId as_dialog_id) {
|
||||
if (query_id == 0) {
|
||||
LOG(ERROR) << "Receive web app query identifier == 0";
|
||||
return;
|
||||
@ -558,6 +582,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.reply_to_message_id_ = reply_to_message_id;
|
||||
opened_web_view.as_dialog_id_ = as_dialog_id;
|
||||
opened_web_views_.emplace(query_id, std::move(opened_web_view));
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,8 @@ class AttachMenuManager final : public Actor {
|
||||
td_api::object_ptr<td_api::themeParameters> &&theme,
|
||||
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);
|
||||
|
||||
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id);
|
||||
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id,
|
||||
DialogId as_dialog_id);
|
||||
|
||||
void close_web_view(int64 query_id, Promise<Unit> &&promise);
|
||||
|
||||
@ -138,6 +139,7 @@ class AttachMenuManager final : public Actor {
|
||||
DialogId dialog_id_;
|
||||
UserId bot_user_id_;
|
||||
MessageId reply_to_message_id_;
|
||||
DialogId as_dialog_id_;
|
||||
};
|
||||
FlatHashMap<int64, OpenedWebView> opened_web_views_;
|
||||
Timeout ping_web_view_timeout_;
|
||||
|
@ -24528,6 +24528,12 @@ bool MessagesManager::get_dialog_silent_send_message(DialogId dialog_id) const {
|
||||
return d->notification_settings.silent_send_message;
|
||||
}
|
||||
|
||||
DialogId MessagesManager::get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const {
|
||||
auto *d = get_dialog(dialog_id);
|
||||
CHECK(d != nullptr);
|
||||
return d->default_send_message_as_dialog_id;
|
||||
}
|
||||
|
||||
int64 MessagesManager::generate_new_random_id(const Dialog *d) {
|
||||
int64 random_id;
|
||||
do {
|
||||
|
@ -429,6 +429,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
bool get_dialog_silent_send_message(DialogId dialog_id) const;
|
||||
|
||||
DialogId get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const;
|
||||
|
||||
Result<td_api::object_ptr<td_api::message>> send_message(
|
||||
DialogId dialog_id, MessageId top_thread_message_id, MessageId reply_to_message_id,
|
||||
tl_object_ptr<td_api::messageSendOptions> &&options, tl_object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||
|
Loading…
Reference in New Issue
Block a user