Add e2ee settings
parent
178e50a564
commit
c6c419f76d
@ -0,0 +1,36 @@
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ConfirmDialog extends StatelessWidget {
|
||||
const ConfirmDialog(
|
||||
this.text,
|
||||
this.confirmText,
|
||||
this.onConfirmed,
|
||||
);
|
||||
final String text;
|
||||
final String confirmText;
|
||||
final Function(BuildContext) onConfirmed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(text),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(I18n.of(context).close.toUpperCase(),
|
||||
style: TextStyle(color: Colors.blueGrey)),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(
|
||||
confirmText.toUpperCase(),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
onConfirmed(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../matrix.dart';
|
||||
|
||||
class RedactMessageDialog extends StatelessWidget {
|
||||
final Event event;
|
||||
const RedactMessageDialog(this.event);
|
||||
|
||||
void removeAction(BuildContext context) {
|
||||
Matrix.of(context).tryRequestWithLoadingDialog(event.redact());
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(I18n.of(context).messageWillBeRemovedWarning),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text("Close".toUpperCase(),
|
||||
style: TextStyle(color: Colors.blueGrey)),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(
|
||||
I18n.of(context).remove.toUpperCase(),
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
onPressed: () => removeAction(context),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
extension BeautifyStringExtension on String {
|
||||
String get beautified {
|
||||
String beautifiedStr = "";
|
||||
for (int i = 0; i < this.length; i++) {
|
||||
beautifiedStr += this.substring(i, i + 1);
|
||||
if (i % 4 == 3) {
|
||||
beautifiedStr += " ";
|
||||
}
|
||||
if (i % 16 == 15) {
|
||||
beautifiedStr += "\n";
|
||||
}
|
||||
}
|
||||
return beautifiedStr;
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/components/dialogs/confirm_dialog.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:fluffychat/utils/beautify_string_extension.dart';
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:fluffychat/views/chat_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ChatEncryptionSettingsView extends StatelessWidget {
|
||||
final String id;
|
||||
|
||||
const ChatEncryptionSettingsView(this.id, {Key key}) : super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AdaptivePageLayout(
|
||||
firstScaffold: ChatList(
|
||||
activeChat: id,
|
||||
),
|
||||
secondScaffold: ChatEncryptionSettings(id),
|
||||
primaryPage: FocusPage.SECOND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatEncryptionSettings extends StatefulWidget {
|
||||
final String id;
|
||||
|
||||
const ChatEncryptionSettings(this.id, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ChatEncryptionSettingsState createState() => _ChatEncryptionSettingsState();
|
||||
}
|
||||
|
||||
class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
|
||||
Room room;
|
||||
|
||||
StreamSubscription roomUpdate;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
roomUpdate?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
room ??= Matrix.of(context).client.getRoomById(widget.id);
|
||||
roomUpdate ??= room.onUpdate.stream.listen((s) => setState(() => null));
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(I18n.of(context).end2endEncryptionSettings),
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(I18n.of(context).encryptionAlgorithm),
|
||||
subtitle: Text(room.encryptionAlgorithm ?? I18n.of(context).none),
|
||||
trailing: Icon(room.encrypted ? Icons.lock : Icons.lock_open),
|
||||
onTap: () {
|
||||
if (room.encrypted) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => ConfirmDialog(
|
||||
I18n.of(context).enableEncryptionWarning +
|
||||
" " +
|
||||
I18n.of(context).needPantalaimonWarning,
|
||||
I18n.of(context).yes,
|
||||
(context) => Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
room.enableEncryption(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
trailing: Icon(Icons.info),
|
||||
subtitle: Text(
|
||||
I18n.of(context).needPantalaimonWarning,
|
||||
),
|
||||
),
|
||||
Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
"${I18n.of(context).participatingUserDevices}:",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(height: 1),
|
||||
FutureBuilder<List<DeviceKeys>>(
|
||||
future: room.getUserDeviceKeys(),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(I18n.of(context).oopsSomethingWentWrong +
|
||||
": " +
|
||||
snapshot.error.toString()),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final List<DeviceKeys> deviceKeys = snapshot.data;
|
||||
return Expanded(
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (BuildContext context, int i) =>
|
||||
Divider(height: 1),
|
||||
itemCount: deviceKeys.length,
|
||||
itemBuilder: (BuildContext context, int i) =>
|
||||
CheckboxListTile(
|
||||
title: Text(
|
||||
"${deviceKeys[i].userId} - ${deviceKeys[i].deviceId}",
|
||||
style: TextStyle(
|
||||
color: deviceKeys[i].blocked
|
||||
? Colors.red
|
||||
: deviceKeys[i].verified
|
||||
? Colors.green
|
||||
: Colors.orange),
|
||||
),
|
||||
subtitle: Text(
|
||||
deviceKeys[i]
|
||||
.keys["ed25519:${deviceKeys[i].deviceId}"]
|
||||
.beautified,
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
value: deviceKeys[i].verified,
|
||||
onChanged: (bool newVal) {
|
||||
if (newVal == true) {
|
||||
if (deviceKeys[i].blocked) {
|
||||
deviceKeys[i]
|
||||
.setBlocked(false, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setVerified(true, Matrix.of(context).client);
|
||||
} else {
|
||||
if (deviceKeys[i].verified) {
|
||||
deviceKeys[i]
|
||||
.setVerified(false, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setBlocked(true, Matrix.of(context).client);
|
||||
}
|
||||
setState(() => null);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue