From 761e90891fef7200c8c03cbf59d043f706f260e4 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 17 Jul 2022 01:20:20 +0200 Subject: [PATCH] Properly figure out entity that is controlled by policy rule --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.yaml | 2 +- src/timeline/TimelineModel.cpp | 37 +++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 026e3c4b..57bd6860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -581,7 +581,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG c2824dae5050882872a6c3f5677f3309a60511be + GIT_TAG 1f42cb0c8560a92b2640306b32cb6a330c564a31 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.yaml b/io.github.NhekoReborn.Nheko.yaml index 879043b2..84c858e8 100644 --- a/io.github.NhekoReborn.Nheko.yaml +++ b/io.github.NhekoReborn.Nheko.yaml @@ -203,7 +203,7 @@ modules: buildsystem: cmake-ninja name: mtxclient sources: - - commit: c2824dae5050882872a6c3f5677f3309a60511be + - commit: 1f42cb0c8560a92b2640306b32cb6a330c564a31 #tag: v0.7.0 type: git url: https://github.com/Nheko-Reborn/mtxclient.git diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index b21fb091..0a9aae6a 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -2340,7 +2340,8 @@ TimelineModel::formatImagePackEvent(const QString &id) QString TimelineModel::formatPolicyRule(const QString &id) { - mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); + auto idStr = id.toStdString(); + mtx::events::collections::TimelineEvents *e = events.get(idStr, ""); if (!e) return {}; @@ -2354,6 +2355,18 @@ TimelineModel::formatPolicyRule(const QString &id) (userRule->content.recommendation != mtx::events::state::policy_rule::recommendation::ban && userRule->content.recommendation != unstable_ban)) { + while (userRule->content.entity.empty() && + !userRule->unsigned_data.replaces_state.empty()) { + auto temp = events.get(userRule->unsigned_data.replaces_state, idStr); + if (!temp) + break; + if (auto tempRule = std::get_if< + mtx::events::StateEvent>(temp)) + userRule = tempRule; + else + break; + } + return tr("%1 disabled the rule to ban users matching %2.") .arg(sender, qsHtml(userRule->content.entity)); } else { @@ -2368,6 +2381,17 @@ TimelineModel::formatPolicyRule(const QString &id) (roomRule->content.recommendation != mtx::events::state::policy_rule::recommendation::ban && roomRule->content.recommendation != unstable_ban)) { + while (roomRule->content.entity.empty() && + !roomRule->unsigned_data.replaces_state.empty()) { + auto temp = events.get(roomRule->unsigned_data.replaces_state, idStr); + if (!temp) + break; + if (auto tempRule = std::get_if< + mtx::events::StateEvent>(temp)) + roomRule = tempRule; + else + break; + } return tr("%1 disabled the rule to ban rooms matching %2.") .arg(sender, qsHtml(roomRule->content.entity)); } else { @@ -2382,6 +2406,17 @@ TimelineModel::formatPolicyRule(const QString &id) (serverRule->content.recommendation != mtx::events::state::policy_rule::recommendation::ban && serverRule->content.recommendation != unstable_ban)) { + while (serverRule->content.entity.empty() && + !serverRule->unsigned_data.replaces_state.empty()) { + auto temp = events.get(serverRule->unsigned_data.replaces_state, idStr); + if (!temp) + break; + if (auto tempRule = std::get_if< + mtx::events::StateEvent>(temp)) + serverRule = tempRule; + else + break; + } return tr("%1 disabled the rule to ban servers matching %2.") .arg(sender, qsHtml(serverRule->content.entity)); } else {