Store pushrules in model with (kind, rule_id) keys
Two rules of different kinds can have the same rule ID
This commit is contained in:
parent
d5bcaca874
commit
99c5346dba
|
@ -1792,8 +1792,11 @@ class MatrixClient(nio.AsyncClient):
|
|||
urgency_hint: Optional[bool] = None,
|
||||
) -> None:
|
||||
|
||||
# XXX: [kind, rule_id]
|
||||
current: PushRule = self.models[self.user_id, "pushrules"][rule_id]
|
||||
kind = PushRuleKind[kind] if isinstance(kind, str) else kind
|
||||
nio_kind = nio.PushRuleKind[kind.value.lower()]
|
||||
|
||||
current: PushRule = \
|
||||
self.models[self.user_id, "pushrules"][kind.value, rule_id]
|
||||
|
||||
actions: List[nio.PushAction] = []
|
||||
|
||||
|
@ -1819,11 +1822,6 @@ class MatrixClient(nio.AsyncClient):
|
|||
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)
|
||||
|
||||
|
||||
|
|
|
@ -97,8 +97,9 @@ class PushRuleKind(AutoStrEnum):
|
|||
class PushRule(ModelItem):
|
||||
"""A push rule configured for one of our account."""
|
||||
|
||||
id: str = field()
|
||||
id: Tuple[str, str] = field() # (kind.value, rule_id)
|
||||
kind: PushRuleKind = field()
|
||||
rule_id: str = field()
|
||||
order: int = field()
|
||||
default: bool = field()
|
||||
enabled: bool = True
|
||||
|
|
|
@ -813,9 +813,10 @@ class NioCallbacks:
|
|||
sound = tweaks.get("sound", False) is not False
|
||||
hint = tweaks.get("urgency_hint", high) is not False
|
||||
|
||||
model[rule.id] = PushRule(
|
||||
id = rule.id,
|
||||
model[kind.value, rule.id] = PushRule(
|
||||
id = (kind.value, rule.id),
|
||||
kind = kind,
|
||||
rule_id = rule.id,
|
||||
order = order,
|
||||
default = rule.default,
|
||||
enabled = rule.enabled,
|
||||
|
|
|
@ -6,11 +6,10 @@ import "../../Base"
|
|||
HButton {
|
||||
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 && page.pendingEdits[model.id] &&
|
||||
toggles in page.pendingEdits[model.id] ?
|
||||
page.pendingEdits[model.id][toggles] :
|
||||
|
||||
toggles ?
|
||||
model[toggles] :
|
||||
|
@ -25,15 +24,15 @@ HButton {
|
|||
onClicked: {
|
||||
if (! toggles) return
|
||||
|
||||
if (! (key in page.pendingEdits)) page.pendingEdits[key] = {}
|
||||
if (! (model.id in page.pendingEdits)) page.pendingEdits[model.id] = {}
|
||||
|
||||
if ((! on) === model[toggles])
|
||||
delete page.pendingEdits[key][toggles]
|
||||
delete page.pendingEdits[model.id][toggles]
|
||||
else
|
||||
page.pendingEdits[key][toggles] = ! on
|
||||
page.pendingEdits[model.id][toggles] = ! on
|
||||
|
||||
if (! Object.keys(page.pendingEdits[key]).length)
|
||||
delete page.pendingEdits[key]
|
||||
if (! Object.keys(page.pendingEdits[model.id]).length)
|
||||
delete page.pendingEdits[model.id]
|
||||
|
||||
page.pendingEditsChanged()
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ HTile {
|
|||
|
||||
readonly property QtObject matchingRoom:
|
||||
model.kind === "Room" ?
|
||||
ModelStore.get(page.userId, "rooms").find(model.id) :
|
||||
ModelStore.get(page.userId, "rooms").find(model.rule_id) :
|
||||
null
|
||||
|
||||
|
||||
|
@ -30,69 +30,69 @@ HTile {
|
|||
wrapMode: HLabel.Wrap
|
||||
|
||||
textFormat:
|
||||
model.id === ".m.rule.contains_user_name" ||
|
||||
model.id === ".m.rule.roomnotif" ||
|
||||
model.rule_id === ".m.rule.contains_user_name" ||
|
||||
model.rule_id === ".m.rule.roomnotif" ||
|
||||
model.kind === "Sender" ?
|
||||
HLabel.StyledText :
|
||||
HLabel.PlainText
|
||||
|
||||
text:
|
||||
model.id === ".m.rule.master" ?
|
||||
model.rule_id === ".m.rule.master" ?
|
||||
qsTr("Any message") :
|
||||
|
||||
model.id === ".m.rule.suppress_notices" ?
|
||||
model.rule_id === ".m.rule.suppress_notices" ?
|
||||
qsTr("Messages sent by bots") :
|
||||
|
||||
model.id === ".m.rule.invite_for_me" ?
|
||||
model.rule_id === ".m.rule.invite_for_me" ?
|
||||
qsTr("Received room invites") :
|
||||
|
||||
model.id === ".m.rule.member_event" ?
|
||||
model.rule_id === ".m.rule.member_event" ?
|
||||
qsTr("Membership, name & avatar changes") :
|
||||
|
||||
model.id === ".m.rule.contains_display_name" ?
|
||||
model.rule_id === ".m.rule.contains_display_name" ?
|
||||
qsTr("Messages containing my display name") :
|
||||
|
||||
model.id === ".m.rule.tombstone" ?
|
||||
model.rule_id === ".m.rule.tombstone" ?
|
||||
qsTr("Room migration alerts") :
|
||||
|
||||
model.id === ".m.rule.reaction" ?
|
||||
model.rule_id === ".m.rule.reaction" ?
|
||||
qsTr("Emoji reactions") :
|
||||
|
||||
model.id === ".m.rule.roomnotif" ?
|
||||
model.rule_id === ".m.rule.roomnotif" ?
|
||||
qsTr("Messages containing %1").arg(
|
||||
utils.htmlColorize("@room", theme.colors.accentText),
|
||||
) :
|
||||
|
||||
model.id === ".m.rule.contains_user_name" ?
|
||||
model.rule_id === ".m.rule.contains_user_name" ?
|
||||
qsTr("Contains %1").arg(utils.coloredNameHtml(
|
||||
"", page.userId, page.userId.split(":")[0].substring(1),
|
||||
)):
|
||||
|
||||
model.id === ".m.rule.call" ?
|
||||
model.rule_id === ".m.rule.call" ?
|
||||
qsTr("Incoming audio calls") :
|
||||
|
||||
model.id === ".m.rule.encrypted_room_one_to_one" ?
|
||||
model.rule_id === ".m.rule.encrypted_room_one_to_one" ?
|
||||
qsTr("Encrypted 1-to-1 messages") :
|
||||
|
||||
model.id === ".m.rule.room_one_to_one" ?
|
||||
model.rule_id === ".m.rule.room_one_to_one" ?
|
||||
qsTr("Unencrypted 1-to-1 messages") :
|
||||
|
||||
model.id === ".m.rule.message" ?
|
||||
model.rule_id === ".m.rule.message" ?
|
||||
qsTr("Unencrypted group messages") :
|
||||
|
||||
model.id === ".m.rule.encrypted" ?
|
||||
model.rule_id === ".m.rule.encrypted" ?
|
||||
qsTr("Encrypted group messages") :
|
||||
|
||||
model.kind === "Content" ?
|
||||
qsTr('Contains "%1"').arg(model.pattern) :
|
||||
|
||||
model.kind === "Sender" ?
|
||||
utils.coloredNameHtml("", model.id) :
|
||||
utils.coloredNameHtml("", model.rule_id) :
|
||||
|
||||
matchingRoom && matchingRoom.display_name ?
|
||||
matchingRoom.display_name :
|
||||
|
||||
model.id
|
||||
model.rule_id
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ 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}}
|
||||
// {model.id: {notify, highlight, bubble, sound, urgency_hint}}
|
||||
property var pendingEdits: ({})
|
||||
property string saveFutureId: ""
|
||||
|
||||
|
@ -28,8 +27,8 @@ HListView {
|
|||
function save() {
|
||||
const args = []
|
||||
|
||||
for (const [kindRuleId, kwargs] of Object.entries(pendingEdits)) {
|
||||
const [kind, rule_id] = JSON.parse(kindRuleId)
|
||||
for (const [modelId, kwargs] of Object.entries(pendingEdits)) {
|
||||
const [kind, rule_id] = JSON.parse(modelId)
|
||||
args.push(Object.assign({}, {kind, rule_id}, kwargs))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user