Add td_api::canSendMessageToUser.

This commit is contained in:
levlam 2024-01-19 15:35:57 +03:00
parent 59de70bd87
commit 5624f91155
6 changed files with 39 additions and 0 deletions

View File

@ -9525,6 +9525,10 @@ setNewChatPrivacySettings settings:newChatPrivacySettings = Ok;
getNewChatPrivacySettings = NewChatPrivacySettings; getNewChatPrivacySettings = NewChatPrivacySettings;
//@description Check whether the current user can message another user or try to create a chat with them @user_id Identifier of the other user
canSendMessageToUser user_id:int53 = Ok;
//@description Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) Can be called before authorization. Can be called synchronously for options "version" and "commit_hash" //@description Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) Can be called before authorization. Can be called synchronously for options "version" and "commit_hash"
//@name The name of the option //@name The name of the option
getOption name:string = OptionValue; getOption name:string = OptionValue;

View File

@ -5491,6 +5491,27 @@ int32 ContactsManager::get_user_was_online(const User *u, UserId user_id, int32
return was_online; return was_online;
} }
void ContactsManager::can_send_message_to_user(UserId user_id, Promise<Unit> &&promise) {
if (user_id == get_my_id()) {
return promise.set_value(Unit());
}
const auto *u = get_user(user_id);
if (!have_input_peer_user(u, user_id, AccessRights::Write)) {
return promise.set_error(Status::Error(400, "Have no write access to the chat"));
}
if (!u->contact_require_premium || td_->option_manager_->get_option_boolean("is_premium") || u->is_mutual_contact) {
return promise.set_value(Unit());
}
auto user_full = get_user_full_force(user_id, "can_send_message_to_user");
if (user_full != nullptr) {
if (!user_full->contact_require_premium) {
return promise.set_value(Unit());
}
return promise.set_error(Status::Error(400, "Can't write to the user first"));
}
return promise.set_value(Unit());
}
void ContactsManager::load_contacts(Promise<Unit> &&promise) { void ContactsManager::load_contacts(Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
are_contacts_loaded_ = true; are_contacts_loaded_ = true;

View File

@ -185,6 +185,8 @@ class ContactsManager final : public Actor {
int32 get_secret_chat_layer(SecretChatId secret_chat_id) const; int32 get_secret_chat_layer(SecretChatId secret_chat_id) const;
FolderId get_secret_chat_initial_folder_id(SecretChatId secret_chat_id) const; FolderId get_secret_chat_initial_folder_id(SecretChatId secret_chat_id) const;
void can_send_message_to_user(UserId user_id, Promise<Unit> &&promise);
void on_imported_contacts(int64 random_id, Result<tl_object_ptr<telegram_api::contacts_importedContacts>> result); void on_imported_contacts(int64 random_id, Result<tl_object_ptr<telegram_api::contacts_importedContacts>> result);
void on_deleted_contacts(const vector<UserId> &deleted_contact_user_ids); void on_deleted_contacts(const vector<UserId> &deleted_contact_user_ids);

View File

@ -6528,6 +6528,12 @@ void Td::on_request(uint64 id, td_api::setNewChatPrivacySettings &request) {
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::canSendMessageToUser &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->can_send_message_to_user(UserId(request.user_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTitle &request) { void Td::on_request(uint64 id, td_api::setChatTitle &request) {
CLEAN_INPUT_STRING(request.title_); CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();

View File

@ -1059,6 +1059,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setNewChatPrivacySettings &request); void on_request(uint64 id, td_api::setNewChatPrivacySettings &request);
void on_request(uint64 id, const td_api::canSendMessageToUser &request);
void on_request(uint64 id, td_api::setChatTitle &request); void on_request(uint64 id, td_api::setChatTitle &request);
void on_request(uint64 id, const td_api::setChatPhoto &request); void on_request(uint64 id, const td_api::setChatPhoto &request);

View File

@ -5449,6 +5449,10 @@ class CliClient final : public Actor {
get_args(args, allow_new_chats_from_unknown_users); get_args(args, allow_new_chats_from_unknown_users);
auto settings = td_api::make_object<td_api::newChatPrivacySettings>(allow_new_chats_from_unknown_users); auto settings = td_api::make_object<td_api::newChatPrivacySettings>(allow_new_chats_from_unknown_users);
send_request(td_api::make_object<td_api::setNewChatPrivacySettings>(std::move(settings))); send_request(td_api::make_object<td_api::setNewChatPrivacySettings>(std::move(settings)));
} else if (op == "csmtu") {
UserId user_id;
get_args(args, user_id);
send_request(td_api::make_object<td_api::canSendMessageToUser>(user_id));
} else if (op == "sct") { } else if (op == "sct") {
ChatId chat_id; ChatId chat_id;
string title; string title;