Add saving of pushrules action changes
This commit is contained in:
parent
2480603ee2
commit
d5bcaca874
|
@ -41,8 +41,8 @@ from .errors import (
|
|||
from .html_markdown import HTML_PROCESSOR as HTML
|
||||
from .media_cache import Media, Thumbnail
|
||||
from .models.items import (
|
||||
ZERO_DATE, Account, Event, Member, Room, Transfer, TransferStatus,
|
||||
TypeSpecifier,
|
||||
ZERO_DATE, Account, Event, Member, PushRule, PushRuleKind, Room,
|
||||
Transfer, TransferStatus, TypeSpecifier,
|
||||
)
|
||||
from .models.model_store import ModelStore
|
||||
from .nio_callbacks import NioCallbacks
|
||||
|
@ -1781,6 +1781,57 @@ class MatrixClient(nio.AsyncClient):
|
|||
raise MatrixUnauthorized()
|
||||
|
||||
|
||||
async def tweak_pushrule(
|
||||
self,
|
||||
kind: Union[PushRuleKind, str],
|
||||
rule_id: str,
|
||||
notify: Optional[bool] = None,
|
||||
highlight: Optional[bool] = None,
|
||||
bubble: Optional[bool] = None,
|
||||
sound: Optional[bool] = None,
|
||||
urgency_hint: Optional[bool] = None,
|
||||
) -> None:
|
||||
|
||||
# XXX: [kind, rule_id]
|
||||
current: PushRule = self.models[self.user_id, "pushrules"][rule_id]
|
||||
|
||||
actions: List[nio.PushAction] = []
|
||||
|
||||
if notify or (notify is None and current.notify):
|
||||
actions.append(nio.PushNotify())
|
||||
|
||||
if highlight or (highlight is None and current.highlight):
|
||||
actions.append(nio.PushSetTweak("highlight", True))
|
||||
|
||||
if bubble or (bubble is None and current.bubble):
|
||||
actions.append(nio.PushSetTweak("bubble", True))
|
||||
elif bubble is False or (bubble is None and not current.bubble):
|
||||
actions.append(nio.PushSetTweak("bubble", False))
|
||||
|
||||
# XXX: don't always override with "default"
|
||||
if sound or (sound is None and current.sound):
|
||||
actions.append(nio.PushSetTweak("sound", "default"))
|
||||
|
||||
hint = urgency_hint
|
||||
|
||||
if hint or (hint is None and current.urgency_hint):
|
||||
actions.append(nio.PushSetTweak("urgency_hint", True))
|
||||
elif hint is False or (hint is None and not current.urgency_hint):
|
||||
actions.append(nio.PushSetTweak("urgency_hint", False))
|
||||
|
||||
nio_kind = nio.PushRuleKind[
|
||||
(kind if isinstance(kind, str) else kind.value).lower()
|
||||
]
|
||||
|
||||
print(nio_kind, rule_id, actions)
|
||||
await self.set_pushrule_actions("global", nio_kind, rule_id, actions)
|
||||
|
||||
|
||||
async def mass_tweak_pushrules(self, *tweaks_kwargs) -> None:
|
||||
coros = [self.tweak_pushrule(**kwargs) for kwargs in tweaks_kwargs]
|
||||
await asyncio.gather(*coros)
|
||||
|
||||
|
||||
# Functions to register/modify data into models
|
||||
|
||||
async def update_account_unread_counts(self) -> None:
|
||||
|
|
|
@ -784,7 +784,7 @@ class NioCallbacks:
|
|||
|
||||
async def onPushRulesEvent(self, ev: nio.PushRulesEvent) -> None:
|
||||
model = self.models[self.user_id, "pushrules"]
|
||||
model.clear()
|
||||
model.clear() # XXX
|
||||
|
||||
kinds: Dict[PushRuleKind, List[nio.PushRule]] = {
|
||||
PushRuleKind.Override: ev.global_rules.override,
|
||||
|
|
|
@ -4,9 +4,39 @@ import QtQuick 2.12
|
|||
import "../../Base"
|
||||
|
||||
HButton {
|
||||
property bool on: true
|
||||
property string toggles: ""
|
||||
|
||||
readonly property string key: JSON.stringify([model.kind, model.id])
|
||||
|
||||
readonly property bool on:
|
||||
toggles && page.pendingEdits[key] && toggles in page.pendingEdits[key]?
|
||||
page.pendingEdits[key][toggles] :
|
||||
|
||||
toggles ?
|
||||
model[toggles] :
|
||||
|
||||
true
|
||||
|
||||
|
||||
opacity: on ? 1 : theme.disabledElementsOpacity
|
||||
hoverEnabled: true
|
||||
backgroundColor: "transparent"
|
||||
|
||||
onClicked: {
|
||||
if (! toggles) return
|
||||
|
||||
if (! (key in page.pendingEdits)) page.pendingEdits[key] = {}
|
||||
|
||||
if ((! on) === model[toggles])
|
||||
delete page.pendingEdits[key][toggles]
|
||||
else
|
||||
page.pendingEdits[key][toggles] = ! on
|
||||
|
||||
if (! Object.keys(page.pendingEdits[key]).length)
|
||||
delete page.pendingEdits[key]
|
||||
|
||||
page.pendingEditsChanged()
|
||||
}
|
||||
|
||||
Behavior on opacity { HNumberAnimation {} }
|
||||
}
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import "../.."
|
||||
import "../../Base"
|
||||
import "../../Base/Buttons"
|
||||
import "../../Base/HTile"
|
||||
import "../../MainPane"
|
||||
import "../../PythonBridge"
|
||||
import "../../ShortcutBundles"
|
||||
|
||||
HTile {
|
||||
id: root
|
||||
|
||||
property string userId
|
||||
property Item page
|
||||
|
||||
readonly property QtObject matchingRoom:
|
||||
model.kind === "Room" ?
|
||||
ModelStore.get(userId, "rooms").find(model.id) :
|
||||
ModelStore.get(page.userId, "rooms").find(model.id) :
|
||||
null
|
||||
|
||||
|
||||
|
@ -69,7 +65,7 @@ HTile {
|
|||
|
||||
model.id === ".m.rule.contains_user_name" ?
|
||||
qsTr("Contains %1").arg(utils.coloredNameHtml(
|
||||
"", userId, userId.split(":")[0].substring(1),
|
||||
"", page.userId, page.userId.split(":")[0].substring(1),
|
||||
)):
|
||||
|
||||
model.id === ".m.rule.call" ?
|
||||
|
@ -103,7 +99,7 @@ HTile {
|
|||
|
||||
HRowLayout {
|
||||
NotificationRuleButton {
|
||||
on: model.notify
|
||||
toggles: "notify"
|
||||
|
||||
contentItem: MessageIndicator {
|
||||
indicatorTheme:
|
||||
|
@ -117,7 +113,7 @@ HTile {
|
|||
}
|
||||
|
||||
NotificationRuleButton {
|
||||
on: model.highlight
|
||||
toggles: "highlight"
|
||||
|
||||
contentItem: MessageIndicator {
|
||||
indicatorTheme:
|
||||
|
@ -134,17 +130,17 @@ HTile {
|
|||
|
||||
NotificationRuleButton {
|
||||
icon.name: "pushrule-action-bubble"
|
||||
on: model.bubble
|
||||
toggles: "bubble"
|
||||
}
|
||||
|
||||
NotificationRuleButton {
|
||||
icon.name: "pushrule-action-sound"
|
||||
on: model.sound
|
||||
toggles: "sound"
|
||||
}
|
||||
|
||||
NotificationRuleButton {
|
||||
icon.name: "pushrule-action-urgency-hint"
|
||||
on: model.urgency_hint
|
||||
toggles: "urgency_hint"
|
||||
}
|
||||
|
||||
HSpacer {}
|
||||
|
|
|
@ -6,7 +6,6 @@ import QtQuick.Layouts 1.12
|
|||
import "../.."
|
||||
import "../../Base"
|
||||
import "../../Base/Buttons"
|
||||
import "../../PythonBridge"
|
||||
import "../../ShortcutBundles"
|
||||
|
||||
HListView {
|
||||
|
@ -17,14 +16,38 @@ HListView {
|
|||
property bool enableFlickShortcuts:
|
||||
SwipeView ? SwipeView.isCurrentItem : true
|
||||
|
||||
// The object's array keys are run through `JSON.stringify(key)`.
|
||||
// {[kind, rule_id]: {notify, highlight, bubble, sound, urgency_hint}}
|
||||
property var pendingEdits: ({})
|
||||
property string saveFutureId: ""
|
||||
|
||||
function takeFocus() {
|
||||
// deviceList.headerItem.exportButton.forceActiveFocus()
|
||||
// deviceList.headerItem.exportButton.forceActiveFocus() TODO
|
||||
}
|
||||
|
||||
function save() {
|
||||
const args = []
|
||||
|
||||
for (const [kindRuleId, kwargs] of Object.entries(pendingEdits)) {
|
||||
const [kind, rule_id] = JSON.parse(kindRuleId)
|
||||
args.push(Object.assign({}, {kind, rule_id}, kwargs))
|
||||
}
|
||||
|
||||
saveFutureId = py.callClientCoro(
|
||||
userId,
|
||||
"mass_tweak_pushrules",
|
||||
args,
|
||||
() => {
|
||||
if (! root) return
|
||||
saveFutureId = ""
|
||||
pendingEdits = {}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
clip: true
|
||||
model: ModelStore.get(userId, "pushrules")
|
||||
bottomMargin: theme.spacing
|
||||
implicitHeight: Math.min(window.height, contentHeight + bottomMargin)
|
||||
|
||||
section.property: "kind"
|
||||
|
@ -42,10 +65,25 @@ HListView {
|
|||
}
|
||||
|
||||
delegate: NotificationRuleDelegate {
|
||||
userId: root.userId
|
||||
page: root
|
||||
width: root.width
|
||||
}
|
||||
|
||||
footer: AutoDirectionLayout {
|
||||
z: 100
|
||||
width: root.width
|
||||
enabled: Object.keys(root.pendingEdits).length !== 0
|
||||
|
||||
ApplyButton {
|
||||
onClicked: root.save()
|
||||
loading: root.saveFutureId !== ""
|
||||
}
|
||||
|
||||
CancelButton {
|
||||
onClicked: pendingEdits = {}
|
||||
}
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user