From e3d41bb4492c6ef74b9b8ea5b35ed9abc5940668 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 28 Sep 2024 14:40:22 +0200 Subject: [PATCH] fix: properly remove reply fallback from (un)localized body --- lib/src/event.dart | 5 ++- test/event_test.dart | 99 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index 3fbc6354..a257eb24 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -869,8 +869,9 @@ class Event extends MatrixEvent { var body = plaintextBody ? this.plaintextBody : this.body; // Html messages will already have their reply fallback removed during the Html to Text conversion. - var mayHaveReplyFallback = - !plaintextBody || content['format'] != 'org.matrix.custom.html'; + var mayHaveReplyFallback = !plaintextBody || + (content['format'] != 'org.matrix.custom.html' || + formattedText.isEmpty); // If we have an edit, we want to operate on the new content final newContent = content.tryGetMap('m.new_content'); diff --git a/test/event_test.dart b/test/event_test.dart index c55f3d3e..7e06e810 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -1686,6 +1686,105 @@ void main() { editFormattedBody: 'edit formatted body', editHtml: true, ); + + // test with reply fallback + testUnlocalizedBody( + expectation: 'body', + plaintextBody: false, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: true, + isEdit: false, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); + testUnlocalizedBody( + expectation: 'body', + plaintextBody: true, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: false, + isEdit: false, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); + testUnlocalizedBody( + expectation: 'body', + plaintextBody: true, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: null, + html: true, + isEdit: false, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); + testUnlocalizedBody( + expectation: '**formatted body**', + plaintextBody: true, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: true, + isEdit: false, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); + testUnlocalizedBody( + expectation: 'edit body', + plaintextBody: false, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: true, + isEdit: true, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); + testUnlocalizedBody( + expectation: 'edit body', + plaintextBody: true, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: true, + isEdit: true, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: false, + ); + testUnlocalizedBody( + expectation: '**edit formatted body**', + plaintextBody: true, + body: '> <@some:user.id> acb def\n\nbody', + formattedBody: + '
abc
formatted body', + html: true, + isEdit: true, + // strictly speaking there is no quote in edits, but we have to handle them anyway because of other clients doing it wrong + editBody: '> <@some:user.id> acb def\n\nedit body', + editFormattedBody: + '
abc
edit formatted body', + editHtml: true, + ); }); test('getDisplayEvent', () {