From 0ab2b7e443990e94221f23eba4a494a65f171d6d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 9 Jun 2022 08:48:37 +0200 Subject: [PATCH] refactor: add calcLocalizedBodyFallback method --- lib/src/event.dart | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index f94600a1..6218cd97 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -653,7 +653,7 @@ class Event extends MatrixEvent { await fetchSenderUser(); } - return _getLocalizedBody(i18n, + return calcLocalizedBodyFallback(i18n, withSenderNamePrefix: withSenderNamePrefix, hideReply: hideReply, hideEdit: hideEdit, @@ -661,22 +661,26 @@ class Event extends MatrixEvent { removeMarkdown: removeMarkdown); } - @Deprecated('Use calcLocalizedBody') + @Deprecated('Use calcLocalizedBody or calcLocalizedBodyFallback') String getLocalizedBody(MatrixLocalizations i18n, - {bool withSenderNamePrefix = false, - bool hideReply = false, - bool hideEdit = false, - bool plaintextBody = false, - bool removeMarkdown = false}) { - return _getLocalizedBody(i18n, - withSenderNamePrefix: withSenderNamePrefix, - hideReply: hideReply, - hideEdit: hideEdit, - plaintextBody: plaintextBody, - removeMarkdown: removeMarkdown); - } + {bool withSenderNamePrefix = false, + bool hideReply = false, + bool hideEdit = false, + bool plaintextBody = false, + bool removeMarkdown = false}) => + calcLocalizedBodyFallback(i18n, + withSenderNamePrefix: withSenderNamePrefix, + hideReply: hideReply, + hideEdit: hideEdit, + plaintextBody: plaintextBody, + removeMarkdown: removeMarkdown); - String _getLocalizedBody(MatrixLocalizations i18n, + /// Works similar to `calcLocalizedBody()` but does not wait for the sender + /// user to be fetched. If it is not in the cache it will just use the + /// fallback and display the localpart of the MXID according to the + /// values of `formatLocalpart` and `mxidLocalPartFallback` in the `Client` + /// class. + String calcLocalizedBodyFallback(MatrixLocalizations i18n, {bool withSenderNamePrefix = false, bool hideReply = false, bool hideEdit = false,