Push rules sound: be a string, not just on/off

This commit is contained in:
miruka 2020-11-01 03:15:00 -04:00
parent d2fc003617
commit 8748c6445f
6 changed files with 19 additions and 10 deletions

View File

@ -1788,7 +1788,7 @@ class MatrixClient(nio.AsyncClient):
notify: Optional[bool] = None, notify: Optional[bool] = None,
highlight: Optional[bool] = None, highlight: Optional[bool] = None,
bubble: Optional[bool] = None, bubble: Optional[bool] = None,
sound: Optional[bool] = None, sound: Optional[str] = None,
urgency_hint: Optional[bool] = None, urgency_hint: Optional[bool] = None,
) -> None: ) -> None:
@ -1811,9 +1811,8 @@ class MatrixClient(nio.AsyncClient):
elif bubble is False or (bubble is None and not current.bubble): elif bubble is False or (bubble is None and not current.bubble):
actions.append(nio.PushSetTweak("bubble", False)) actions.append(nio.PushSetTweak("bubble", False))
# XXX: don't always override with "default"
if sound or (sound is None and current.sound): if sound or (sound is None and current.sound):
actions.append(nio.PushSetTweak("sound", "default")) actions.append(nio.PushSetTweak("sound", sound))
hint = urgency_hint hint = urgency_hint

View File

@ -107,7 +107,7 @@ class PushRule(ModelItem):
notify: bool = False notify: bool = False
highlight: bool = False highlight: bool = False
bubble: bool = False bubble: bool = False
sound: bool = False sound: str = "" # usually "default" when set
urgency_hint: bool = False urgency_hint: bool = False
def __lt__(self, other: "PushRule") -> bool: def __lt__(self, other: "PushRule") -> bool:

View File

@ -108,7 +108,11 @@ class Model(MutableMapping):
del self._sorted_data[index_then] del self._sorted_data[index_then]
self._sorted_data.add(new) self._sorted_data.add(new)
index_now = self._sorted_data.index(new) try:
index_now = self._sorted_data.index(new)
except ValueError:
import remote_pdb; remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
pass
# Insert into dict data # Insert into dict data

View File

@ -825,7 +825,7 @@ class NioCallbacks:
high = tweaks.get("highlight", False) is not False high = tweaks.get("highlight", False) is not False
bubble = tweaks.get("bubble", notify) is not False bubble = tweaks.get("bubble", notify) is not False
sound = tweaks.get("sound", False) is not False sound = str(tweaks.get("sound") or "")
hint = tweaks.get("urgency_hint", high) is not False hint = tweaks.get("urgency_hint", high) is not False
model[kind.value, rule.id] = PushRule( model[kind.value, rule.id] = PushRule(

View File

@ -5,14 +5,15 @@ import "../../Base"
HButton { HButton {
property string toggles: "" property string toggles: ""
property var nextValue: ! on
readonly property bool on: readonly property bool on:
toggles && page.pendingEdits[model.id] && toggles && page.pendingEdits[model.id] &&
toggles in page.pendingEdits[model.id] ? toggles in page.pendingEdits[model.id] ?
page.pendingEdits[model.id][toggles] : Boolean(page.pendingEdits[model.id][toggles]) :
toggles ? toggles ?
model[toggles] : Boolean(model[toggles]) :
true true
@ -26,10 +27,10 @@ HButton {
if (! (model.id in page.pendingEdits)) page.pendingEdits[model.id] = {} if (! (model.id in page.pendingEdits)) page.pendingEdits[model.id] = {}
if ((! on) === model[toggles]) if ((! on) === Boolean(model[toggles]))
delete page.pendingEdits[model.id][toggles] delete page.pendingEdits[model.id][toggles]
else else
page.pendingEdits[model.id][toggles] = ! on page.pendingEdits[model.id][toggles] = nextValue
if (! Object.keys(page.pendingEdits[model.id]).length) if (! Object.keys(page.pendingEdits[model.id]).length)
delete page.pendingEdits[model.id] delete page.pendingEdits[model.id]

View File

@ -136,6 +136,11 @@ HTile {
NotificationRuleButton { NotificationRuleButton {
icon.name: "pushrule-action-sound" icon.name: "pushrule-action-sound"
toggles: "sound" toggles: "sound"
nextValue:
on ? "" :
model[toggles] ? model[toggles] :
model.rule_id === ".m.rule.call" ? "ring" :
"default"
} }
NotificationRuleButton { NotificationRuleButton {