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