Add get_restriction_reason helper function.

This commit is contained in:
levlam 2024-08-13 20:27:02 +03:00
parent 4fbe7741dc
commit 4101db16a7
2 changed files with 16 additions and 6 deletions

View File

@ -16,9 +16,9 @@
namespace td {
string get_restriction_reason_description(const vector<RestrictionReason> &restriction_reasons) {
const RestrictionReason *get_restriction_reason(const vector<RestrictionReason> &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<RestrictionReason> &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<RestrictionReason> &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<RestrictionReason> &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<RestrictionReason> &restriction_reasons) {
const auto *restriction_reason = get_restriction_reason(restriction_reasons);
if (restriction_reason == nullptr) {
return string();
}
return restriction_reason->description_;
}
vector<RestrictionReason> get_restriction_reasons(Slice legacy_restriction_reason) {

View File

@ -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<RestrictionReason> &restriction_reasons);
friend string get_restriction_reason_description(const vector<RestrictionReason> &restriction_reasons);
public: