From 4306098692e74be5e03cf8559d4a44037c5e1915 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 24 Feb 2021 14:35:43 -0400 Subject: [PATCH] Add actions to push rule settings popup --- docs/TODO.md | 2 + src/backend/matrix_client.py | 29 +++++--- .../PushRuleSettingsPopup/GeneralRule.qml | 2 +- .../PushRuleSettingsPopup.qml | 74 ++++++++++++++++++- src/icons/thin/pushrule-action-add.svg | 3 + 5 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 src/icons/thin/pushrule-action-add.svg diff --git a/docs/TODO.md b/docs/TODO.md index 776daaa8..5509cd4f 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -1,5 +1,7 @@ # TODO +- custom action +- sfx selection - combo box custom item - explain pattern - fix spinbox buttons diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 73b61913..be6cecd3 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -1795,7 +1795,9 @@ class MatrixClient(nio.AsyncClient): pattern: Optional[str] = None, actions: Optional[List[PushAction]] = None, ) -> None: - """Create or edit an existing non-builtin pushrule.""" + """Create or edit an existing non-builtin pushrule. + For builtin server ("default") rules, only actions can be edited. + """ # Convert arguments that were passed as basic types (usually from QML) @@ -1810,7 +1812,7 @@ class MatrixClient(nio.AsyncClient): ] if isinstance(conditions, list) else None actions = [ - nio.PushAction.from_dict(a) if isinstance(a, dict) else a + nio.PushAction.from_dict(a) if isinstance(a, (str, dict)) else a for a in actions ] if isinstance(actions, list) else None @@ -1835,16 +1837,19 @@ class MatrixClient(nio.AsyncClient): # Matrix API forces us to always pass a non-null actions paramater actions = [nio.PushAction.from_dict(a) for a in old.actions] - await self.set_pushrule( - scope = "global", - kind = kind, - rule_id = rule_id, - before = move_before_rule_id, - after = move_after_rule_id, - actions = actions or [], - conditions = conditions, - pattern = pattern, - ) + if old and old.default: + await self.set_pushrule_actions("global", kind, rule_id, actions) + else: + await self.set_pushrule( + scope = "global", + kind = kind, + rule_id = rule_id, + before = move_before_rule_id, + after = move_after_rule_id, + actions = actions or [], + conditions = conditions, + pattern = pattern, + ) # If we're editing an existing rule but its kind or ID is changed, # set_pushrule creates a new rule, thus we must delete the old one diff --git a/src/gui/Popups/PushRuleSettingsPopup/GeneralRule.qml b/src/gui/Popups/PushRuleSettingsPopup/GeneralRule.qml index 1a3a13be..fcc82b5e 100644 --- a/src/gui/Popups/PushRuleSettingsPopup/GeneralRule.qml +++ b/src/gui/Popups/PushRuleSettingsPopup/GeneralRule.qml @@ -38,7 +38,7 @@ HColumnLayout { Layout.topMargin: theme.spacing / 2 CustomLabel { - text: qsTr("Conditions for a message to trigger this rule:") + text: qsTr("Conditions for messages to trigger this rule:") } PositiveButton { diff --git a/src/gui/Popups/PushRuleSettingsPopup/PushRuleSettingsPopup.qml b/src/gui/Popups/PushRuleSettingsPopup/PushRuleSettingsPopup.qml index 631325ff..d0474aa6 100644 --- a/src/gui/Popups/PushRuleSettingsPopup/PushRuleSettingsPopup.qml +++ b/src/gui/Popups/PushRuleSettingsPopup/PushRuleSettingsPopup.qml @@ -35,6 +35,14 @@ HFlickableColumnPopup { positionCombo.model[positionCombo.currentIndex].rule_id : undefined + const actions = [] + const sfx = soundCheck.checked ? "default": false + notifyCheck.checked && actions.push("notify") + actions.push({set_tweak: "highlight", value: highlightCheck.checked}) + actions.push({set_tweak: "bubble", value: bubbleCheck.checked}) + actions.push({set_tweak: "sound", value: sfx}) + actions.push({set_tweak: "urgency_hint", value: urgencyCheck.checked}) + const args = [ checkedKind, details.idField.text, @@ -45,6 +53,7 @@ HFlickableColumnPopup { enableCheck.checked, generalChecked ? details.matrixConditions : undefined, contentRadio.checked ? details.idField.text : undefined, + actions, ] py.callClientCoro(userId, "edit_pushrule", args, root.close) @@ -169,9 +178,72 @@ HFlickableColumnPopup { GeneralRule { enabled: SwipeView.isCurrentItem } } + HColumnLayout { + spacing: theme.spacing / 2 + + HRowLayout { + CustomLabel { + text: qsTr("Actions for messages that trigger this rule:") + } + + PositiveButton { + icon.name: "pushrule-action-add" + iconItem.small: true + Layout.fillHeight: true + Layout.fillWidth: false + // onClicked: addConditionMenu.open() + } + } + + HCheckBox { + id: notifyCheck + text: qsTr("Mark as unread") + defaultChecked: root.rule.notify + Layout.fillWidth: true + } + + HCheckBox { + id: highlightCheck + text: qsTr("Mark as important") + enabled: notifyCheck.checked + defaultChecked: root.rule.highlight + Layout.fillWidth: true + } + + HCheckBox { + id: bubbleCheck + text: qsTr("Show notification bubble") + enabled: notifyCheck.checked + defaultChecked: root.rule.bubble + Layout.fillWidth: true + } + + HCheckBox { + id: soundCheck + text: qsTr("Play sound") + enabled: notifyCheck.checked + defaultChecked: root.rule.sound + Layout.fillWidth: true + } + + HCheckBox { + id: urgencyCheck + text: + Qt.platform === "windows" ? + qsTr("Make taskbar application icon flash") : + Qt.platform === "osx" ? + qsTr("Make dock application icon flash") : + qsTr("Highlight the application window") + + enabled: notifyCheck.checked + defaultChecked: root.rule.urgency_hint + Layout.fillWidth: true + } + } + HLabeledItem { visible: ! rule.default && positionCombo.model.length > 1 - label.text: qsTr("Position:") + label.text: qsTr("Rule position:") Layout.fillWidth: true HComboBox { diff --git a/src/icons/thin/pushrule-action-add.svg b/src/icons/thin/pushrule-action-add.svg new file mode 100644 index 00000000..b0ca843e --- /dev/null +++ b/src/icons/thin/pushrule-action-add.svg @@ -0,0 +1,3 @@ + + +