diff --git a/Telegram/SourceFiles/api/api_global_privacy.cpp b/Telegram/SourceFiles/api/api_global_privacy.cpp index c940dbe863..89e1d57da7 100644 --- a/Telegram/SourceFiles/api/api_global_privacy.cpp +++ b/Telegram/SourceFiles/api/api_global_privacy.cpp @@ -56,6 +56,15 @@ rpl::producer GlobalPrivacy::archiveAndMute() const { return _archiveAndMute.value(); } +UnarchiveOnNewMessage GlobalPrivacy::unarchiveOnNewMessageCurrent() const { + return _unarchiveOnNewMessage.current(); +} + +auto GlobalPrivacy::unarchiveOnNewMessage() const +-> rpl::producer { + return _unarchiveOnNewMessage.value(); +} + rpl::producer GlobalPrivacy::showArchiveAndMute() const { using namespace rpl::mappers; @@ -78,11 +87,20 @@ void GlobalPrivacy::dismissArchiveAndMuteSuggestion() { void GlobalPrivacy::update(bool archiveAndMute) { using Flag = MTPDglobalPrivacySettings::Flag; + const auto unarchive = unarchiveOnNewMessageCurrent(); _api.request(_requestId).cancel(); + const auto flags = Flag() + | (archiveAndMute + ? Flag::f_archive_and_mute_new_noncontact_peers + : Flag()) + | (unarchive == UnarchiveOnNewMessage::AnyUnmuted + ? Flag::f_keep_archived_unmuted + : Flag()) + | (unarchive != UnarchiveOnNewMessage::None + ? Flag::f_keep_archived_folders + : Flag()); _requestId = _api.request(MTPaccount_SetGlobalPrivacySettings( - MTP_globalPrivacySettings( - MTP_flags(Flag::f_archive_and_mute_new_noncontact_peers), - MTP_bool(archiveAndMute)) + MTP_globalPrivacySettings(MTP_flags(flags)) )).done([=](const MTPGlobalPrivacySettings &result) { _requestId = 0; apply(result); @@ -94,9 +112,12 @@ void GlobalPrivacy::update(bool archiveAndMute) { void GlobalPrivacy::apply(const MTPGlobalPrivacySettings &data) { data.match([&](const MTPDglobalPrivacySettings &data) { - _archiveAndMute = data.varchive_and_mute_new_noncontact_peers() - ? mtpIsTrue(*data.varchive_and_mute_new_noncontact_peers()) - : false; + _archiveAndMute = data.is_archive_and_mute_new_noncontact_peers(); + _unarchiveOnNewMessage = data.is_keep_archived_unmuted() + ? UnarchiveOnNewMessage::AnyUnmuted + : data.is_keep_archived_folders() + ? UnarchiveOnNewMessage::NotInFoldersUnmuted + : UnarchiveOnNewMessage::None; }); } diff --git a/Telegram/SourceFiles/api/api_global_privacy.h b/Telegram/SourceFiles/api/api_global_privacy.h index a1a693499f..f569951caa 100644 --- a/Telegram/SourceFiles/api/api_global_privacy.h +++ b/Telegram/SourceFiles/api/api_global_privacy.h @@ -17,6 +17,12 @@ class Session; namespace Api { +enum class UnarchiveOnNewMessage { + None, + NotInFoldersUnmuted, + AnyUnmuted, +}; + class GlobalPrivacy final { public: explicit GlobalPrivacy(not_null api); @@ -26,6 +32,10 @@ public: [[nodiscard]] bool archiveAndMuteCurrent() const; [[nodiscard]] rpl::producer archiveAndMute() const; + [[nodiscard]] auto unarchiveOnNewMessageCurrent() const + -> UnarchiveOnNewMessage; + [[nodiscard]] auto unarchiveOnNewMessage() const + -> rpl::producer; [[nodiscard]] rpl::producer showArchiveAndMute() const; [[nodiscard]] rpl::producer<> suggestArchiveAndMute() const; void dismissArchiveAndMuteSuggestion(); @@ -37,6 +47,8 @@ private: MTP::Sender _api; mtpRequestId _requestId = 0; rpl::variable _archiveAndMute = false; + rpl::variable _unarchiveOnNewMessage + = UnarchiveOnNewMessage::None; rpl::variable _showArchiveAndMute = false; std::vector> _callbacks; diff --git a/Telegram/SourceFiles/mtproto/scheme/api.tl b/Telegram/SourceFiles/mtproto/scheme/api.tl index b8771b61c2..18c9bcd5b0 100644 --- a/Telegram/SourceFiles/mtproto/scheme/api.tl +++ b/Telegram/SourceFiles/mtproto/scheme/api.tl @@ -1238,7 +1238,7 @@ statsGroupTopInviter#535f779d user_id:long invitations:int = StatsGroupTopInvite stats.megagroupStats#ef7ff916 period:StatsDateRangeDays members:StatsAbsValueAndPrev messages:StatsAbsValueAndPrev viewers:StatsAbsValueAndPrev posters:StatsAbsValueAndPrev growth_graph:StatsGraph members_graph:StatsGraph new_members_by_source_graph:StatsGraph languages_graph:StatsGraph messages_graph:StatsGraph actions_graph:StatsGraph top_hours_graph:StatsGraph weekdays_graph:StatsGraph top_posters:Vector top_admins:Vector top_inviters:Vector users:Vector = stats.MegagroupStats; -globalPrivacySettings#bea2f424 flags:# archive_and_mute_new_noncontact_peers:flags.0?Bool = GlobalPrivacySettings; +globalPrivacySettings#734c4ccb flags:# archive_and_mute_new_noncontact_peers:flags.0?true keep_archived_unmuted:flags.1?true keep_archived_folders:flags.2?true = GlobalPrivacySettings; help.countryCode#4203c5ef flags:# country_code:string prefixes:flags.0?Vector patterns:flags.1?Vector = help.CountryCode; @@ -1529,7 +1529,7 @@ sponsoredWebPage#3db8ec63 flags:# url:string site_name:string photo:flags.0?Phot storyViews#d36760cf flags:# views_count:int recent_viewers:flags.0?Vector = StoryViews; storyItemDeleted#51e6ee4f id:int = StoryItem; -storyItemSkipped#693206a2 id:int date:int expire_date:int = StoryItem; +storyItemSkipped#ffadc913 flags:# close_friends:flags.8?true id:int date:int expire_date:int = StoryItem; storyItem#562aa637 flags:# pinned:flags.5?true public:flags.7?true close_friends:flags.8?true min:flags.9?true noforwards:flags.10?true edited:flags.11?true id:int date:int expire_date:int caption:flags.0?string entities:flags.1?Vector media:MessageMedia privacy:flags.2?Vector views:flags.3?StoryViews = StoryItem; userStories#8611a200 flags:# user_id:long max_read_id:flags.0?int stories:Vector = UserStories;