2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/encryption.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat_encryption_settings/chat_encryption_settings_view.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import '../key_verification/key_verification_dialog.dart';
|
2021-04-14 14:02:10 +02:00
|
|
|
|
|
|
|
class ChatEncryptionSettings extends StatefulWidget {
|
2022-01-29 12:35:03 +01:00
|
|
|
const ChatEncryptionSettings({Key? key}) : super(key: key);
|
2021-04-14 14:02:10 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
ChatEncryptionSettingsController createState() =>
|
|
|
|
ChatEncryptionSettingsController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChatEncryptionSettingsController extends State<ChatEncryptionSettings> {
|
2022-01-29 12:35:03 +01:00
|
|
|
String? get roomId => VRouter.of(context).pathParameters['roomid'];
|
2021-10-14 18:09:30 +02:00
|
|
|
|
|
|
|
Future<void> unblock(DeviceKeys key) async {
|
|
|
|
if (key.blocked) {
|
|
|
|
await key.setBlocked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:02:10 +02:00
|
|
|
Future<void> onSelected(
|
|
|
|
BuildContext context, String action, DeviceKeys key) async {
|
2022-01-29 12:35:03 +01:00
|
|
|
final room = Matrix.of(context).client.getRoomById(roomId!);
|
2021-04-14 14:02:10 +02:00
|
|
|
switch (action) {
|
|
|
|
case 'verify':
|
2021-10-14 18:09:30 +02:00
|
|
|
await unblock(key);
|
2021-04-14 14:02:10 +02:00
|
|
|
final req = key.startVerification();
|
|
|
|
req.onUpdate = () {
|
|
|
|
if (req.state == KeyVerificationState.done) {
|
2022-01-29 12:35:03 +01:00
|
|
|
setState(() {});
|
2021-04-14 14:02:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
await KeyVerificationDialog(request: req).show(context);
|
|
|
|
break;
|
|
|
|
case 'verify_user':
|
2021-10-14 18:09:30 +02:00
|
|
|
await unblock(key);
|
2021-04-14 14:02:10 +02:00
|
|
|
final req =
|
2022-01-29 12:35:03 +01:00
|
|
|
await room!.client.userDeviceKeys[key.userId]!.startVerification();
|
2021-04-14 14:02:10 +02:00
|
|
|
req.onUpdate = () {
|
|
|
|
if (req.state == KeyVerificationState.done) {
|
2022-01-29 12:35:03 +01:00
|
|
|
setState(() {});
|
2021-04-14 14:02:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
await KeyVerificationDialog(request: req).show(context);
|
|
|
|
break;
|
|
|
|
case 'block':
|
|
|
|
if (key.directVerified) {
|
|
|
|
await key.setVerified(false);
|
|
|
|
}
|
|
|
|
await key.setBlocked(true);
|
2022-01-29 12:35:03 +01:00
|
|
|
setState(() {});
|
2021-04-14 14:02:10 +02:00
|
|
|
break;
|
|
|
|
case 'unblock':
|
2021-10-14 18:09:30 +02:00
|
|
|
await unblock(key);
|
2022-01-29 12:35:03 +01:00
|
|
|
setState(() {});
|
2021-04-14 14:02:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-05-22 09:13:47 +02:00
|
|
|
Widget build(BuildContext context) => ChatEncryptionSettingsView(this);
|
2021-04-14 14:02:10 +02:00
|
|
|
}
|