@@ -267,16 +267,29 @@ async def _set_reply(
267
267
if isinstance (evt , Message ) and isinstance (evt .peer_id , PeerChannel )
268
268
else source .tgid
269
269
)
270
+ if evt .reply_to .reply_to_peer_id and evt .reply_to .reply_to_peer_id != evt .peer_id :
271
+ if not self .config ["bridge.cross_room_replies" ]:
272
+ return
273
+ space = (
274
+ evt .reply_to .reply_to_peer_id .channel_id
275
+ if isinstance (evt .reply_to .reply_to_peer_id , PeerChannel )
276
+ else source .tgid
277
+ )
270
278
reply_to_id = TelegramID (evt .reply_to .reply_to_msg_id )
271
279
msg = await DBMessage .get_one_by_tgid (reply_to_id , space )
272
280
no_fallback = no_fallback or self .config ["bridge.disable_reply_fallbacks" ]
273
- if not msg or msg .mx_room != self .portal .mxid :
281
+ if not msg :
282
+ # TODO try to find room ID when generating deterministic ID for cross-room reply
274
283
if deterministic_id :
275
284
content .set_reply (self .deterministic_event_id (space , reply_to_id ))
276
285
return
286
+ elif msg .mx_room != self .portal .mxid and not self .config ["bridge.cross_room_replies" ]:
287
+ return
277
288
elif not isinstance (content , TextMessageEventContent ) or no_fallback :
278
289
# Not a text message, just set the reply metadata and return
279
290
content .set_reply (msg .mxid )
291
+ if msg .mx_room != self .portal .mxid :
292
+ content .relates_to .in_reply_to ["room_id" ] = msg .mx_room
280
293
return
281
294
282
295
# Text message, try to fetch original message to generate reply fallback.
@@ -291,6 +304,8 @@ async def _set_reply(
291
304
except Exception :
292
305
self .log .exception ("Failed to get event to add reply fallback" )
293
306
content .set_reply (msg .mxid )
307
+ if msg .mx_room != self .portal .mxid :
308
+ content .relates_to .in_reply_to ["room_id" ] = msg .mx_room
294
309
295
310
@staticmethod
296
311
def _photo_size_key (photo : TypePhotoSize ) -> int :
0 commit comments