2023-06-03 16:27:26 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2023-08-02 10:08:23 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2021-06-18 08:29:48 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2023-01-26 08:47:30 +00:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2022-12-26 16:47:08 +00:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import 'package:fluffychat/pages/chat_encryption_settings/chat_encryption_settings.dart';
|
2023-02-17 07:45:49 +00:00
|
|
|
import 'package:fluffychat/utils/beautify_string_extension.dart';
|
2023-08-12 11:37:42 +00:00
|
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
2020-02-04 13:42:35 +00:00
|
|
|
|
2021-05-22 07:13:47 +00:00
|
|
|
class ChatEncryptionSettingsView extends StatelessWidget {
|
2021-04-14 12:02:10 +00:00
|
|
|
final ChatEncryptionSettingsController controller;
|
2020-02-04 13:42:35 +00:00
|
|
|
|
2023-10-28 11:03:16 +00:00
|
|
|
const ChatEncryptionSettingsView(this.controller, {super.key});
|
2020-06-25 14:29:06 +00:00
|
|
|
|
2020-02-04 13:42:35 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-04 12:09:36 +00:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
2022-12-26 16:47:08 +00:00
|
|
|
final room = controller.room;
|
|
|
|
return StreamBuilder<Object>(
|
2023-03-02 09:57:52 +00:00
|
|
|
stream: room.client.onSync.stream.where(
|
|
|
|
(s) => s.rooms?.join?[room.id] != null || s.deviceLists != null,
|
|
|
|
),
|
|
|
|
builder: (context, _) => Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.close_outlined),
|
2023-08-13 14:07:15 +00:00
|
|
|
onPressed: () => context.go('/rooms/${controller.roomId!}'),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2023-06-03 16:27:26 +00:00
|
|
|
title: Text(L10n.of(context)!.encryption),
|
2023-03-02 09:57:52 +00:00
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => launchUrlString(AppConfig.encryptionTutorial),
|
|
|
|
child: Text(L10n.of(context)!.help),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
body: MaxWidthBody(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
SwitchListTile(
|
|
|
|
secondary: CircleAvatar(
|
2024-08-04 12:09:36 +00:00
|
|
|
foregroundColor: theme.colorScheme.onPrimaryContainer,
|
|
|
|
backgroundColor: theme.colorScheme.primaryContainer,
|
2023-08-12 11:37:42 +00:00
|
|
|
child: const Icon(Icons.lock_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.encryptThisChat),
|
|
|
|
value: room.encrypted,
|
|
|
|
onChanged: controller.enableEncryption,
|
2022-01-15 12:18:25 +00:00
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
Icon(
|
|
|
|
CupertinoIcons.lock_shield,
|
|
|
|
size: 128,
|
2024-08-04 12:09:36 +00:00
|
|
|
color: theme.colorScheme.onInverseSurface,
|
2023-08-12 11:37:42 +00:00
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
if (room.isDirectChat)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
onPressed: controller.startVerification,
|
|
|
|
icon: const Icon(Icons.verified_outlined),
|
|
|
|
label: Text(L10n.of(context)!.verifyStart),
|
|
|
|
),
|
2022-12-26 16:47:08 +00:00
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
if (room.encrypted) ...[
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context)!.deviceKeys,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-12-26 16:47:08 +00:00
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
StreamBuilder(
|
2024-05-19 05:52:18 +00:00
|
|
|
stream: room.client.onRoomState.stream
|
|
|
|
.where((update) => update.roomId == controller.room.id),
|
2023-08-12 11:37:42 +00:00
|
|
|
builder: (context, snapshot) =>
|
|
|
|
FutureBuilder<List<DeviceKeys>>(
|
|
|
|
future: room.getUserDeviceKeys(),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
'${L10n.of(context)!.oopsSomethingWentWrong}: ${snapshot.error}',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator.adaptive(
|
|
|
|
strokeWidth: 2,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
final deviceKeys = snapshot.data!;
|
|
|
|
return ListView.builder(
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
itemCount: deviceKeys.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) =>
|
|
|
|
SwitchListTile(
|
|
|
|
value: !deviceKeys[i].blocked,
|
|
|
|
activeColor: deviceKeys[i].verified
|
|
|
|
? Colors.green
|
|
|
|
: Colors.orange,
|
|
|
|
onChanged: (_) =>
|
|
|
|
controller.toggleDeviceKey(deviceKeys[i]),
|
|
|
|
title: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
deviceKeys[i].verified
|
|
|
|
? Icons.verified_outlined
|
|
|
|
: deviceKeys[i].blocked
|
|
|
|
? Icons.block_outlined
|
|
|
|
: Icons.info_outlined,
|
|
|
|
color: deviceKeys[i].verified
|
|
|
|
? Colors.green
|
|
|
|
: deviceKeys[i].blocked
|
|
|
|
? Colors.red
|
|
|
|
: Colors.orange,
|
|
|
|
size: 20,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Text(
|
|
|
|
deviceKeys[i].deviceId ??
|
|
|
|
L10n.of(context)!.unknownDevice,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Flexible(
|
|
|
|
fit: FlexFit.loose,
|
|
|
|
child: Material(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
AppConfig.borderRadius,
|
|
|
|
),
|
|
|
|
side: BorderSide(
|
2024-08-04 12:09:36 +00:00
|
|
|
color: theme.colorScheme.primary,
|
2023-08-12 11:37:42 +00:00
|
|
|
),
|
|
|
|
),
|
2024-08-04 12:09:36 +00:00
|
|
|
color: theme.colorScheme.primaryContainer,
|
2023-08-12 11:37:42 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4.0),
|
|
|
|
child: Text(
|
|
|
|
deviceKeys[i].userId,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
2024-08-04 12:09:36 +00:00
|
|
|
color: theme.colorScheme.primary,
|
2023-08-12 11:37:42 +00:00
|
|
|
fontSize: 12,
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2022-12-26 16:47:08 +00:00
|
|
|
),
|
2023-02-04 15:56:42 +00:00
|
|
|
),
|
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
deviceKeys[i].ed25519Key?.beautified ??
|
|
|
|
L10n.of(context)!.unknownEncryptionAlgorithm,
|
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: 'RobotoMono',
|
2024-08-04 12:09:36 +00:00
|
|
|
color: theme.colorScheme.secondary,
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2022-12-26 16:47:08 +00:00
|
|
|
),
|
2020-06-25 14:29:06 +00:00
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
] else
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context)!.encryptionNotEnabled,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
2022-12-26 16:47:08 +00:00
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
|
|
|
),
|
2023-08-12 11:37:42 +00:00
|
|
|
],
|
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-02-04 13:42:35 +00:00
|
|
|
}
|
|
|
|
}
|