Use nio.PushRuleKind instead of own enum
This commit is contained in:
parent
8748c6445f
commit
35a8c0aec4
|
@ -41,7 +41,7 @@ from .errors import (
|
||||||
from .html_markdown import HTML_PROCESSOR as HTML
|
from .html_markdown import HTML_PROCESSOR as HTML
|
||||||
from .media_cache import Media, Thumbnail
|
from .media_cache import Media, Thumbnail
|
||||||
from .models.items import (
|
from .models.items import (
|
||||||
ZERO_DATE, Account, Event, Member, PushRule, PushRuleKind, Room,
|
ZERO_DATE, Account, Event, Member, PushRule, Room,
|
||||||
Transfer, TransferStatus, TypeSpecifier,
|
Transfer, TransferStatus, TypeSpecifier,
|
||||||
)
|
)
|
||||||
from .models.model_store import ModelStore
|
from .models.model_store import ModelStore
|
||||||
|
@ -1783,7 +1783,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
async def tweak_pushrule(
|
async def tweak_pushrule(
|
||||||
self,
|
self,
|
||||||
kind: Union[PushRuleKind, str],
|
kind: Union[nio.PushRuleKind, str],
|
||||||
rule_id: str,
|
rule_id: str,
|
||||||
notify: Optional[bool] = None,
|
notify: Optional[bool] = None,
|
||||||
highlight: Optional[bool] = None,
|
highlight: Optional[bool] = None,
|
||||||
|
@ -1792,8 +1792,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
urgency_hint: Optional[bool] = None,
|
urgency_hint: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
kind = PushRuleKind[kind] if isinstance(kind, str) else kind
|
kind = nio.PushRuleKind[kind] if isinstance(kind, str) else kind
|
||||||
nio_kind = nio.PushRuleKind[kind.value.lower()]
|
|
||||||
|
|
||||||
current: PushRule = \
|
current: PushRule = \
|
||||||
self.models[self.user_id, "pushrules"][kind.value, rule_id]
|
self.models[self.user_id, "pushrules"][kind.value, rule_id]
|
||||||
|
@ -1821,7 +1820,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
elif hint is False or (hint is None and not current.urgency_hint):
|
elif hint is False or (hint is None and not current.urgency_hint):
|
||||||
actions.append(nio.PushSetTweak("urgency_hint", False))
|
actions.append(nio.PushSetTweak("urgency_hint", False))
|
||||||
|
|
||||||
await self.set_pushrule_actions("global", nio_kind, rule_id, actions)
|
await self.set_pushrule_actions("global", kind, rule_id, actions)
|
||||||
|
|
||||||
|
|
||||||
async def mass_tweak_pushrules(self, *tweaks_kwargs) -> None:
|
async def mass_tweak_pushrules(self, *tweaks_kwargs) -> None:
|
||||||
|
|
|
@ -85,48 +85,40 @@ class Account(ModelItem):
|
||||||
return (self.order, self.id) < (other.order, other.id)
|
return (self.order, self.id) < (other.order, other.id)
|
||||||
|
|
||||||
|
|
||||||
class PushRuleKind(AutoStrEnum):
|
|
||||||
Override = auto()
|
|
||||||
Content = auto()
|
|
||||||
Room = auto()
|
|
||||||
Sender = auto()
|
|
||||||
Underride = auto()
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=False)
|
@dataclass(eq=False)
|
||||||
class PushRule(ModelItem):
|
class PushRule(ModelItem):
|
||||||
"""A push rule configured for one of our account."""
|
"""A push rule configured for one of our account."""
|
||||||
|
|
||||||
id: Tuple[str, str] = field() # (kind.value, rule_id)
|
id: Tuple[str, str] = field() # (kind.value, rule_id)
|
||||||
kind: PushRuleKind = field()
|
kind: nio.PushRuleKind = field()
|
||||||
rule_id: str = field()
|
rule_id: str = field()
|
||||||
order: int = field()
|
order: int = field()
|
||||||
default: bool = field()
|
default: bool = field()
|
||||||
enabled: bool = True
|
enabled: bool = True
|
||||||
pattern: str = ""
|
pattern: str = ""
|
||||||
notify: bool = False
|
notify: bool = False
|
||||||
highlight: bool = False
|
highlight: bool = False
|
||||||
bubble: bool = False
|
bubble: bool = False
|
||||||
sound: str = "" # usually "default" when set
|
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:
|
||||||
"""Sort by `kind`, then `order`."""
|
"""Sort by `kind`, then `order`."""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self.kind is PushRuleKind.Underride,
|
self.kind is nio.PushRuleKind.underride,
|
||||||
self.kind is PushRuleKind.Sender,
|
self.kind is nio.PushRuleKind.sender,
|
||||||
self.kind is PushRuleKind.Room,
|
self.kind is nio.PushRuleKind.room,
|
||||||
self.kind is PushRuleKind.Content,
|
self.kind is nio.PushRuleKind.content,
|
||||||
self.kind is PushRuleKind.Override,
|
self.kind is nio.PushRuleKind.override,
|
||||||
self.order,
|
self.order,
|
||||||
self.id,
|
self.id,
|
||||||
) < (
|
) < (
|
||||||
other.kind is PushRuleKind.Underride,
|
other.kind is nio.PushRuleKind.underride,
|
||||||
other.kind is PushRuleKind.Sender,
|
other.kind is nio.PushRuleKind.sender,
|
||||||
other.kind is PushRuleKind.Room,
|
other.kind is nio.PushRuleKind.room,
|
||||||
other.kind is PushRuleKind.Content,
|
other.kind is nio.PushRuleKind.content,
|
||||||
other.kind is PushRuleKind.Override,
|
other.kind is nio.PushRuleKind.override,
|
||||||
other.order,
|
other.order,
|
||||||
other.id,
|
other.id,
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@ import nio
|
||||||
|
|
||||||
from .html_markdown import HTML_PROCESSOR
|
from .html_markdown import HTML_PROCESSOR
|
||||||
from .media_cache import Media
|
from .media_cache import Media
|
||||||
from .models.items import PushRule, PushRuleKind, TypeSpecifier
|
from .models.items import PushRule, TypeSpecifier
|
||||||
from .presence import Presence
|
from .presence import Presence
|
||||||
from .pyotherside_events import DevicesUpdated
|
from .pyotherside_events import DevicesUpdated
|
||||||
from .utils import classes_defined_in, plain2html
|
from .utils import classes_defined_in, plain2html
|
||||||
|
@ -785,12 +785,8 @@ class NioCallbacks:
|
||||||
async def onPushRulesEvent(self, ev: nio.PushRulesEvent) -> None:
|
async def onPushRulesEvent(self, ev: nio.PushRulesEvent) -> None:
|
||||||
model = self.models[self.user_id, "pushrules"]
|
model = self.models[self.user_id, "pushrules"]
|
||||||
|
|
||||||
kinds: Dict[PushRuleKind, List[nio.PushRule]] = {
|
kinds: Dict[nio.PushRuleKind, List[nio.PushRule]] = {
|
||||||
PushRuleKind.Override: ev.global_rules.override,
|
kind: getattr(ev.global_rules, kind.value) for kind in nio.PushRuleKind
|
||||||
PushRuleKind.Content: ev.global_rules.content,
|
|
||||||
PushRuleKind.Room: ev.global_rules.room,
|
|
||||||
PushRuleKind.Sender: ev.global_rules.sender,
|
|
||||||
PushRuleKind.Underride: ev.global_rules.underride,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove from model rules that are now deleted.
|
# Remove from model rules that are now deleted.
|
||||||
|
|
|
@ -13,7 +13,7 @@ HTile {
|
||||||
property Item page
|
property Item page
|
||||||
|
|
||||||
readonly property QtObject matchingRoom:
|
readonly property QtObject matchingRoom:
|
||||||
model.kind === "Room" ?
|
model.kind === "room" ?
|
||||||
ModelStore.get(page.userId, "rooms").find(model.rule_id) :
|
ModelStore.get(page.userId, "rooms").find(model.rule_id) :
|
||||||
null
|
null
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ HTile {
|
||||||
textFormat:
|
textFormat:
|
||||||
model.rule_id === ".m.rule.contains_user_name" ||
|
model.rule_id === ".m.rule.contains_user_name" ||
|
||||||
model.rule_id === ".m.rule.roomnotif" ||
|
model.rule_id === ".m.rule.roomnotif" ||
|
||||||
model.kind === "Sender" ?
|
model.kind === "sender" ?
|
||||||
HLabel.StyledText :
|
HLabel.StyledText :
|
||||||
HLabel.PlainText
|
HLabel.PlainText
|
||||||
|
|
||||||
|
@ -83,10 +83,10 @@ HTile {
|
||||||
model.rule_id === ".m.rule.encrypted" ?
|
model.rule_id === ".m.rule.encrypted" ?
|
||||||
qsTr("Encrypted group messages") :
|
qsTr("Encrypted group messages") :
|
||||||
|
|
||||||
model.kind === "Content" ?
|
model.kind === "content" ?
|
||||||
qsTr('Contains "%1"').arg(model.pattern) :
|
qsTr('Contains "%1"').arg(model.pattern) :
|
||||||
|
|
||||||
model.kind === "Sender" ?
|
model.kind === "sender" ?
|
||||||
utils.coloredNameHtml("", model.rule_id) :
|
utils.coloredNameHtml("", model.rule_id) :
|
||||||
|
|
||||||
matchingRoom && matchingRoom.display_name ?
|
matchingRoom && matchingRoom.display_name ?
|
||||||
|
|
|
@ -54,14 +54,14 @@ HListView {
|
||||||
section.property: "kind"
|
section.property: "kind"
|
||||||
section.delegate: HLabel {
|
section.delegate: HLabel {
|
||||||
width: root.width
|
width: root.width
|
||||||
topPadding: padding * (section === "Override" ? 1 : 1.5)
|
topPadding: padding * (section === "override" ? 1 : 1.5)
|
||||||
padding: theme.spacing
|
padding: theme.spacing
|
||||||
font.pixelSize: theme.fontSize.big
|
font.pixelSize: theme.fontSize.big
|
||||||
text:
|
text:
|
||||||
section === "Override" ? qsTr("High-priority general rules") :
|
section === "override" ? qsTr("High-priority general rules") :
|
||||||
section === "Content" ? qsTr("Message text rules") :
|
section === "content" ? qsTr("Message text rules") :
|
||||||
section === "Room" ? qsTr("Room rules") :
|
section === "room" ? qsTr("Room rules") :
|
||||||
section === "Sender" ? qsTr("Sender rules") :
|
section === "sender" ? qsTr("Sender rules") :
|
||||||
qsTr("General rules")
|
qsTr("General rules")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user