Skip to content
Snippets Groups Projects
Unverified Commit cd7110c8 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Merge pull request #4797 from matrix-org/rav/inline_rr_send

Clean up read-receipt handling.
parents 8e28bc5e b29693a3
No related branches found
No related tags found
No related merge requests found
Clean up read-receipt handling.
...@@ -16,7 +16,6 @@ import logging ...@@ -16,7 +16,6 @@ import logging
from twisted.internet import defer from twisted.internet import defer
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.types import get_domain_from_id from synapse.types import get_domain_from_id
from ._base import BaseHandler from ._base import BaseHandler
...@@ -38,31 +37,6 @@ class ReceiptsHandler(BaseHandler): ...@@ -38,31 +37,6 @@ class ReceiptsHandler(BaseHandler):
self.clock = self.hs.get_clock() self.clock = self.hs.get_clock()
self.state = hs.get_state_handler() self.state = hs.get_state_handler()
@defer.inlineCallbacks
def received_client_receipt(self, room_id, receipt_type, user_id,
event_id):
"""Called when a client tells us a local user has read up to the given
event_id in the room.
"""
receipt = {
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id,
"event_ids": [event_id],
"data": {
"ts": int(self.clock.time_msec()),
}
}
is_new = yield self._handle_new_receipts([receipt])
if is_new:
# fire off a process in the background to send the receipt to
# remote servers
run_as_background_process(
'push_receipts_to_remotes', self._push_remotes, receipt
)
@defer.inlineCallbacks @defer.inlineCallbacks
def _received_remote_receipt(self, origin, content): def _received_remote_receipt(self, origin, content):
"""Called when we receive an EDU of type m.receipt from a remote HS. """Called when we receive an EDU of type m.receipt from a remote HS.
...@@ -128,43 +102,54 @@ class ReceiptsHandler(BaseHandler): ...@@ -128,43 +102,54 @@ class ReceiptsHandler(BaseHandler):
defer.returnValue(True) defer.returnValue(True)
@defer.inlineCallbacks @defer.inlineCallbacks
def _push_remotes(self, receipt): def received_client_receipt(self, room_id, receipt_type, user_id,
"""Given a receipt, works out which remote servers should be event_id):
poked and pokes them. """Called when a client tells us a local user has read up to the given
event_id in the room.
""" """
try: receipt = {
# TODO: optimise this to move some of the work to the workers. "room_id": room_id,
room_id = receipt["room_id"] "receipt_type": receipt_type,
receipt_type = receipt["receipt_type"] "user_id": user_id,
user_id = receipt["user_id"] "event_ids": [event_id],
event_ids = receipt["event_ids"] "data": {
data = receipt["data"] "ts": int(self.clock.time_msec()),
}
}
users = yield self.state.get_current_user_in_room(room_id) is_new = yield self._handle_new_receipts([receipt])
remotedomains = set(get_domain_from_id(u) for u in users) if not is_new:
remotedomains = remotedomains.copy() return
remotedomains.discard(self.server_name)
# Work out which remote servers should be poked and poke them.
logger.debug("Sending receipt to: %r", remotedomains)
# TODO: optimise this to move some of the work to the workers.
for domain in remotedomains: data = receipt["data"]
self.federation.build_and_send_edu(
destination=domain, # XXX why does this not use state.get_current_hosts_in_room() ?
edu_type="m.receipt", users = yield self.state.get_current_user_in_room(room_id)
content={ remotedomains = set(get_domain_from_id(u) for u in users)
room_id: { remotedomains = remotedomains.copy()
receipt_type: { remotedomains.discard(self.server_name)
user_id: {
"event_ids": event_ids, logger.debug("Sending receipt to: %r", remotedomains)
"data": data,
} for domain in remotedomains:
self.federation.build_and_send_edu(
destination=domain,
edu_type="m.receipt",
content={
room_id: {
receipt_type: {
user_id: {
"event_ids": [event_id],
"data": data,
} }
}, }
}, },
key=(room_id, receipt_type, user_id), },
) key=(room_id, receipt_type, user_id),
except Exception: )
logger.exception("Error pushing receipts to remote servers")
@defer.inlineCallbacks @defer.inlineCallbacks
def get_receipts_for_room(self, room_id, to_key): def get_receipts_for_room(self, room_id, to_key):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment