Enhance chatencryptionsettings page

This commit is contained in:
Christian Pauly 2020-02-05 09:26:41 +01:00
parent 0116031812
commit 6f48a68798
6 changed files with 135 additions and 121 deletions

View file

@ -97,6 +97,11 @@ class MatrixState extends State<Matrix> {
hideLoadingDialog() => Navigator.of(_loadingDialogContext)?.pop();
bool get encryptionEnabled =>
client.userDeviceKeys.containsKey(client.userID) &&
client.userDeviceKeys[client.userID].deviceKeys
.containsKey(client.deviceID);
Future<String> downloadAndSaveContent(MxContent content,
{int width, int height, ThumbnailMethod method}) async {
final bool thumbnail = width == null && height == null ? false : true;

View file

@ -383,58 +383,61 @@ class _ChatState extends State<_Chat> {
),
SizedBox(width: 8),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: TextField(
minLines: 1,
maxLines: kIsWeb ? 1 : 8,
keyboardType: kIsWeb
? TextInputType.text
: TextInputType.multiline,
onSubmitted: (String text) {
send();
FocusScope.of(context).requestFocus(inputFocus);
},
focusNode: inputFocus,
controller: sendController,
decoration: InputDecoration(
hintText: I18n.of(context).writeAMessage,
border: InputBorder.none,
),
onChanged: (String text) {
this.typingCoolDown?.cancel();
this.typingCoolDown =
Timer(Duration(seconds: 2), () {
this.typingCoolDown = null;
this.currentlyTyping = false;
room.sendTypingInfo(false);
});
this.typingTimeout ??=
Timer(Duration(seconds: 30), () {
this.typingTimeout = null;
this.currentlyTyping = false;
});
if (!this.currentlyTyping) {
this.currentlyTyping = true;
room.sendTypingInfo(true,
timeout:
Duration(seconds: 30).inMilliseconds);
}
},
),
)),
SizedBox(width: 8),
if (sendController.text.isEmpty)
IconButton(
icon: Icon(
room.encrypted ? Icons.lock : Icons.lock_open),
onPressed: () => Navigator.of(context).push(
AppRoute.defaultRoute(
context,
ChatEncryptionSettingsView(widget.id),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: TextField(
minLines: 1,
maxLines: kIsWeb ? 1 : 8,
keyboardType: kIsWeb
? TextInputType.text
: TextInputType.multiline,
onSubmitted: (String text) {
send();
FocusScope.of(context).requestFocus(inputFocus);
},
focusNode: inputFocus,
controller: sendController,
decoration: InputDecoration(
hintText: I18n.of(context).writeAMessage,
border: InputBorder.none,
suffixIcon: sendController.text.isEmpty
? InkWell(
child: Icon(room.encrypted
? Icons.lock
: Icons.lock_open),
onTap: () => Navigator.of(context).push(
AppRoute.defaultRoute(
context,
ChatEncryptionSettingsView(
widget.id),
),
),
)
: null,
),
onChanged: (String text) {
this.typingCoolDown?.cancel();
this.typingCoolDown =
Timer(Duration(seconds: 2), () {
this.typingCoolDown = null;
this.currentlyTyping = false;
room.sendTypingInfo(false);
});
this.typingTimeout ??=
Timer(Duration(seconds: 30), () {
this.typingTimeout = null;
this.currentlyTyping = false;
});
if (!this.currentlyTyping) {
this.currentlyTyping = true;
room.sendTypingInfo(true,
timeout:
Duration(seconds: 30).inMilliseconds);
}
},
),
),
),
IconButton(
icon: Icon(Icons.send),
onPressed: () => send(),

View file

@ -8,6 +8,7 @@ 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';
import 'package:toast/toast.dart';
class ChatEncryptionSettingsView extends StatelessWidget {
final String id;
@ -49,6 +50,7 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
Widget build(BuildContext context) {
room ??= Matrix.of(context).client.getRoomById(widget.id);
roomUpdate ??= room.onUpdate.stream.listen((s) => setState(() => null));
print(Matrix.of(context).client.userDeviceKeys.length);
return Scaffold(
appBar: AppBar(
@ -59,15 +61,19 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
ListTile(
title: Text(I18n.of(context).encryptionAlgorithm),
subtitle: Text(room.encryptionAlgorithm ?? I18n.of(context).none),
trailing: Icon(room.encrypted ? Icons.lock : Icons.lock_open),
trailing: Icon(room.encrypted ? Icons.lock : Icons.lock_open,
color: room.encrypted ? Colors.green : Colors.red),
onTap: () {
if (room.encrypted) return;
if (!Matrix.of(context).encryptionEnabled) {
Toast.show(I18n.of(context).needPantalaimonWarning, context,
duration: 8);
return;
}
showDialog(
context: context,
builder: (BuildContext context) => ConfirmDialog(
I18n.of(context).enableEncryptionWarning +
" " +
I18n.of(context).needPantalaimonWarning,
I18n.of(context).enableEncryptionWarning,
I18n.of(context).yes,
(context) => Matrix.of(context).tryRequestWithLoadingDialog(
room.enableEncryption(),
@ -83,75 +89,77 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
),
),
Divider(height: 1),
ListTile(
title: Text(
"${I18n.of(context).participatingUserDevices}:",
style: TextStyle(
fontWeight: FontWeight.bold,
if (room.encrypted)
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);
}
if (room.encrypted) Divider(height: 1),
if (room.encrypted)
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]
.setVerified(true, Matrix.of(context).client);
} else {
if (deviceKeys[i].verified) {
.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(false, Matrix.of(context).client);
.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);
}
deviceKeys[i]
.setBlocked(true, Matrix.of(context).client);
}
setState(() => null);
},
setState(() => null);
},
),
),
),
);
},
),
);
},
),
],
),
);

View file

@ -110,8 +110,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "166b1a9464843cd17e86d9330ac8782d6081f46b"
resolved-ref: "166b1a9464843cd17e86d9330ac8782d6081f46b"
ref: "6a6ca40e96712d2ad3638fec7ec3ec5b17eaedca"
resolved-ref: "6a6ca40e96712d2ad3638fec7ec3ec5b17eaedca"
url: "https://gitlab.com/famedly/famedlysdk.git"
source: git
version: "0.0.1"

View file

@ -27,7 +27,7 @@ dependencies:
famedlysdk:
git:
url: https://gitlab.com/famedly/famedlysdk.git
ref: 166b1a9464843cd17e86d9330ac8782d6081f46b
ref: 4bf6a4bcb60ca8877b5f2d435978e47358c20cad
localstorage: ^3.0.1+4
bubble: ^1.1.9+1

View file

@ -7,8 +7,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:fluffychat/main.dart';
void main() {
testWidgets('Test if the app starts', (WidgetTester tester) async {
// Build our app and trigger a frame.