From f2687a31dcba201fb4f02cb76f7e88bc2fd186a1 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Mar 2024 20:59:06 +0300 Subject: [PATCH] Check chat identifier along with business connection identifier. --- td/telegram/BusinessConnectionManager.cpp | 18 +++++++++++++++--- td/telegram/BusinessConnectionManager.h | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/td/telegram/BusinessConnectionManager.cpp b/td/telegram/BusinessConnectionManager.cpp index 1c59240db..c7fc1f85a 100644 --- a/td/telegram/BusinessConnectionManager.cpp +++ b/td/telegram/BusinessConnectionManager.cpp @@ -90,11 +90,23 @@ void BusinessConnectionManager::tear_down() { parent_.reset(); } -Status BusinessConnectionManager::check_business_connection_id(const BusinessConnectionId &connection_id) const { - if (connection_id.is_empty() || business_connections_.count(connection_id) != 0) { +Status BusinessConnectionManager::check_business_connection(const BusinessConnectionId &connection_id, + DialogId dialog_id) const { + if (connection_id.is_empty()) { return Status::OK(); } - return Status::Error(400, "Business connection not found"); + auto connection = business_connections_.get_pointer(connection_id); + if (connection == nullptr) { + return Status::Error(400, "Business connection not found"); + } + if (dialog_id.get_type() != DialogType::User) { + return Status::Error(400, "Chat must be a private chat"); + } + if (dialog_id == DialogId(connection->user_id_)) { + return Status::Error(400, "Messages must not be sent to self"); + } + // no need to check connection->can_reply_ and connection->is_disabled_ + return Status::OK(); } void BusinessConnectionManager::on_update_bot_business_connect( diff --git a/td/telegram/BusinessConnectionManager.h b/td/telegram/BusinessConnectionManager.h index 3be9e4611..4ddf26b32 100644 --- a/td/telegram/BusinessConnectionManager.h +++ b/td/telegram/BusinessConnectionManager.h @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/BusinessConnectionId.h" +#include "td/telegram/DialogId.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" @@ -30,7 +31,7 @@ class BusinessConnectionManager final : public Actor { BusinessConnectionManager &operator=(BusinessConnectionManager &&) = delete; ~BusinessConnectionManager() final; - Status check_business_connection_id(const BusinessConnectionId &connection_id) const; + Status check_business_connection(const BusinessConnectionId &connection_id, DialogId dialog_id) const; void on_update_bot_business_connect(telegram_api::object_ptr &&connection);