2021-04-14 14:02:10 +02:00
|
|
|
import 'package:famedlysdk/encryption.dart';
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2021-04-15 13:03:14 +02:00
|
|
|
import 'package:fluffychat/views/ui/chat_encryption_settings_ui.dart';
|
2021-04-14 14:02:10 +02:00
|
|
|
import 'package:fluffychat/views/widgets/matrix.dart';
|
|
|
|
import 'package:flutter/material.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 {
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
const ChatEncryptionSettings(this.id, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
ChatEncryptionSettingsController createState() =>
|
|
|
|
ChatEncryptionSettingsController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChatEncryptionSettingsController extends State<ChatEncryptionSettings> {
|
|
|
|
Future<void> onSelected(
|
|
|
|
BuildContext context, String action, DeviceKeys key) async {
|
|
|
|
final room = Matrix.of(context).client.getRoomById(widget.id);
|
|
|
|
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-04-15 13:03:14 +02:00
|
|
|
Widget build(BuildContext context) => ChatEncryptionSettingsUI(this);
|
2021-04-14 14:02:10 +02:00
|
|
|
}
|