14
14
import logging
15
15
from typing import TYPE_CHECKING , Iterable , List , Optional , Tuple
16
16
17
- from synapse .api .constants import ReadReceiptEventFields , ReceiptTypes
17
+ from synapse .api .constants import ReceiptTypes
18
18
from synapse .appservice import ApplicationService
19
19
from synapse .streams import EventSource
20
20
from synapse .types import JsonDict , ReadReceipt , UserID , get_domain_from_id
@@ -138,7 +138,7 @@ async def _handle_new_receipts(self, receipts: List[ReadReceipt]) -> bool:
138
138
return True
139
139
140
140
async def received_client_receipt (
141
- self , room_id : str , receipt_type : str , user_id : str , event_id : str , hidden : bool
141
+ self , room_id : str , receipt_type : str , user_id : str , event_id : str
142
142
) -> None :
143
143
"""Called when a client tells us a local user has read up to the given
144
144
event_id in the room.
@@ -148,15 +148,15 @@ async def received_client_receipt(
148
148
receipt_type = receipt_type ,
149
149
user_id = user_id ,
150
150
event_ids = [event_id ],
151
- data = {"ts" : int (self .clock .time_msec ()), "hidden" : hidden },
151
+ data = {"ts" : int (self .clock .time_msec ())},
152
152
)
153
153
154
154
is_new = await self ._handle_new_receipts ([receipt ])
155
155
if not is_new :
156
156
return
157
157
158
158
if self .federation_sender and not (
159
- self .hs .config .experimental .msc2285_enabled and hidden
159
+ self .hs .config .experimental .msc2285_enabled and receipt_type == ReceiptTypes . READ_PRIVATE
160
160
):
161
161
await self .federation_sender .send_read_receipt (receipt )
162
162
@@ -178,35 +178,25 @@ def filter_out_hidden(events: List[JsonDict], user_id: str) -> List[JsonDict]:
178
178
179
179
for event_id in content .keys ():
180
180
event_content = content .get (event_id , {})
181
- m_read = event_content .get (ReceiptTypes .READ , {})
182
181
183
- # If m_read is missing copy over the original event_content as there is nothing to process here
184
- if not m_read :
185
- new_event ["content" ][event_id ] = event_content . copy ()
182
+ m_read = event_content . get ( ReceiptTypes . READ , None )
183
+ if m_read :
184
+ new_event ["content" ][event_id ] = { ReceiptTypes . READ : m_read }
186
185
continue
187
186
188
- new_users = {}
189
- for rr_user_id , user_rr in m_read .items ():
190
- try :
191
- hidden = user_rr .get ("hidden" )
192
- except AttributeError :
193
- # Due to https://github.com/matrix-org/synapse/issues/10376
194
- # there are cases where user_rr is a string, in those cases
195
- # we just ignore the read receipt
196
- continue
187
+ m_read_private = event_content .get (ReceiptTypes .READ_PRIVATE , None )
188
+ if m_read_private :
189
+ new_users = {}
190
+ for rr_user_id , user_rr in m_read_private .items ():
191
+ if rr_user_id == user_id :
192
+ new_users [rr_user_id ] = user_rr .copy ()
193
+
194
+ # Set new users unless empty
195
+ if len (new_users .keys ()) > 0 :
196
+ new_event ["content" ][event_id ] = {ReceiptTypes .READ_PRIVATE : new_users }
197
+ continue
197
198
198
- if hidden is not True or rr_user_id == user_id :
199
- new_users [rr_user_id ] = user_rr .copy ()
200
- # If hidden has a value replace hidden with the correct prefixed key
201
- if hidden is not None :
202
- new_users [rr_user_id ].pop ("hidden" )
203
- new_users [rr_user_id ][
204
- ReadReceiptEventFields .MSC2285_HIDDEN
205
- ] = hidden
206
-
207
- # Set new users unless empty
208
- if len (new_users .keys ()) > 0 :
209
- new_event ["content" ][event_id ] = {ReceiptTypes .READ : new_users }
199
+ new_event ["content" ][event_id ] = event_content
210
200
211
201
# Append new_event to visible_events unless empty
212
202
if len (new_event ["content" ].keys ()) > 0 :
0 commit comments