fluffychat/lib/pages/chat/event_info_dialog.dart

99 lines
2.9 KiB
Dart
Raw Normal View History

2021-11-13 13:06:36 +01:00
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-11-22 19:27:40 +01:00
import 'package:fluffychat/config/app_config.dart';
2021-11-13 13:06:36 +01:00
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
extension EventInfoDialogExtension on Event {
void showInfoDialog(BuildContext context) => showModalBottomSheet(
context: context,
builder: (context) =>
2022-01-29 12:35:03 +01:00
EventInfoDialog(l10n: L10n.of(context)!, event: this),
2021-11-13 13:06:36 +01:00
);
}
class EventInfoDialog extends StatelessWidget {
final Event event;
final L10n l10n;
const EventInfoDialog({
2022-01-29 12:35:03 +01:00
required this.event,
required this.l10n,
Key? key,
2021-11-13 13:06:36 +01:00
}) : super(key: key);
String get prettyJson {
const JsonDecoder decoder = JsonDecoder();
2021-11-22 19:27:40 +01:00
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
2021-11-13 13:06:36 +01:00
final object = decoder.convert(jsonEncode(event.toJson()));
return encoder.convert(object);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.messageInfo),
2021-11-13 13:06:36 +01:00
leading: IconButton(
icon: const Icon(Icons.arrow_downward_outlined),
onPressed: Navigator.of(context, rootNavigator: false).pop,
2022-01-29 12:35:03 +01:00
tooltip: L10n.of(context)!.close,
2021-11-13 13:06:36 +01:00
),
),
body: ListView(
children: [
ListTile(
2021-11-20 10:42:23 +01:00
leading: Avatar(
mxContent: event.senderFromMemoryOrFallback.avatarUrl,
name: event.senderFromMemoryOrFallback.calcDisplayname(),
2021-11-20 10:42:23 +01:00
),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.sender),
subtitle: Text(
'${event.senderFromMemoryOrFallback.calcDisplayname()} [${event.senderId}]'),
2021-11-13 13:06:36 +01:00
),
ListTile(
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.time),
2021-11-13 13:06:36 +01:00
subtitle: Text(event.originServerTs.localizedTime(context)),
),
ListTile(
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.messageType),
2021-11-13 13:06:36 +01:00
subtitle: Text(event.humanreadableType),
),
2022-01-29 12:35:03 +01:00
ListTile(title: Text('${L10n.of(context)!.sourceCode}:')),
2021-11-13 13:06:36 +01:00
Padding(
padding: const EdgeInsets.all(12.0),
2021-11-22 19:27:40 +01:00
child: Material(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
color: Theme.of(context).colorScheme.surface,
child: SingleChildScrollView(
padding: const EdgeInsets.all(8),
scrollDirection: Axis.horizontal,
child: SelectableText(prettyJson),
),
2021-11-13 13:06:36 +01:00
),
),
],
),
);
}
}
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;
}
}