diff --git a/CMakeLists.txt b/CMakeLists.txt index e480ddc83..52685c8d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -369,6 +369,7 @@ set(TDLIB_SOURCE td/telegram/Game.cpp td/telegram/GameManager.cpp td/telegram/Global.cpp + td/telegram/GlobalPrivacySettings.cpp td/telegram/GroupCallManager.cpp td/telegram/GroupCallParticipant.cpp td/telegram/GroupCallParticipantOrder.cpp @@ -634,6 +635,7 @@ set(TDLIB_SOURCE td/telegram/GameManager.h td/telegram/GitCommitHash.h td/telegram/Global.h + td/telegram/GlobalPrivacySettings.h td/telegram/GroupCallId.h td/telegram/GroupCallManager.h td/telegram/GroupCallParticipant.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 488fff202..3701f2c45 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1409,6 +1409,12 @@ recommendedChatFolder folder:chatFolder description:string = RecommendedChatFold //@description Contains a list of recommended chat folders @chat_folders List of recommended chat folders recommendedChatFolders chat_folders:vector = RecommendedChatFolders; +//@description Contains settings for automatic moving of chats to and from the Archive chat lists +//@archive_and_mute_new_chats_from_unknown_users True, if new chats from non-contacts will be automatically archived and muted. Can be set to true only if the option "can_archive_and_mute_new_chats_from_unknown_users" is true +//@keep_unmuted_chats_archived True, if unmuted chats will be kept in the Archive chat list when they get a new message +//@keep_chats_from_shareable_folders_archived True, if unmuted chats added via a shareable folder will be kept in the Archive chat list when they get a new message. Ignored if keep_unmuted_chats_archived == true +archiveChatListSettings archive_and_mute_new_chats_from_unknown_users:Bool keep_unmuted_chats_archived:Bool keep_chats_from_shareable_folders_archived:Bool = ArchiveChatListSettings; + //@class ChatList @description Describes a list of chats @@ -7074,6 +7080,9 @@ getChatFolderNewChats chat_folder_id:int32 = Chats; //@description Process new chats added to a shareable chat folder by its owner @chat_folder_id Chat folder identifier @added_chat_ids Identifiers of the new chats, which are added to the chat folder. The chats are automatically joined if they aren't joined yet processChatFolderNewChats chat_folder_id:int32 added_chat_ids:vector = Ok; +//@description Returns settings for automatic moving of chats to and from the Archive chat lists +getArchiveChatListSettings = ArchiveChatListSettings; + //@description Changes the chat title. Supported only for basic groups, supergroups and channels. Requires can_change_info administrator right //@chat_id Chat identifier diff --git a/td/telegram/GlobalPrivacySettings.cpp b/td/telegram/GlobalPrivacySettings.cpp new file mode 100644 index 000000000..f0c338558 --- /dev/null +++ b/td/telegram/GlobalPrivacySettings.cpp @@ -0,0 +1,62 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/GlobalPrivacySettings.h" + +#include "td/telegram/Global.h" +#include "td/telegram/net/NetQueryCreator.h" +#include "td/telegram/Td.h" + +#include "td/utils/buffer.h" +#include "td/utils/Status.h" + +namespace td { + +class GetGlobalPrivacySettingsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetGlobalPrivacySettingsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::account_getGlobalPrivacySettings())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto settings = GlobalPrivacySettings(result_ptr.move_as_ok()); + promise_.set_value(settings.get_archive_chat_list_settings_object()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + +GlobalPrivacySettings::GlobalPrivacySettings(telegram_api::object_ptr &&settings) + : archive_and_mute_new_noncontact_peers_(settings->archive_and_mute_new_noncontact_peers_) + , keep_archived_unmuted_(settings->keep_archived_unmuted_) + , keep_archived_folders_(settings->keep_archived_folders_) { +} + +td_api::object_ptr GlobalPrivacySettings::get_archive_chat_list_settings_object() + const { + return td_api::make_object(archive_and_mute_new_noncontact_peers_, + keep_archived_unmuted_, keep_archived_folders_); +} + +void GlobalPrivacySettings::get_global_privacy_settings( + Td *td, Promise> &&promise) { + td->create_handler(std::move(promise))->send(); +} + +} // namespace td diff --git a/td/telegram/GlobalPrivacySettings.h b/td/telegram/GlobalPrivacySettings.h new file mode 100644 index 000000000..fe2d73e9b --- /dev/null +++ b/td/telegram/GlobalPrivacySettings.h @@ -0,0 +1,33 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/Promise.h" + +namespace td { + +class Td; + +class GlobalPrivacySettings { + bool archive_and_mute_new_noncontact_peers_ = false; + bool keep_archived_unmuted_ = false; + bool keep_archived_folders_ = false; + + public: + explicit GlobalPrivacySettings(telegram_api::object_ptr &&settings); + + td_api::object_ptr get_archive_chat_list_settings_object() const; + + static void get_global_privacy_settings(Td *td, + Promise> &&promise); +}; + +} // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 981167ae6..407f8c57a 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -60,6 +60,7 @@ #include "td/telegram/FullMessageId.h" #include "td/telegram/GameManager.h" #include "td/telegram/Global.h" +#include "td/telegram/GlobalPrivacySettings.h" #include "td/telegram/GroupCallId.h" #include "td/telegram/GroupCallManager.h" #include "td/telegram/HashtagHints.h" @@ -6343,6 +6344,12 @@ void Td::on_request(uint64 id, const td_api::processChatFolderNewChats &request) DialogFilterId(request.chat_folder_id_), DialogId::get_dialog_ids(request.added_chat_ids_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getArchiveChatListSettings &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + GlobalPrivacySettings::get_global_privacy_settings(this, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setChatTitle &request) { CLEAN_INPUT_STRING(request.title_); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index bce198083..eb63f72e5 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -972,6 +972,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::processChatFolderNewChats &request); + void on_request(uint64 id, const td_api::getArchiveChatListSettings &request); + void on_request(uint64 id, td_api::setChatTitle &request); void on_request(uint64 id, const td_api::setChatPhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index e2abffbda..27559e914 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4952,6 +4952,8 @@ class CliClient final : public Actor { send_request(td_api::make_object()); } else if (op == "gcfdin") { execute(td_api::make_object(as_chat_folder(args))); + } else if (op == "gacls") { + send_request(td_api::make_object()); } else if (op == "sct") { ChatId chat_id; string title;