Skip to content
This repository was archived by the owner on Mar 23, 2020. It is now read-only.

Commit 33b1602

Browse files
committed
Fix Room.backfill_previous_messages
It would always uselessly return the same previous batch
1 parent 9239f12 commit 33b1602

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

matrix_client/room.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, client, room_id, verify_devices=False):
5656
self.rotation_period_msgs = None
5757
self.rotation_period_ms = None
5858
self.verify_devices = verify_devices
59+
self.loaded_all_history = False
5960

6061
def set_user_profile(self,
6162
displayname=None,
@@ -562,8 +563,16 @@ def backfill_previous_messages(self, reverse=False, limit=10):
562563
order (old to new), otherwise the order will be reversed (new to old).
563564
limit (int): Number of messages to go back.
564565
"""
566+
if self.loaded_all_history:
567+
return
568+
565569
res = self.client.api.get_room_messages(self.room_id, self.prev_batch,
566570
direction="b", limit=limit)
571+
if res["end"] == self.prev_batch:
572+
self.loaded_all_history = True
573+
return
574+
self.prev_batch = res["end"]
575+
567576
events = res["chunk"]
568577
if not reverse:
569578
events = reversed(events)

0 commit comments

Comments
 (0)