server: Send read markers after sending a message.

This commit is contained in:
Damir Jelić 2018-12-10 20:10:36 +01:00
parent eabaee6a1b
commit cf178a32c4
2 changed files with 18 additions and 8 deletions

View file

@ -486,7 +486,10 @@ def buffer_switch_cb(_, _signal, buffer_ptr):
continue continue
if room_buffer.should_send_read_marker: if room_buffer.should_send_read_marker:
server.room_send_read_marker(room_buffer) event_id = room_buffer.last_event_id
server.room_send_read_marker(
room_buffer.room.room_id, event_id)
room_buffer.last_read_event = event_id
if room_buffer.members_fetched: if room_buffer.members_fetched:
return W.WEECHAT_RC_OK return W.WEECHAT_RC_OK

View file

@ -673,26 +673,23 @@ class MatrixServer(object):
self.backlog_queue[uuid] = room_id self.backlog_queue[uuid] = room_id
self.send_or_queue(request) self.send_or_queue(request)
def room_send_read_marker(self, room_buffer): def room_send_read_marker(self, room_id, event_id):
"""Send read markers for the provided room. """Send read markers for the provided room.
Args: Args:
room_buffer(RoomBuffer): the room for which the read markers should room_id(str): the room for which the read markers should
be sent. be sent.
event_id(str): the event id where to set the marker
""" """
if not self.connected: if not self.connected:
return return
event_id = room_buffer.last_event_id
_, request = self.client.room_read_markers( _, request = self.client.room_read_markers(
room_buffer.room.room_id, room_id,
fully_read_event=event_id, fully_read_event=event_id,
read_event=event_id) read_event=event_id)
self.send(request) self.send(request)
room_buffer.last_read_event = event_id
def room_send_typing_notice(self, room_buffer): def room_send_typing_notice(self, room_buffer):
"""Send a typing notice for the provided room. """Send a typing notice for the provided room.
@ -863,6 +860,13 @@ class MatrixServer(object):
room_buffer.printed_before_ack_queue.remove(response.uuid) room_buffer.printed_before_ack_queue.remove(response.uuid)
def handle_own_messages(self, response): def handle_own_messages(self, response):
def send_marker():
if not room_buffer.read_markers_enabled:
return
self.room_send_read_marker(response.room_id, response.event_id)
room_buffer.last_read_event = response.event_id
room_buffer = self.room_buffers[response.room_id] room_buffer = self.room_buffers[response.room_id]
message = room_buffer.sent_messages_queue.pop(response.uuid) message = room_buffer.sent_messages_queue.pop(response.uuid)
message = message._replace(event_id=response.event_id) message = message._replace(event_id=response.event_id)
@ -871,13 +875,16 @@ class MatrixServer(object):
if response.uuid in room_buffer.printed_before_ack_queue: if response.uuid in room_buffer.printed_before_ack_queue:
room_buffer.replace_printed_line_by_uuid(response.uuid, message) room_buffer.replace_printed_line_by_uuid(response.uuid, message)
room_buffer.printed_before_ack_queue.remove(response.uuid) room_buffer.printed_before_ack_queue.remove(response.uuid)
send_marker()
return return
if isinstance(message, OwnAction): if isinstance(message, OwnAction):
room_buffer.self_action(message) room_buffer.self_action(message)
send_marker()
return return
if isinstance(message, OwnMessage): if isinstance(message, OwnMessage):
room_buffer.self_message(message) room_buffer.self_message(message)
send_marker()
return return
raise NotImplementedError( raise NotImplementedError(