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,
highlight: Optional[bool] = None,
bubble: Optional[bool] = None,
sound: Optional[bool] = None,
sound: Optional[str] = None,
urgency_hint: Optional[bool] = None,
) -> None:
@ -1811,9 +1811,8 @@ class MatrixClient(nio.AsyncClient):
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"))
actions.append(nio.PushSetTweak("sound", sound))
hint = urgency_hint

View File

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

View File

@ -108,7 +108,11 @@ class Model(MutableMapping):
del self._sorted_data[index_then]
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

View File

@ -825,7 +825,7 @@ class NioCallbacks:
high = tweaks.get("highlight", False) 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
model[kind.value, rule.id] = PushRule(

View File

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

View File

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