diff --git a/lib/src/room.dart b/lib/src/room.dart
index 8018922e..5e19eaa2 100644
--- a/lib/src/room.dart
+++ b/lib/src/room.dart
@@ -784,7 +784,10 @@ class Room {
.replaceAll('\n', '
'));
content['formatted_body'] =
'In reply to ${inReplyTo.senderId}
$replyHtml
$repliedHtml';
- content['body'] = replyText + "\n\n${content.tryGet('body', '')}";
+ // We escape all @room-mentions here to prevent accidental room pings when an admin
+ // replies to a message containing that!
+ content['body'] =
+ '${replyText.replaceAll('@room', '@\u200broom')}\n\n${content.tryGet('body', '')}';
content['m.relates_to'] = {
'm.in_reply_to': {
'event_id': inReplyTo.eventId,
diff --git a/test/room_test.dart b/test/room_test.dart
index 7270b666..8f537faa 100644
--- a/test/room_test.dart
+++ b/test/room_test.dart
@@ -499,6 +499,35 @@ void main() {
},
},
});
+
+ event = Event.fromJson({
+ 'event_id': '\$replyEvent',
+ 'content': {
+ 'body': 'Hey @room',
+ 'msgtype': 'm.text',
+ },
+ 'type': 'm.room.message',
+ 'sender': '@alice:example.org',
+ }, room);
+ FakeMatrixApi.calledEndpoints.clear();
+ resp = await room.sendTextEvent('Hello world',
+ txid: 'testtxid', inReplyTo: event);
+ expect(resp.startsWith('\$event'), true);
+ entry = FakeMatrixApi.calledEndpoints.entries
+ .firstWhere((p) => p.key.contains('/send/m.room.message/'));
+ content = json.decode(entry.value.first);
+ expect(content, {
+ 'body': '> <@alice:example.org> Hey @\u{200b}room\n\nHello world',
+ 'msgtype': 'm.text',
+ 'format': 'org.matrix.custom.html',
+ 'formatted_body':
+ 'In reply to @alice:example.org
Hey @room
Hello world',
+ 'm.relates_to': {
+ 'm.in_reply_to': {
+ 'event_id': '\$replyEvent',
+ },
+ },
+ });
});
test('send reaction', () async {