1818
1919from synapse .handlers ._base import BaseHandler
2020from synapse .types import ReadReceipt , get_domain_from_id
21+ from synapse .util .async_helpers import maybe_awaitable
2122
2223logger = logging .getLogger (__name__ )
2324
@@ -36,8 +37,7 @@ def __init__(self, hs):
3637 self .clock = self .hs .get_clock ()
3738 self .state = hs .get_state_handler ()
3839
39- @defer .inlineCallbacks
40- def _received_remote_receipt (self , origin , content ):
40+ async def _received_remote_receipt (self , origin , content ):
4141 """Called when we receive an EDU of type m.receipt from a remote HS.
4242 """
4343 receipts = []
@@ -62,17 +62,16 @@ def _received_remote_receipt(self, origin, content):
6262 )
6363 )
6464
65- yield self ._handle_new_receipts (receipts )
65+ await self ._handle_new_receipts (receipts )
6666
67- @defer .inlineCallbacks
68- def _handle_new_receipts (self , receipts ):
67+ async def _handle_new_receipts (self , receipts ):
6968 """Takes a list of receipts, stores them and informs the notifier.
7069 """
7170 min_batch_id = None
7271 max_batch_id = None
7372
7473 for receipt in receipts :
75- res = yield self .store .insert_receipt (
74+ res = await self .store .insert_receipt (
7675 receipt .room_id ,
7776 receipt .receipt_type ,
7877 receipt .user_id ,
@@ -99,14 +98,15 @@ def _handle_new_receipts(self, receipts):
9998
10099 self .notifier .on_new_event ("receipt_key" , max_batch_id , rooms = affected_room_ids )
101100 # Note that the min here shouldn't be relied upon to be accurate.
102- yield self .hs .get_pusherpool ().on_new_receipts (
103- min_batch_id , max_batch_id , affected_room_ids
101+ await maybe_awaitable (
102+ self .hs .get_pusherpool ().on_new_receipts (
103+ min_batch_id , max_batch_id , affected_room_ids
104+ )
104105 )
105106
106107 return True
107108
108- @defer .inlineCallbacks
109- def received_client_receipt (self , room_id , receipt_type , user_id , event_id ):
109+ async def received_client_receipt (self , room_id , receipt_type , user_id , event_id ):
110110 """Called when a client tells us a local user has read up to the given
111111 event_id in the room.
112112 """
@@ -118,24 +118,11 @@ def received_client_receipt(self, room_id, receipt_type, user_id, event_id):
118118 data = {"ts" : int (self .clock .time_msec ())},
119119 )
120120
121- is_new = yield self ._handle_new_receipts ([receipt ])
121+ is_new = await self ._handle_new_receipts ([receipt ])
122122 if not is_new :
123123 return
124124
125- yield self .federation .send_read_receipt (receipt )
126-
127- @defer .inlineCallbacks
128- def get_receipts_for_room (self , room_id , to_key ):
129- """Gets all receipts for a room, upto the given key.
130- """
131- result = yield self .store .get_linearized_receipts_for_room (
132- room_id , to_key = to_key
133- )
134-
135- if not result :
136- return []
137-
138- return result
125+ await self .federation .send_read_receipt (receipt )
139126
140127
141128class ReceiptEventSource (object ):
0 commit comments