diff --git a/td/telegram/RestrictionReason.cpp b/td/telegram/RestrictionReason.cpp index 52aba3df0..e74362be1 100644 --- a/td/telegram/RestrictionReason.cpp +++ b/td/telegram/RestrictionReason.cpp @@ -16,9 +16,9 @@ namespace td { -string get_restriction_reason_description(const vector &restriction_reasons) { +const RestrictionReason *get_restriction_reason(const vector &restriction_reasons) { if (restriction_reasons.empty()) { - return string(); + return nullptr; } auto ignored_restriction_reasons = full_split(G()->get_option_string("ignored_restriction_reasons"), ','); @@ -45,7 +45,7 @@ string get_restriction_reason_description(const vector &restr for (auto &restriction_reason : restriction_reasons) { if (restriction_reason.platform_ == platform && !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { - return restriction_reason.description_; + return &restriction_reason; } } } @@ -55,7 +55,7 @@ string get_restriction_reason_description(const vector &restr for (auto &restriction_reason : restriction_reasons) { if (td::contains(restriction_add_platforms, restriction_reason.platform_) && !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { - return restriction_reason.description_; + return &restriction_reason; } } } @@ -64,11 +64,19 @@ string get_restriction_reason_description(const vector &restr for (auto &restriction_reason : restriction_reasons) { if (restriction_reason.platform_ == "all" && !td::contains(ignored_restriction_reasons, restriction_reason.reason_)) { - return restriction_reason.description_; + return &restriction_reason; } } - return string(); + return nullptr; +} + +string get_restriction_reason_description(const vector &restriction_reasons) { + const auto *restriction_reason = get_restriction_reason(restriction_reasons); + if (restriction_reason == nullptr) { + return string(); + } + return restriction_reason->description_; } vector get_restriction_reasons(Slice legacy_restriction_reason) { diff --git a/td/telegram/RestrictionReason.h b/td/telegram/RestrictionReason.h index 729f23915..eddbd0304 100644 --- a/td/telegram/RestrictionReason.h +++ b/td/telegram/RestrictionReason.h @@ -29,6 +29,8 @@ 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 string get_restriction_reason_description(const vector &restriction_reasons); public: