Merge branch 'nico/fix-reply-fallback' into 'main'
fix: fallback in body for replies to replies Closes famedly/fluffychat#702 and famedly/fluffychat#359 See merge request famedly/company/frontend/famedlysdk!927
This commit is contained in:
commit
85bf49ddba
|
|
@ -747,6 +747,25 @@ class Room {
|
|||
);
|
||||
}
|
||||
|
||||
String _stripBodyFallback(String body) {
|
||||
if (body.startsWith('> <@')) {
|
||||
var temp = '';
|
||||
var inPrefix = true;
|
||||
for (final l in body.split('\n')) {
|
||||
if (inPrefix && (l.isEmpty || l.startsWith('> '))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inPrefix = false;
|
||||
temp += temp.isEmpty ? l : ('\n' + l);
|
||||
}
|
||||
|
||||
return temp;
|
||||
} else {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends an event to this room with this json as a content. Returns the
|
||||
/// event ID generated from the server.
|
||||
Future<String?> sendEvent(
|
||||
|
|
@ -765,7 +784,8 @@ class Room {
|
|||
}
|
||||
|
||||
if (inReplyTo != null) {
|
||||
var replyText = '<${inReplyTo.senderId}> ' + inReplyTo.body;
|
||||
var replyText =
|
||||
'<${inReplyTo.senderId}> ' + _stripBodyFallback(inReplyTo.body);
|
||||
replyText = replyText.split('\n').map((line) => '> $line').join('\n');
|
||||
content['format'] = 'org.matrix.custom.html';
|
||||
// be sure that we strip any previous reply fallbacks
|
||||
|
|
|
|||
|
|
@ -638,6 +638,44 @@ void main() {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Reply to a reply
|
||||
event = Event.fromJson({
|
||||
'event_id': '\$replyEvent',
|
||||
'content': {
|
||||
'body': '> <@alice:example.org> Hey\n\nHello world',
|
||||
'msgtype': 'm.text',
|
||||
'format': 'org.matrix.custom.html',
|
||||
'formatted_body':
|
||||
'<mx-reply><blockquote><a href="https://matrix.to/#/!localpart:server.abc/\$replyEvent">In reply to</a> <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a><br>Hey</blockquote></mx-reply>Hello world',
|
||||
'm.relates_to': {
|
||||
'm.in_reply_to': {
|
||||
'event_id': '\$replyEvent',
|
||||
},
|
||||
},
|
||||
},
|
||||
'type': 'm.room.message',
|
||||
'sender': '@alice:example.org',
|
||||
}, room);
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
resp =
|
||||
await room.sendTextEvent('Fox', 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> Hello world\n\nFox',
|
||||
'msgtype': 'm.text',
|
||||
'format': 'org.matrix.custom.html',
|
||||
'formatted_body':
|
||||
'<mx-reply><blockquote><a href="https://matrix.to/#/!localpart:server.abc/\$replyEvent">In reply to</a> <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a><br>Hello world</blockquote></mx-reply>Fox',
|
||||
'm.relates_to': {
|
||||
'm.in_reply_to': {
|
||||
'event_id': '\$replyEvent',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('send reaction', () async {
|
||||
|
|
|
|||
Loading…
Reference in New Issue