fluffychat/lib/pages/views/chat_encryption_settings_view.dart

206 lines
9.1 KiB
Dart
Raw Normal View History

import 'package:matrix/matrix.dart';
2021-05-22 08:57:49 +02:00
import 'package:fluffychat/pages/chat_encryption_settings.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2020-02-04 14:42:35 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.dart';
import '../../utils/matrix_sdk_extensions.dart/device_extension.dart';
2020-02-04 14:42:35 +01:00
2021-05-22 09:13:47 +02:00
class ChatEncryptionSettingsView extends StatelessWidget {
2021-04-14 14:02:10 +02:00
final ChatEncryptionSettingsController controller;
2020-02-04 14:42:35 +01:00
2021-05-22 09:13:47 +02:00
const ChatEncryptionSettingsView(this.controller, {Key key})
: super(key: key);
2020-06-25 16:29:06 +02:00
2020-02-04 14:42:35 +01:00
@override
Widget build(BuildContext context) {
2021-05-23 13:11:55 +02:00
final room = Matrix.of(context).client.getRoomById(controller.roomId);
2020-02-04 14:42:35 +01:00
return Scaffold(
appBar: AppBar(
2021-05-23 13:11:55 +02:00
leading: IconButton(
icon: Icon(Icons.close_outlined),
onPressed: () =>
2021-07-08 17:10:20 +02:00
VRouter.of(context).to('/rooms/${controller.roomId}'),
2021-05-23 13:11:55 +02:00
),
2021-02-27 10:41:58 +01:00
title: Text(L10n.of(context).tapOnDeviceToVerify),
bottom: PreferredSize(
preferredSize: Size.fromHeight(56),
child: ListTile(
title: Text(L10n.of(context).deviceVerifyDescription),
leading: CircleAvatar(
backgroundColor: Theme.of(context).secondaryHeaderColor,
2021-05-24 10:59:00 +02:00
foregroundColor: Theme.of(context).colorScheme.secondary,
2021-02-27 10:41:58 +01:00
child: Icon(Icons.lock),
),
),
),
2020-02-04 14:42:35 +01:00
),
2021-04-09 18:26:44 +02:00
body: MaxWidthBody(
withScrolling: true,
child: StreamBuilder(
stream: room.onUpdate.stream,
builder: (context, snapshot) {
return FutureBuilder<List<DeviceKeys>>(
future: room.getUserDeviceKeys(),
builder: (BuildContext context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(L10n.of(context).oopsSomethingWentWrong +
': ' +
snapshot.error.toString()),
);
}
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
final deviceKeys = snapshot.data;
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: deviceKeys.length,
itemBuilder: (BuildContext context, int i) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (i == 0 ||
deviceKeys[i].userId !=
deviceKeys[i - 1].userId) ...{
Divider(height: 1, thickness: 1),
PopupMenuButton(
2021-04-14 14:02:10 +02:00
onSelected: (action) => controller.onSelected(
context, action, deviceKeys[i]),
2021-04-09 18:26:44 +02:00
itemBuilder: (c) {
2021-04-14 10:37:15 +02:00
final items = <PopupMenuEntry<String>>[];
2021-04-09 18:26:44 +02:00
if (room
.client
.userDeviceKeys[deviceKeys[i].userId]
.verified ==
UserVerifiedStatus.unknown) {
items.add(PopupMenuItem(
value: 'verify_user',
child: Text(L10n.of(context).verifyUser),
));
}
return items;
},
child: ListTile(
leading: Avatar(
room
.getUserByMXIDSync(deviceKeys[i].userId)
.avatarUrl,
room
.getUserByMXIDSync(deviceKeys[i].userId)
.calcDisplayname(),
),
title: Row(
children: [
Text(
room
.getUserByMXIDSync(deviceKeys[i].userId)
.calcDisplayname(),
),
Spacer(),
Text(
deviceKeys[i].userId,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.textTheme
.bodyText1
.color
.withAlpha(150),
),
),
],
),
),
),
},
2021-02-27 10:41:58 +01:00
PopupMenuButton(
2021-04-14 14:02:10 +02:00
onSelected: (action) => controller.onSelected(
context, action, deviceKeys[i]),
2021-02-27 10:41:58 +01:00
itemBuilder: (c) {
2021-04-14 10:37:15 +02:00
final items = <PopupMenuEntry<String>>[];
2021-04-09 18:26:44 +02:00
if (deviceKeys[i].blocked ||
!deviceKeys[i].verified) {
2021-02-27 10:41:58 +01:00
items.add(PopupMenuItem(
2021-04-09 18:26:44 +02:00
value:
deviceKeys[i].userId == room.client.userID
? 'verify'
: 'verify_user',
child: Text(L10n.of(context).verifyStart),
));
}
if (deviceKeys[i].blocked) {
items.add(PopupMenuItem(
value: 'unblock',
child: Text(L10n.of(context).unblockDevice),
));
}
if (!deviceKeys[i].blocked) {
items.add(PopupMenuItem(
value: 'block',
child: Text(L10n.of(context).blockDevice),
2021-02-27 10:41:58 +01:00
));
}
return items;
},
child: ListTile(
2021-04-09 18:26:44 +02:00
leading: CircleAvatar(
foregroundColor:
Theme.of(context).textTheme.bodyText1.color,
backgroundColor:
Theme.of(context).secondaryHeaderColor,
child: Icon(deviceKeys[i].icon),
),
title: Text(
deviceKeys[i].displayname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
2021-02-27 10:41:58 +01:00
),
2021-04-09 18:26:44 +02:00
subtitle: Row(
2021-02-27 10:41:58 +01:00
children: [
Text(
2021-04-09 18:26:44 +02:00
deviceKeys[i].deviceId,
2021-02-27 10:41:58 +01:00
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.textTheme
.bodyText1
.color
.withAlpha(150),
),
),
2021-04-09 18:26:44 +02:00
Spacer(),
Text(
deviceKeys[i].blocked
? L10n.of(context).blocked
2021-02-27 10:41:58 +01:00
: deviceKeys[i].verified
2021-04-09 18:26:44 +02:00
? L10n.of(context).verified
: L10n.of(context).unknownDevice,
style: TextStyle(
fontSize: 14,
color: deviceKeys[i].blocked
? Colors.red
: deviceKeys[i].verified
? Colors.green
: Colors.orange,
),
2021-02-27 10:41:58 +01:00
),
2021-04-09 18:26:44 +02:00
],
),
2020-06-25 16:29:06 +02:00
),
),
2021-04-09 18:26:44 +02:00
],
),
);
},
);
}),
),
2020-02-04 14:42:35 +01:00
);
}
}