declare a ReadReceipt class
I'm going to use this in queues and things, so it'll be useful to give it more of a structure.
This commit is contained in:
parent
d42c81d724
commit
eed7271b3b
|
@ -16,7 +16,7 @@ import logging
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.types import get_domain_from_id
|
from synapse.types import ReadReceipt, get_domain_from_id
|
||||||
|
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ class ReceiptsHandler(BaseHandler):
|
||||||
"""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.
|
||||||
"""
|
"""
|
||||||
receipts = [
|
receipts = [
|
||||||
{
|
ReadReceipt(
|
||||||
"room_id": room_id,
|
room_id=room_id,
|
||||||
"receipt_type": receipt_type,
|
receipt_type=receipt_type,
|
||||||
"user_id": user_id,
|
user_id=user_id,
|
||||||
"event_ids": user_values["event_ids"],
|
event_ids=user_values["event_ids"],
|
||||||
"data": user_values.get("data", {}),
|
data=user_values.get("data", {}),
|
||||||
}
|
)
|
||||||
for room_id, room_values in content.items()
|
for room_id, room_values in content.items()
|
||||||
for receipt_type, users in room_values.items()
|
for receipt_type, users in room_values.items()
|
||||||
for user_id, user_values in users.items()
|
for user_id, user_values in users.items()
|
||||||
|
@ -64,14 +64,12 @@ class ReceiptsHandler(BaseHandler):
|
||||||
max_batch_id = None
|
max_batch_id = None
|
||||||
|
|
||||||
for receipt in receipts:
|
for receipt in receipts:
|
||||||
room_id = receipt["room_id"]
|
|
||||||
receipt_type = receipt["receipt_type"]
|
|
||||||
user_id = receipt["user_id"]
|
|
||||||
event_ids = receipt["event_ids"]
|
|
||||||
data = receipt["data"]
|
|
||||||
|
|
||||||
res = yield self.store.insert_receipt(
|
res = yield self.store.insert_receipt(
|
||||||
room_id, receipt_type, user_id, event_ids, data
|
receipt.room_id,
|
||||||
|
receipt.receipt_type,
|
||||||
|
receipt.user_id,
|
||||||
|
receipt.event_ids,
|
||||||
|
receipt.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not res:
|
if not res:
|
||||||
|
@ -107,15 +105,15 @@ class ReceiptsHandler(BaseHandler):
|
||||||
"""Called when a client tells us a local user has read up to the given
|
"""Called when a client tells us a local user has read up to the given
|
||||||
event_id in the room.
|
event_id in the room.
|
||||||
"""
|
"""
|
||||||
receipt = {
|
receipt = ReadReceipt(
|
||||||
"room_id": room_id,
|
room_id=room_id,
|
||||||
"receipt_type": receipt_type,
|
receipt_type=receipt_type,
|
||||||
"user_id": user_id,
|
user_id=user_id,
|
||||||
"event_ids": [event_id],
|
event_ids=[event_id],
|
||||||
"data": {
|
data={
|
||||||
"ts": int(self.clock.time_msec()),
|
"ts": int(self.clock.time_msec()),
|
||||||
}
|
},
|
||||||
}
|
)
|
||||||
|
|
||||||
is_new = yield self._handle_new_receipts([receipt])
|
is_new = yield self._handle_new_receipts([receipt])
|
||||||
if not is_new:
|
if not is_new:
|
||||||
|
@ -124,7 +122,7 @@ class ReceiptsHandler(BaseHandler):
|
||||||
# Work out which remote servers should be poked and poke them.
|
# Work out which remote servers should be poked and poke them.
|
||||||
|
|
||||||
# TODO: optimise this to move some of the work to the workers.
|
# TODO: optimise this to move some of the work to the workers.
|
||||||
data = receipt["data"]
|
data = receipt.data
|
||||||
|
|
||||||
# XXX why does this not use state.get_current_hosts_in_room() ?
|
# XXX why does this not use state.get_current_hosts_in_room() ?
|
||||||
users = yield self.state.get_current_user_in_room(room_id)
|
users = yield self.state.get_current_user_in_room(room_id)
|
||||||
|
|
|
@ -16,6 +16,8 @@ import re
|
||||||
import string
|
import string
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
|
|
||||||
|
|
||||||
|
@ -455,3 +457,13 @@ class ThirdPartyInstanceID(
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, appservice_id, network_id,):
|
def create(cls, appservice_id, network_id,):
|
||||||
return cls(appservice_id=appservice_id, network_id=network_id)
|
return cls(appservice_id=appservice_id, network_id=network_id)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(slots=True)
|
||||||
|
class ReadReceipt(object):
|
||||||
|
"""Information about a read-receipt"""
|
||||||
|
room_id = attr.ib()
|
||||||
|
receipt_type = attr.ib()
|
||||||
|
user_id = attr.ib()
|
||||||
|
event_ids = attr.ib()
|
||||||
|
data = attr.ib()
|
||||||
|
|
Loading…
Reference in New Issue