fluffychat/lib/views/chat_encryption_settings.dart

155 lines
5.7 KiB
Dart
Raw Normal View History

2020-02-04 14:42:35 +01:00
import 'dart:async';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
2020-02-23 09:31:44 +01:00
import 'package:fluffychat/components/avatar.dart';
2020-02-04 14:42:35 +01:00
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/beautify_string_extension.dart';
2020-05-07 07:52:40 +02:00
import 'package:fluffychat/l10n/l10n.dart';
2020-02-04 14:42:35 +01:00
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(
2020-05-07 07:52:40 +02:00
title: Text(L10n.of(context).participatingUserDevices),
2020-02-04 14:42:35 +01:00
),
body: Column(
children: <Widget>[
2020-02-23 09:31:44 +01:00
FutureBuilder<List<DeviceKeys>>(
future: room.getUserDeviceKeys(),
builder: (BuildContext context, snapshot) {
if (snapshot.hasError) {
return Center(
2020-05-07 07:52:40 +02:00
child: Text(L10n.of(context).oopsSomethingWentWrong +
2020-02-23 09:31:44 +01:00
": " +
snapshot.error.toString()),
2020-02-16 11:36:18 +01:00
);
}
2020-02-23 09:31:44 +01:00
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) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (i == 0 ||
deviceKeys[i].userId != deviceKeys[i - 1].userId)
Material(
child: ListTile(
leading: Avatar(
room
.getUserByMXIDSync(deviceKeys[i].userId)
.avatarUrl,
room
.getUserByMXIDSync(deviceKeys[i].userId)
.calcDisplayname(),
),
title: Text(room
.getUserByMXIDSync(deviceKeys[i].userId)
.calcDisplayname()),
subtitle: Text(deviceKeys[i].userId),
),
elevation: 2,
),
CheckboxListTile(
title: Text(
2020-05-07 07:52:40 +02:00
"${deviceKeys[i].unsigned["device_display_name"] ?? L10n.of(context).unknownDevice} - ${deviceKeys[i].deviceId}",
2020-02-23 09:31:44 +01:00
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(
2020-05-06 18:43:30 +02:00
color:
Theme.of(context).textTheme.bodyText2.color),
2020-02-23 09:31:44 +01:00
),
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);
},
),
],
),
),
);
2020-02-04 14:42:35 +01:00
},
),
2020-02-23 09:31:44 +01:00
Divider(thickness: 1, height: 1),
2020-02-04 14:42:35 +01:00
ListTile(
2020-02-23 09:31:44 +01:00
title: Text("Outbound MegOlm session ID:"),
2020-02-04 14:42:35 +01:00
subtitle: Text(
2020-02-23 09:31:44 +01:00
room.outboundGroupSession?.session_id()?.beautified ?? "None"),
2020-02-04 14:42:35 +01:00
),
],
),
);
}
}