fluffychat/lib/pages/chat_encryption_settings/chat_encryption_settings_view.dart

195 lines
8.3 KiB
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-10-26 18:50:34 +02:00
import 'package:vrouter/vrouter.dart';
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/chat_encryption_settings/chat_encryption_settings.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/widgets/matrix.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(
2021-10-14 18:09:30 +02:00
icon: const Icon(Icons.close_outlined),
2021-05-23 13:11:55 +02:00
onPressed: () =>
2021-08-15 13:26:16 +02:00
VRouter.of(context).toSegments(['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(
2021-10-14 18:09:30 +02:00
preferredSize: const Size.fromHeight(56),
2021-02-27 10:41:58 +01:00
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-10-14 18:09:30 +02:00
child: const Icon(Icons.lock),
2021-02-27 10:41:58 +01:00
),
),
),
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) {
2021-10-14 18:09:30 +02:00
return const Center(
2021-10-10 13:38:06 +02:00
child:
CircularProgressIndicator.adaptive(strokeWidth: 2));
2021-04-09 18:26:44 +02:00
}
final deviceKeys = snapshot.data;
return ListView.builder(
shrinkWrap: true,
2021-10-14 18:09:30 +02:00
physics: const NeverScrollableScrollPhysics(),
2021-04-09 18:26:44 +02:00
itemCount: deviceKeys.length,
itemBuilder: (BuildContext context, int i) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (i == 0 ||
deviceKeys[i].userId !=
deviceKeys[i - 1].userId) ...{
2021-10-14 18:09:30 +02:00
const Divider(height: 1, thickness: 1),
2021-04-09 18:26:44 +02:00
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: Text(
room
.getUserByMXIDSync(deviceKeys[i].userId)
.calcDisplayname(),
),
subtitle: Text(
deviceKeys[i].userId,
2021-10-17 14:15:29 +02:00
style: const TextStyle(
fontWeight: FontWeight.w300),
2021-04-09 18:26:44 +02:00
),
),
),
},
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: Colors.white,
backgroundColor: deviceKeys[i].color,
2021-04-09 18:26:44 +02:00
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-10-17 14:15:29 +02:00
style: const TextStyle(
fontWeight: FontWeight.w300),
2021-02-27 10:41:58 +01:00
),
2021-10-14 18:09:30 +02:00
const Spacer(),
2021-04-09 18:26:44 +02:00
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).unverified,
2021-04-09 18:26:44 +02:00
style: TextStyle(
fontSize: 14,
color: deviceKeys[i].color,
2021-04-09 18:26:44 +02:00
),
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
);
}
}
extension on DeviceKeys {
Color get color => blocked
? Colors.red
: verified
? Colors.green
: Colors.orange;
}