2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Support 18+/restrictions for messages.

This commit is contained in:
John Preston
2024-08-14 15:17:59 +02:00
parent 074dbf41e0
commit b9de12fedb
35 changed files with 711 additions and 299 deletions

View File

@@ -38,15 +38,18 @@ void AppConfig::start() {
}, _lifetime);
}
void AppConfig::refresh() {
void AppConfig::refresh(bool force) {
if (_requestId || !_api) {
if (force) {
_pendingRefresh = true;
}
return;
}
_pendingRefresh = false;
_requestId = _api->request(MTPhelp_GetAppConfig(
MTP_int(_hash)
)).done([=](const MTPhelp_AppConfig &result) {
_requestId = 0;
refreshDelayed();
result.match([&](const MTPDhelp_appConfig &data) {
_hash = data.vhash().v;
@@ -55,15 +58,25 @@ void AppConfig::refresh() {
LOG(("API Error: Unexpected config type."));
return;
}
auto was = ignoredRestrictionReasons();
_data.clear();
for (const auto &element : config.c_jsonObject().vvalue().v) {
element.match([&](const MTPDjsonObjectValue &data) {
_data.emplace_or_assign(qs(data.vkey()), data.vvalue());
});
}
updateIgnoredRestrictionReasons(std::move(was));
DEBUG_LOG(("getAppConfig result handled."));
_refreshed.fire({});
}, [](const MTPDhelp_appConfigNotModified &) {});
if (base::take(_pendingRefresh)) {
refresh();
} else {
refreshDelayed();
}
}).fail([=] {
_requestId = 0;
refreshDelayed();
@@ -76,6 +89,24 @@ void AppConfig::refreshDelayed() {
});
}
void AppConfig::updateIgnoredRestrictionReasons(std::vector<QString> was) {
_ignoreRestrictionReasons = get<std::vector<QString>>(
u"ignore_restriction_reasons"_q,
std::vector<QString>());
ranges::sort(_ignoreRestrictionReasons);
if (_ignoreRestrictionReasons != was) {
for (const auto &reason : _ignoreRestrictionReasons) {
const auto i = ranges::remove(was, reason);
if (i != end(was)) {
was.erase(i, end(was));
} else {
was.push_back(reason);
}
}
_ignoreRestrictionChanges.fire(std::move(was));
}
}
rpl::producer<> AppConfig::refreshed() const {
return _refreshed.events();
}