2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2023-01-26 09:47:30 +01:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2022-12-26 17:47:08 +01:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat_encryption_settings/chat_encryption_settings.dart';
|
2023-02-17 08:45:49 +01:00
|
|
|
import 'package:fluffychat/utils/beautify_string_extension.dart';
|
2020-02-04 14:42:35 +01:00
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class ChatEncryptionSettingsView extends StatelessWidget {
|
2021-04-14 14:02:10 +02:00
|
|
|
final ChatEncryptionSettingsController controller;
|
2020-02-04 14:42:35 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const ChatEncryptionSettingsView(this.controller, {Key? key})
|
2021-05-22 09:13:47 +02:00
|
|
|
: super(key: key);
|
2020-06-25 16:29:06 +02:00
|
|
|
|
2020-02-04 14:42:35 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-26 17:47:08 +01:00
|
|
|
final room = controller.room;
|
|
|
|
return StreamBuilder<Object>(
|
2023-03-02 10:57:52 +01: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),
|
|
|
|
onPressed: () =>
|
|
|
|
VRouter.of(context).toSegments(['rooms', controller.roomId!]),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.endToEndEncryption),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => launchUrlString(AppConfig.encryptionTutorial),
|
|
|
|
child: Text(L10n.of(context)!.help),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
|
|
|
SwitchListTile(
|
|
|
|
secondary: CircleAvatar(
|
|
|
|
foregroundColor:
|
|
|
|
Theme.of(context).colorScheme.onPrimaryContainer,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
child: const Icon(Icons.lock_outlined),
|
2022-01-15 13:18:25 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
title: Text(L10n.of(context)!.encryptThisChat),
|
|
|
|
value: room.encrypted,
|
|
|
|
onChanged: controller.enableEncryption,
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/encryption.png',
|
|
|
|
width: 212,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Divider(height: 1),
|
|
|
|
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 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
if (room.encrypted) ...[
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context)!.deviceKeys,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
StreamBuilder(
|
|
|
|
stream: room.onUpdate.stream,
|
|
|
|
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}',
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator.adaptive(
|
|
|
|
strokeWidth: 2,
|
2023-02-17 16:34:01 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
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(
|
2023-02-17 08:45:49 +01:00
|
|
|
color:
|
2023-03-02 10:57:52 +01:00
|
|
|
Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.primaryContainer,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4.0),
|
|
|
|
child: Text(
|
|
|
|
deviceKeys[i].userId,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.primary,
|
|
|
|
fontSize: 12,
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2023-02-04 16:56:42 +01:00
|
|
|
),
|
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
deviceKeys[i].ed25519Key?.beautified ??
|
|
|
|
L10n.of(context)!.unknownEncryptionAlgorithm,
|
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: 'RobotoMono',
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2020-06-25 16:29:06 +02:00
|
|
|
),
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01: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 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
),
|
|
|
|
),
|
2022-12-26 17:47:08 +01:00
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-02-04 14:42:35 +01:00
|
|
|
}
|
|
|
|
}
|