send message without pipelining
This commit is contained in:
parent
6e4becd3df
commit
ade9615a74
1 changed files with 11 additions and 13 deletions
|
@ -41,7 +41,6 @@ class Client(Aobject):
|
||||||
__sync_token:Optional[str]
|
__sync_token:Optional[str]
|
||||||
__sync_token_queue: asyncio.Queue[str]
|
__sync_token_queue: asyncio.Queue[str]
|
||||||
__invite_queue: asyncio.Queue[tuple[RoomId, nio.responses.InviteInfo]]
|
__invite_queue: asyncio.Queue[tuple[RoomId, nio.responses.InviteInfo]]
|
||||||
__message_queue: asyncio.Queue[tuple[Union[RoomAlias, RoomId], dict[Any,Any]]]
|
|
||||||
whitelist_rooms: Optional[dict[RoomId, Room]]
|
whitelist_rooms: Optional[dict[RoomId, Room]]
|
||||||
|
|
||||||
async def __init__(
|
async def __init__(
|
||||||
|
@ -78,7 +77,6 @@ class Client(Aobject):
|
||||||
self.__sync_token = None
|
self.__sync_token = None
|
||||||
self.__sync_token_queue = asyncio.Queue()
|
self.__sync_token_queue = asyncio.Queue()
|
||||||
self.__invite_queue = asyncio.Queue()
|
self.__invite_queue = asyncio.Queue()
|
||||||
self.__message_queue = asyncio.Queue()
|
|
||||||
resp = await self.__client.login(password)
|
resp = await self.__client.login(password)
|
||||||
if isinstance(resp, nio.responses.LoginError):
|
if isinstance(resp, nio.responses.LoginError):
|
||||||
raise RuntimeError(f"Fail to connect: {resp.message}")
|
raise RuntimeError(f"Fail to connect: {resp.message}")
|
||||||
|
@ -142,7 +140,7 @@ class Client(Aobject):
|
||||||
"body": message,
|
"body": message,
|
||||||
"msgtype": "m.text"
|
"msgtype": "m.text"
|
||||||
}
|
}
|
||||||
await self.__message_queue.put((room, msg))
|
await self.__send_message(room, msg)
|
||||||
|
|
||||||
async def __save_sync_tocken(self)->NoReturn:
|
async def __save_sync_tocken(self)->NoReturn:
|
||||||
"""
|
"""
|
||||||
|
@ -187,16 +185,17 @@ class Client(Aobject):
|
||||||
|
|
||||||
self.__invite_queue.task_done()
|
self.__invite_queue.task_done()
|
||||||
|
|
||||||
async def __send_messages(self)->NoReturn:
|
async def __send_message(
|
||||||
|
self,
|
||||||
|
room_name: Union[RoomAlias, RoomId],
|
||||||
|
msg: dict[Any, Any]
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Send messages from the queue.
|
Send a message, take a room name and the dict of the message.
|
||||||
"""
|
"""
|
||||||
while True:
|
|
||||||
room_name, msg = await self.__message_queue.get()
|
|
||||||
room = await self.resolve_room(room_name)
|
room = await self.resolve_room(room_name)
|
||||||
await self.__client.room_send(room.id, "m.room.message", msg)
|
await self.__client.room_send(room.id, "m.room.message", msg)
|
||||||
log.debug(f"message sent to room {room.id}")
|
log.debug(f"message sent to room {room.id}")
|
||||||
self.__message_queue.task_done()
|
|
||||||
|
|
||||||
async def __sync(
|
async def __sync(
|
||||||
self,
|
self,
|
||||||
|
@ -233,8 +232,7 @@ class Client(Aobject):
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
self.__sync(sync_timeout=sync_timeout),
|
self.__sync(sync_timeout=sync_timeout),
|
||||||
self.__save_sync_tocken(),
|
self.__save_sync_tocken(),
|
||||||
self.__process_invites(),
|
self.__process_invites()
|
||||||
self.__send_messages(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue