From 6d4f69e3a225d8d0d68d8b77c797fc06ff63492a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Thu, 22 Feb 2018 14:26:54 +0100 Subject: [PATCH] Disallow sending of multiple backlog messages in parallel. --- matrix/commands.py | 5 +++++ matrix/events.py | 1 + matrix/rooms.py | 17 +++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/matrix/commands.py b/matrix/commands.py index 7ae6cd7..6367420 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -108,6 +108,10 @@ def hook_commands(): def matrix_fetch_old_messages(server, room_id): room = server.rooms[room_id] + + if room.backlog_pending: + return + prev_batch = room.prev_batch if not prev_batch: @@ -119,6 +123,7 @@ def matrix_fetch_old_messages(server, room_id): token=prev_batch, limit=OPTIONS.backlog_limit ) + room.backlog_pending = True server.send_or_queue(message) diff --git a/matrix/events.py b/matrix/events.py index 2938ba1..cb84365 100644 --- a/matrix/events.py +++ b/matrix/events.py @@ -343,6 +343,7 @@ class MatrixBacklogEvent(MatrixEvent): message.prnt(room, buf, tags) room.prev_batch = self.end_token + room.backlog_pending = False class MatrixSyncEvent(MatrixEvent): diff --git a/matrix/rooms.py b/matrix/rooms.py index 85c4984..8887ab5 100644 --- a/matrix/rooms.py +++ b/matrix/rooms.py @@ -25,14 +25,15 @@ class MatrixRoom: def __init__(self, room_id): # type: (str) -> None # yapf: disable - self.room_id = room_id # type: str - self.alias = room_id # type: str - self.topic = "" # type: str - self.topic_author = "" # type: str - self.topic_date = None # type: datetime.datetime - self.prev_batch = "" # type: str - self.users = dict() # type: Dict[str, MatrixUser] - self.encrypted = False # type: bool + self.room_id = room_id # type: str + self.alias = room_id # type: str + self.topic = "" # type: str + self.topic_author = "" # type: str + self.topic_date = None # type: datetime.datetime + self.prev_batch = "" # type: str + self.users = dict() # type: Dict[str, MatrixUser] + self.encrypted = False # type: bool + self.backlog_pending = False # type: bool # yapf: enable