Check chat identifier along with business connection identifier.

This commit is contained in:
levlam 2024-03-07 20:59:06 +03:00
parent 967829d14b
commit f2687a31dc
2 changed files with 17 additions and 4 deletions

View File

@ -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(

View File

@ -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<telegram_api::botBusinessConnection> &&connection);