From 188ce96ef31680cccf34ed25734abc0f10511c68 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Fri, 27 Sep 2024 17:43:02 +0200 Subject: [PATCH] chore: Improve message info dialog --- lib/pages/chat/event_info_dialog.dart | 52 +++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/pages/chat/event_info_dialog.dart b/lib/pages/chat/event_info_dialog.dart index c930e4b14..fd2dcc68f 100644 --- a/lib/pages/chat/event_info_dialog.dart +++ b/lib/pages/chat/event_info_dialog.dart @@ -27,7 +27,7 @@ class EventInfoDialog extends StatelessWidget { super.key, }); - String get prettyJson { + String prettyJson(MatrixEvent event) { const decoder = JsonDecoder(); const encoder = JsonEncoder.withIndent(' '); final object = decoder.convert(jsonEncode(event.toJson())); @@ -37,6 +37,7 @@ class EventInfoDialog extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Theme.of(context); + final originalSource = event.originalSource; return Scaffold( appBar: AppBar( title: Text(L10n.of(context)!.messageInfo), @@ -61,48 +62,53 @@ class EventInfoDialog extends StatelessWidget { ), ), ListTile( - title: Text(L10n.of(context)!.time), + title: Text('${L10n.of(context)!.time}:'), subtitle: Text(event.originServerTs.localizedTime(context)), ), ListTile( - title: Text(L10n.of(context)!.messageType), - subtitle: Text(event.humanreadableType), + title: Text('${L10n.of(context)!.status}:'), + subtitle: Text(event.status.name), ), ListTile(title: Text('${L10n.of(context)!.sourceCode}:')), Padding( padding: const EdgeInsets.all(12.0), child: Material( borderRadius: BorderRadius.circular(AppConfig.borderRadius), - color: theme.colorScheme.inverseSurface, + color: theme.colorScheme.surfaceContainer, child: SingleChildScrollView( - padding: const EdgeInsets.all(8), + padding: const EdgeInsets.all(16), scrollDirection: Axis.horizontal, child: SelectableText( - prettyJson, + prettyJson(MatrixEvent.fromJson(event.toJson())), style: TextStyle( - color: theme.colorScheme.onInverseSurface, + color: theme.colorScheme.onSurface, ), ), ), ), ), + if (originalSource != null) ...[ + ListTile(title: Text('${L10n.of(context)!.encrypted}:')), + Padding( + padding: const EdgeInsets.all(12.0), + child: Material( + borderRadius: BorderRadius.circular(AppConfig.borderRadius), + color: theme.colorScheme.surfaceContainer, + child: SingleChildScrollView( + padding: const EdgeInsets.all(16), + scrollDirection: Axis.horizontal, + child: SelectableText( + prettyJson(originalSource), + style: TextStyle( + color: theme.colorScheme.onSurface, + ), + ), + ), + ), + ), + ], ], ), ); } } - -extension on Event { - String get humanreadableType { - if (type == EventTypes.Message) { - return messageType.split('m.').last; - } - if (type.startsWith('m.room.')) { - return type.split('m.room.').last; - } - if (type.startsWith('m.')) { - return type.split('m.').last; - } - return type; - } -}