From f3f6f084d9abc67dbdf0c4a95c97759a23e4526f Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 13 Aug 2024 21:01:01 +0300 Subject: [PATCH] Ignore "sensitive" restriction for the whole chat. --- td/telegram/RestrictionReason.cpp | 13 ++++++++----- td/telegram/RestrictionReason.h | 7 ++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/td/telegram/RestrictionReason.cpp b/td/telegram/RestrictionReason.cpp index e74362be1..c2368e573 100644 --- a/td/telegram/RestrictionReason.cpp +++ b/td/telegram/RestrictionReason.cpp @@ -16,7 +16,7 @@ namespace td { -const RestrictionReason *get_restriction_reason(const vector &restriction_reasons) { +const RestrictionReason *get_restriction_reason(const vector &restriction_reasons, bool sensitive) { if (restriction_reasons.empty()) { return nullptr; } @@ -44,7 +44,8 @@ const RestrictionReason *get_restriction_reason(const vector // first find restriction for the current platform for (auto &restriction_reason : restriction_reasons) { if (restriction_reason.platform_ == platform && - !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { + !td::contains(ignored_restriction_reasons, restriction_reason.reason_) && + restriction_reason.is_sensitive() == sensitive) { return &restriction_reason; } } @@ -54,7 +55,8 @@ const RestrictionReason *get_restriction_reason(const vector // then find restriction for added platforms for (auto &restriction_reason : restriction_reasons) { if (td::contains(restriction_add_platforms, restriction_reason.platform_) && - !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { + !td::contains(ignored_restriction_reasons, restriction_reason.reason_) && + restriction_reason.is_sensitive() == sensitive) { return &restriction_reason; } } @@ -63,7 +65,8 @@ const RestrictionReason *get_restriction_reason(const vector // then find restriction for all platforms for (auto &restriction_reason : restriction_reasons) { if (restriction_reason.platform_ == "all" && - !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { + !td::contains(ignored_restriction_reasons, restriction_reason.reason_) && + restriction_reason.is_sensitive() == sensitive) { return &restriction_reason; } } @@ -72,7 +75,7 @@ const RestrictionReason *get_restriction_reason(const vector } string get_restriction_reason_description(const vector &restriction_reasons) { - const auto *restriction_reason = get_restriction_reason(restriction_reasons); + const auto *restriction_reason = get_restriction_reason(restriction_reasons, false); if (restriction_reason == nullptr) { return string(); } diff --git a/td/telegram/RestrictionReason.h b/td/telegram/RestrictionReason.h index eddbd0304..45e81601f 100644 --- a/td/telegram/RestrictionReason.h +++ b/td/telegram/RestrictionReason.h @@ -29,10 +29,15 @@ class RestrictionReason { return lhs.platform_ == rhs.platform_ && lhs.reason_ == rhs.reason_ && lhs.description_ == rhs.description_; } - friend const RestrictionReason *get_restriction_reason(const vector &restriction_reasons); + friend const RestrictionReason *get_restriction_reason(const vector &restriction_reasons, + bool sensitive); friend string get_restriction_reason_description(const vector &restriction_reasons); + bool is_sensitive() const { + return reason_ == "sensitive"; + } + public: RestrictionReason() = default;