From ede270776785b61725dab3dd716a6e16dde321bf Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 2 Sep 2023 15:48:50 +0000 Subject: [PATCH] New default pushrules Add handling for new default push rules added in 1.7 also add a generic unknown handling for if any others are added in the future so they don't appear in keywords --- src/models/pushrulemodel.cpp | 9 +++++++ src/models/pushrulemodel.h | 4 +++ src/qml/Settings/GlobalNotificationsPage.qml | 26 ++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/models/pushrulemodel.cpp b/src/models/pushrulemodel.cpp index 632971302..a3ee19d38 100644 --- a/src/models/pushrulemodel.cpp +++ b/src/models/pushrulemodel.cpp @@ -23,6 +23,9 @@ static const QHash defaultRuleNames = { {QStringLiteral(".m.rule.encrypted"), QStringLiteral("Messages in encrypted group chats")}, {QStringLiteral(".m.rule.tombstone"), QStringLiteral("Room upgrade messages")}, {QStringLiteral(".m.rule.contains_display_name"), QStringLiteral("Messages containing my display name")}, + {QStringLiteral(".m.rule.is_user_mention"), QStringLiteral("Messages which mention my Matrix user ID.")}, + {QStringLiteral(".m.rule.is_room_mention"), QStringLiteral("Messages which mention a room.")}, + {QStringLiteral(".m.rule.contains_user_name"), QStringLiteral("Messages containing the local part of my Matrix ID.")}, {QStringLiteral(".m.rule.roomnotif"), QStringLiteral("Whole room (@room) notifications")}, {QStringLiteral(".m.rule.invite_for_me"), QStringLiteral("Invites to a room")}, {QStringLiteral(".m.rule.call"), QStringLiteral("Call invitation")}, @@ -37,6 +40,9 @@ static const QHash defaultSections = {QStringLiteral(".m.rule.encrypted"), PushNotificationSection::Room}, {QStringLiteral(".m.rule.tombstone"), PushNotificationSection::Room}, {QStringLiteral(".m.rule.contains_display_name"), PushNotificationSection::Mentions}, + {QStringLiteral(".m.rule.is_user_mention"), PushNotificationSection::Mentions}, + {QStringLiteral(".m.rule.is_room_mention"), PushNotificationSection::Mentions}, + {QStringLiteral(".m.rule.contains_user_name"), PushNotificationSection::Mentions}, {QStringLiteral(".m.rule.roomnotif"), PushNotificationSection::Mentions}, {QStringLiteral(".m.rule.invite_for_me"), PushNotificationSection::Invites}, {QStringLiteral(".m.rule.call"), PushNotificationSection::Undefined}, // TODO: make invites when VOIP added. @@ -140,6 +146,9 @@ PushNotificationSection::Section PushRuleModel::getSection(Quotient::PushRule ru if (defaultSections.contains(ruleId)) { return defaultSections.value(ruleId); } else { + if (rule.ruleId.startsWith(u'.')) { + return PushNotificationSection::Unknown; + } /** * If the rule name resolves to a matrix id for a room that the user is part * of it shouldn't appear in the global list as it's overriding the global diff --git a/src/models/pushrulemodel.h b/src/models/pushrulemodel.h index b19b75db9..476b84eae 100644 --- a/src/models/pushrulemodel.h +++ b/src/models/pushrulemodel.h @@ -83,12 +83,16 @@ public: Keywords, /**< Global Keyword push rules. */ RoomKeywords, /**< Keyword push rules that only apply to a specific room. */ Invites, /**< Push rules relating to invites. */ + Unknown, /**< New default push rules that have not been added to the model yet. */ /** * @brief Push rules that should never be shown. * * There are numerous rules that get set that shouldn't be shown in the general * list e.g. The array of rules used to override global settings in individual * rooms. + * + * This is specifically different to unknown which are just new default push + * rule that haven't been added to the model yet. */ Undefined, }; diff --git a/src/qml/Settings/GlobalNotificationsPage.qml b/src/qml/Settings/GlobalNotificationsPage.qml index 43ab38197..ef60de0ed 100644 --- a/src/qml/Settings/GlobalNotificationsPage.qml +++ b/src/qml/Settings/GlobalNotificationsPage.qml @@ -176,6 +176,32 @@ Kirigami.ScrollablePage { } } } + + MobileForm.FormHeader { + Layout.fillWidth: true + title: i18n("Unknown") + visible: unknownModel.rowCount() > 0 + } + MobileForm.FormCard { + Layout.fillWidth: true + visible: unknownModel.rowCount() > 0 + + contentItem: ColumnLayout { + spacing: 0 + Repeater { + model: KSortFilterProxyModel { + id: unknownModel + sourceModel: Controller.pushRuleModel + filterRowCallback: function(source_row, source_parent) { + let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole) + return sectionRole == PushNotificationSection.Unknown; + } + } + + delegate: ruleDelegate + } + } + } } Component {