fluffychat/lib/pages/chat_encryption_settings.dart

66 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:matrix/encryption.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/pages/views/chat_encryption_settings_view.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/matrix.dart';
2021-04-14 14:02:10 +02:00
import 'package:flutter/material.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.dart';
2021-04-24 09:15:59 +02:00
import 'key_verification_dialog.dart';
2021-04-14 14:02:10 +02:00
class ChatEncryptionSettings extends StatefulWidget {
2021-05-23 13:11:55 +02: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> {
2021-05-23 13:11:55 +02:00
String get roomId => VRouter.of(context).pathParameters['roomid'];
2021-04-14 14:02:10 +02:00
Future<void> onSelected(
BuildContext context, String action, DeviceKeys key) async {
2021-05-23 13:11:55 +02:00
final room = Matrix.of(context).client.getRoomById(roomId);
2021-04-14 14:02:10 +02:00
final unblock = () async {
if (key.blocked) {
await key.setBlocked(false);
}
};
switch (action) {
case 'verify':
await unblock();
final req = key.startVerification();
req.onUpdate = () {
if (req.state == KeyVerificationState.done) {
setState(() => null);
}
};
await KeyVerificationDialog(request: req).show(context);
break;
case 'verify_user':
await unblock();
final req =
await room.client.userDeviceKeys[key.userId].startVerification();
req.onUpdate = () {
if (req.state == KeyVerificationState.done) {
setState(() => null);
}
};
await KeyVerificationDialog(request: req).show(context);
break;
case 'block':
if (key.directVerified) {
await key.setVerified(false);
}
await key.setBlocked(true);
setState(() => null);
break;
case 'unblock':
await unblock();
setState(() => null);
break;
}
}
@override
2021-05-22 09:13:47 +02:00
Widget build(BuildContext context) => ChatEncryptionSettingsView(this);
2021-04-14 14:02:10 +02:00
}