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