diff --git a/matrix/api.py b/matrix/api.py index ea01d08..dcb4fa6 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -431,6 +431,25 @@ class MatrixRedactMessage(MatrixGenericMessage): ) +class MatrixBacklogMessage(MatrixGenericMessage): + def __init__(self, client, room_id, token, limit): + self.room_id = room_id + + data = { + "room_id": self.room_id, + "start_token": token, + "direction": "b", + "limit": limit + } + + MatrixGenericMessage.__init__( + self, + MessageType.ROOM_MSG, + client.room_get_messages, + data + ) + + class MatrixUser: def __init__(self, name, display_name): self.name = name # type: str diff --git a/matrix/commands.py b/matrix/commands.py index 99a5f5b..d1be2a3 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -28,7 +28,8 @@ from matrix.api import ( MatrixMessage, MessageType, MatrixTopicMessage, - MatrixRedactMessage + MatrixRedactMessage, + MatrixBacklogMessage ) from matrix.utils import key_from_value, tags_from_line_data from matrix.plugin_options import DebugType @@ -110,8 +111,12 @@ def matrix_fetch_old_messages(server, room_id): if not prev_batch: return - message = MatrixMessage(server, OPTIONS, MessageType.ROOM_MSG, - room_id=room_id, token=prev_batch) + message = MatrixBacklogMessage( + server.client, + room_id=room_id, + token=prev_batch, + limit=OPTIONS.backlog_limit + ) server.send_or_queue(message)