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,16 @@ 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
160
+ and receipt_type == ReceiptTypes .READ_PRIVATE
160
161
):
161
162
await self .federation_sender .send_read_receipt (receipt )
162
163
@@ -178,35 +179,27 @@ def filter_out_hidden(events: List[JsonDict], user_id: str) -> List[JsonDict]:
178
179
179
180
for event_id in content .keys ():
180
181
event_content = content .get (event_id , {})
181
- m_read = event_content .get (ReceiptTypes .READ , {})
182
182
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 ()
183
+ m_read = event_content . get ( ReceiptTypes . READ , None )
184
+ if m_read :
185
+ new_event ["content" ][event_id ] = { ReceiptTypes . READ : m_read }
186
186
continue
187
187
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
188
+ m_read_private = event_content .get (ReceiptTypes .READ_PRIVATE , None )
189
+ if m_read_private :
190
+ new_users = {}
191
+ for rr_user_id , user_rr in m_read_private .items ():
192
+ if rr_user_id == user_id :
193
+ new_users [rr_user_id ] = user_rr .copy ()
194
+
195
+ # Set new users unless empty
196
+ if len (new_users .keys ()) > 0 :
197
+ new_event ["content" ][event_id ] = {
198
+ ReceiptTypes .READ_PRIVATE : new_users
199
+ }
200
+ continue
197
201
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 }
202
+ new_event ["content" ][event_id ] = event_content
210
203
211
204
# Append new_event to visible_events unless empty
212
205
if len (new_event ["content" ].keys ()) > 0 :
0 commit comments