api!(deltachat-jsonrpc): use kind as a tag for all union types

This commit is contained in:
link2xt
2023-08-03 19:37:26 +00:00
parent 954067eb6d
commit e12044e6af
16 changed files with 43 additions and 43 deletions

View File

@@ -54,14 +54,14 @@ class Chat:
"""
if duration is not None:
assert duration > 0, "Invalid duration"
dur: Union[str, dict] = {"Until": duration}
dur: dict = {"kind": "Until", "duration": duration}
else:
dur = "Forever"
dur = {"kind": "Forever"}
await self._rpc.set_chat_mute_duration(self.account.id, self.id, dur)
async def unmute(self) -> None:
"""Unmute this chat."""
await self._rpc.set_chat_mute_duration(self.account.id, self.id, "NotMuted")
await self._rpc.set_chat_mute_duration(self.account.id, self.id, {"kind": "NotMuted"})
async def pin(self) -> None:
"""Pin this chat."""

View File

@@ -106,10 +106,10 @@ class Client:
await self._process_messages() # Process old messages.
while True:
event = await self.account.wait_for_event()
event["type"] = EventType(event.type)
event["kind"] = EventType(event.kind)
event["account"] = self.account
await self._on_event(event)
if event.type == EventType.INCOMING_MSG:
if event.kind == EventType.INCOMING_MSG:
await self._process_messages()
stop = func(event)

View File

@@ -83,7 +83,7 @@ class RawEvent(EventFilter):
return False
async def filter(self, event: "AttrDict") -> bool:
if self.types and event.type not in self.types:
if self.types and event.kind not in self.types:
return False
return await self._call_func(event)

View File

@@ -57,7 +57,7 @@ class ACFactory:
while True:
event = await account.wait_for_event()
print(event)
if event.type == EventType.IMAP_INBOX_IDLE:
if event.kind == EventType.IMAP_INBOX_IDLE:
break
return account
@@ -98,7 +98,7 @@ class ACFactory:
group=group,
)
return await to_client.run_until(lambda e: e.type == EventType.INCOMING_MSG)
return await to_client.run_until(lambda e: e.kind == EventType.INCOMING_MSG)
@pytest_asyncio.fixture