Use nio.PushRuleKind instead of own enum
This commit is contained in:
@@ -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,48 +85,40 @@ 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()
|
||||
rule_id: str = field()
|
||||
order: int = field()
|
||||
default: bool = field()
|
||||
enabled: bool = True
|
||||
pattern: str = ""
|
||||
notify: bool = False
|
||||
highlight: bool = False
|
||||
bubble: bool = False
|
||||
sound: str = "" # usually "default" when set
|
||||
urgency_hint: bool = False
|
||||
id: Tuple[str, str] = field() # (kind.value, rule_id)
|
||||
kind: nio.PushRuleKind = field()
|
||||
rule_id: str = field()
|
||||
order: int = field()
|
||||
default: bool = field()
|
||||
enabled: bool = True
|
||||
pattern: str = ""
|
||||
notify: bool = False
|
||||
highlight: bool = False
|
||||
bubble: bool = False
|
||||
sound: str = "" # usually "default" when set
|
||||
urgency_hint: bool = False
|
||||
|
||||
def __lt__(self, other: "PushRule") -> bool:
|
||||
"""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.
|
||||
|
Reference in New Issue
Block a user