buffer: Check for already printed events while fetching the backlog.

This commit is contained in:
Damir Jelić 2019-09-11 13:26:59 +02:00
parent 5924264139
commit f48a69a6b6

View file

@ -869,6 +869,7 @@ class RoomBuffer(object):
self.leave_event_id = None # type: Optional[str]
self.members_fetched = False
self.first_view = True
self.first_backlog_request = True
self.unhandled_users = [] # type: List[str]
self.inactive_users = []
@ -979,6 +980,14 @@ class RoomBuffer(object):
return ""
@property
def printed_event_ids(self):
for line in self.weechat_buffer.lines:
for tag in line.tags:
if tag.startswith("matrix_id"):
event_id = tag[10:]
yield event_id
@property
def read_markers_enabled(self):
# type: () -> bool
@ -1688,10 +1697,22 @@ class RoomBuffer(object):
self.prev_batch = response.end
for event in response.chunk:
# The first backlog request seems to have a race condition going on
# where we receive a message in a sync response, get a prev_batch,
# yet when we request older messages with the prev_batch the same
# message might appear in the room messages response. This only
# seems to happen if the message is relatively recently sent.
# Because of this we check if our first backlog request contains
# some already printed events, if so; skip printing them.
if (self.first_backlog_request
and event.event_id in self.printed_event_ids):
continue
self.old_message(event)
self.sort_messages()
self.first_backlog_request = False
self.backlog_pending = False
def handle_joined_room(self, info):