chore: Improve message info dialog

This commit is contained in:
krille-chan 2024-09-27 17:43:02 +02:00
parent efad71e535
commit 188ce96ef3
No known key found for this signature in database

View file

@ -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;
}
}