Add notification options to room context menu

This commit is contained in:
miruka 2021-02-28 09:00:36 -04:00
parent 716b480550
commit af321d8eae
3 changed files with 83 additions and 2 deletions

View File

@ -1819,7 +1819,7 @@ class MatrixClient(nio.AsyncClient):
# Now edit the rule # Now edit the rule
old: Optional[PushRule] = None old: Optional[PushRule] = None
key = (old_kind.value, old_rule_id) key = (old_kind.value if old_kind else None, old_rule_id)
if None not in key: if None not in key:
old = self.models[self.user_id, "pushrules"].get(key) old = self.models[self.user_id, "pushrules"].get(key)
@ -1914,9 +1914,50 @@ class MatrixClient(nio.AsyncClient):
"""Remove an existing non-builtin pushrule.""" """Remove an existing non-builtin pushrule."""
kind = nio.PushRuleKind[kind] if isinstance(kind, str) else kind kind = nio.PushRuleKind[kind] if isinstance(kind, str) else kind
if (kind.value, rule_id) in self.models[self.user_id, "pushrules"]:
await self.delete_pushrule("global", kind, rule_id) await self.delete_pushrule("global", kind, rule_id)
async def _remove_room_override_rule(self, room_id: str) -> None:
for rule in self.models[self.user_id, "pushrules"].values():
override_kind = rule.kind is nio.PushRuleKind.override
this_room_cnd = nio.PushEventMatch("room_id", room_id).as_value
if (override_kind and rule.conditions == [this_room_cnd]):
print(rule)
await self.remove_pushrule(rule.kind, rule.rule_id)
async def room_pushrule_use_default(self, room_id: str) -> None:
await self._remove_room_override_rule(room_id)
await self.remove_pushrule(nio.PushRuleKind.room, room_id)
async def room_pushrule_all_events(self, room_id: str) -> None:
await self._remove_room_override_rule(room_id)
await self.edit_pushrule(
kind = nio.PushRuleKind.room,
rule_id = room_id,
actions = [nio.PushNotify(), nio.PushSetTweak("sound", "default")],
)
async def room_pushrule_highlights_only(self, room_id: str) -> None:
await self._remove_room_override_rule(room_id)
await self.edit_pushrule(nio.PushRuleKind.room, room_id, actions=[])
async def room_pushrule_ignore_all(self, room_id: str) -> None:
await self._remove_room_override_rule(room_id)
await self.remove_pushrule(nio.PushRuleKind.room, room_id)
cnd = nio.PushEventMatch("room_id", room_id)
await self.edit_pushrule(
nio.PushRuleKind.override, room_id, conditions=[cnd], actions=[],
)
# Functions to register/modify data into models # Functions to register/modify data into models
async def update_account_unread_counts(self) -> None: async def update_account_unread_counts(self) -> None:

View File

@ -136,6 +136,9 @@ HTile {
} }
contextMenu: HMenu { contextMenu: HMenu {
// This delegate is only used for nested menus
delegate: HMenuItem { icon.name: "room-menu-notifications" }
HMenuItem { HMenuItem {
icon.name: model.pinned ? "room-unpin": "room-pin" icon.name: model.pinned ? "room-unpin": "room-pin"
text: model.pinned ? qsTr("Unpin"): qsTr("Pin to top") text: model.pinned ? qsTr("Unpin"): qsTr("Pin to top")
@ -144,6 +147,40 @@ HTile {
) )
} }
HMenu {
title: qsTr("Notifications")
HMenuItem {
text: qsTr("Use default account settings")
onTriggered: py.callClientCoro(
model.for_account, "room_pushrule_use_default", [model.id],
)
}
HMenuItem {
text: qsTr("All new messages")
onTriggered: py.callClientCoro(
model.for_account, "room_pushrule_all_events", [model.id],
)
}
HMenuItem {
text: qsTr("Highlights only (replies, keywords...)")
onTriggered: py.callClientCoro(
model.for_account,
"room_pushrule_highlights_only",
[model.id],
)
}
HMenuItem {
text: qsTr("Ignore new messages")
onTriggered: py.callClientCoro(
model.for_account, "room_pushrule_ignore_all", [model.id],
)
}
}
HMenuItemPopupSpawner { HMenuItemPopupSpawner {
visible: joined visible: joined
enabled: model.can_invite && accountModel.presence !== "offline" enabled: model.can_invite && accountModel.presence !== "offline"

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m15 21c0 1.598-1.392 3-2.971 3s-3.029-1.402-3.029-3zm.137-17.055c-.644-.374-1.042-1.07-1.041-1.82v-.003c.001-1.172-.938-2.122-2.096-2.122s-2.097.95-2.097 2.122v.003c.001.751-.396 1.446-1.041 1.82-4.668 2.709-1.985 11.715-6.862 13.306v1.749h20v-1.749c-4.877-1.591-2.193-10.598-6.863-13.306zm-3.137-2.945c.552 0 1 .449 1 1 0 .552-.448 1-1 1s-1-.448-1-1c0-.551.448-1 1-1zm-6.451 16c1.189-1.667 1.605-3.891 1.964-5.815.447-2.39.869-4.648 2.354-5.509 1.38-.801 2.956-.76 4.267 0 1.485.861 1.907 3.119 2.354 5.509.359 1.924.775 4.148 1.964 5.815z"/>
</svg>

After

Width:  |  Height:  |  Size: 648 B