Add td_api::newChatPrivacySettings and methods for getting and setting it.

This commit is contained in:
levlam 2024-01-19 14:25:24 +03:00
parent 2504de4978
commit c8e4622da4
6 changed files with 63 additions and 2 deletions

View File

@ -5393,10 +5393,14 @@ userPrivacySettingAllowFindingByPhoneNumber = UserPrivacySetting;
userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages = UserPrivacySetting;
//@description Contains privacy settings for message read date
//@description Contains privacy settings for message read date in private chats
//@show_read_date True, if message read date is shown to other users in private chats. If disabled and the current user isn't a Telegram Premium user, then they will not be able to see other's message read date
readDatePrivacySettings show_read_date:Bool = ReadDatePrivacySettings;
//@description Contains privacy settings for new chats with non-contacts
//@allow_new_chats_from_unknown_users True, if non-contacts users are able to write first to the current user. Telegram Premium subscribers are able to write first regardless of this setting
newChatPrivacySettings allow_new_chats_from_unknown_users:Bool = NewChatPrivacySettings;
//@description Contains information about the period of inactivity after which the current user's account will automatically be deleted @days Number of days of inactivity before the account will be flagged for deletion; 30-366 days
accountTtl days:int32 = AccountTtl;
@ -9513,6 +9517,12 @@ setReadDatePrivacySettings settings:readDatePrivacySettings = Ok;
//@description Returns privacy settings for message read date
getReadDatePrivacySettings = ReadDatePrivacySettings;
//@description Changes privacy settings for new chat creation @settings New settings
setNewChatPrivacySettings settings:newChatPrivacySettings = Ok;
//@description Returns privacy settings for new chat creation
getNewChatPrivacySettings = NewChatPrivacySettings;
//@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

View File

@ -95,6 +95,13 @@ GlobalPrivacySettings::GlobalPrivacySettings(td_api::object_ptr<td_api::readDate
}
}
GlobalPrivacySettings::GlobalPrivacySettings(td_api::object_ptr<td_api::newChatPrivacySettings> &&settings)
: set_type_(SetType::NewChat) {
if (settings != nullptr) {
new_noncontact_peers_require_premium_ = !settings->allow_new_chats_from_unknown_users_;
}
}
void GlobalPrivacySettings::apply_changes(const GlobalPrivacySettings &set_settings) {
CHECK(set_type_ == SetType::None);
switch (set_settings.set_type_) {
@ -106,6 +113,9 @@ void GlobalPrivacySettings::apply_changes(const GlobalPrivacySettings &set_setti
case SetType::ReadDate:
hide_read_marks_ = set_settings.hide_read_marks_;
break;
case SetType::NewChat:
new_noncontact_peers_require_premium_ = set_settings.new_noncontact_peers_require_premium_;
break;
default:
UNREACHABLE();
break;
@ -148,6 +158,11 @@ td_api::object_ptr<td_api::readDatePrivacySettings> GlobalPrivacySettings::get_r
return td_api::make_object<td_api::readDatePrivacySettings>(!hide_read_marks_);
}
td_api::object_ptr<td_api::newChatPrivacySettings> GlobalPrivacySettings::get_new_chat_privacy_settings_object() const {
CHECK(set_type_ == SetType::None);
return td_api::make_object<td_api::newChatPrivacySettings>(!new_noncontact_peers_require_premium_);
}
void GlobalPrivacySettings::get_global_privacy_settings(Td *td, Promise<GlobalPrivacySettings> &&promise) {
td->create_handler<GetGlobalPrivacySettingsQuery>(std::move(promise))->send();
}

View File

@ -17,7 +17,7 @@ namespace td {
class Td;
class GlobalPrivacySettings {
enum class SetType : int32 { None, Archive, ReadDate };
enum class SetType : int32 { None, Archive, ReadDate, NewChat };
SetType set_type_ = SetType::None;
bool archive_and_mute_new_noncontact_peers_ = false;
bool keep_archived_unmuted_ = false;
@ -34,12 +34,16 @@ class GlobalPrivacySettings {
explicit GlobalPrivacySettings(td_api::object_ptr<td_api::readDatePrivacySettings> &&settings);
explicit GlobalPrivacySettings(td_api::object_ptr<td_api::newChatPrivacySettings> &&settings);
telegram_api::object_ptr<telegram_api::globalPrivacySettings> get_input_global_privacy_settings() const;
td_api::object_ptr<td_api::archiveChatListSettings> get_archive_chat_list_settings_object() const;
td_api::object_ptr<td_api::readDatePrivacySettings> get_read_date_privacy_settings_object() const;
td_api::object_ptr<td_api::newChatPrivacySettings> get_new_chat_privacy_settings_object() const;
static void get_global_privacy_settings(Td *td, Promise<GlobalPrivacySettings> &&promise);
static void set_global_privacy_settings(Td *td, GlobalPrivacySettings settings, Promise<Unit> &&promise);

View File

@ -6507,6 +6507,27 @@ void Td::on_request(uint64 id, td_api::setReadDatePrivacySettings &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getNewChatPrivacySettings &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<GlobalPrivacySettings> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(result.ok().get_new_chat_privacy_settings_object());
}
});
GlobalPrivacySettings::get_global_privacy_settings(this, std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::setNewChatPrivacySettings &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
GlobalPrivacySettings::set_global_privacy_settings(this, GlobalPrivacySettings(std::move(request.settings_)),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTitle &request) {
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();

View File

@ -1055,6 +1055,10 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setReadDatePrivacySettings &request);
void on_request(uint64 id, const td_api::getNewChatPrivacySettings &request);
void on_request(uint64 id, td_api::setNewChatPrivacySettings &request);
void on_request(uint64 id, td_api::setChatTitle &request);
void on_request(uint64 id, const td_api::setChatPhoto &request);

View File

@ -5442,6 +5442,13 @@ class CliClient final : public Actor {
get_args(args, show_read_date);
auto settings = td_api::make_object<td_api::readDatePrivacySettings>(show_read_date);
send_request(td_api::make_object<td_api::setReadDatePrivacySettings>(std::move(settings)));
} else if (op == "gncps") {
send_request(td_api::make_object<td_api::getNewChatPrivacySettings>());
} else if (op == "sncps") {
bool 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);
send_request(td_api::make_object<td_api::setNewChatPrivacySettings>(std::move(settings)));
} else if (op == "sct") {
ChatId chat_id;
string title;