fluffychat/lib/pages/chat_permissions_settings/chat_permissions_settings_view.dart

136 lines
5.5 KiB
Dart
Raw Normal View History

2021-04-15 08:48:26 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
2021-04-15 08:48:26 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:vrouter/vrouter.dart';
2021-04-15 08:48:26 +02:00
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/chat_permissions_settings/chat_permissions_settings.dart';
import 'package:fluffychat/pages/chat_permissions_settings/permission_list_tile.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-05-22 09:13:47 +02:00
class ChatPermissionsSettingsView extends StatelessWidget {
2021-04-15 08:48:26 +02:00
final ChatPermissionsSettingsController controller;
2021-05-22 09:13:47 +02:00
const ChatPermissionsSettingsView(this.controller, {Key key})
: super(key: key);
2021-04-15 08:48:26 +02:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-08-04 10:15:42 +02:00
leading: VRouter.of(context).path.startsWith('/spaces/')
? null
: IconButton(
2021-10-14 18:09:30 +02:00
icon: const Icon(Icons.close_outlined),
2021-08-15 13:26:16 +02:00
onPressed: () => VRouter.of(context)
.toSegments(['rooms', controller.roomId]),
2021-08-04 10:15:42 +02:00
),
2021-04-15 08:48:26 +02:00
title: Text(L10n.of(context).editChatPermissions),
),
body: MaxWidthBody(
withScrolling: true,
child: StreamBuilder(
stream: controller.onChanged,
builder: (context, _) {
final room =
2021-05-23 13:11:55 +02:00
Matrix.of(context).client.getRoomById(controller.roomId);
2021-04-15 08:48:26 +02:00
final powerLevelsContent = Map<String, dynamic>.from(
room.getState(EventTypes.RoomPowerLevels).content);
final powerLevels = Map<String, dynamic>.from(powerLevelsContent)
2021-10-14 18:09:30 +02:00
..removeWhere((k, v) => v is! int);
2021-04-15 08:48:26 +02:00
final eventsPowerLevels =
Map<String, dynamic>.from(powerLevelsContent['events'] ?? {})
2021-10-14 18:09:30 +02:00
..removeWhere((k, v) => v is! int);
2021-04-15 08:48:26 +02:00
return Column(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
for (var entry in powerLevels.entries)
PermissionsListTile(
permissionKey: entry.key,
permission: entry.value,
onTap: () => controller.editPowerLevel(
context, entry.key, entry.value),
),
2021-10-14 18:09:30 +02:00
const Divider(thickness: 1),
2021-04-15 08:48:26 +02:00
ListTile(
title: Text(
L10n.of(context).notifications,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
),
),
Builder(builder: (context) {
2021-10-14 18:09:30 +02:00
const key = 'rooms';
2021-04-15 08:48:26 +02:00
final int value = powerLevelsContent
.containsKey('notifications')
? powerLevelsContent['notifications']['rooms'] ?? 0
: 0;
return PermissionsListTile(
permissionKey: key,
permission: value,
category: 'notifications',
onTap: () => controller.editPowerLevel(
context, key, value,
category: 'notifications'),
);
}),
2021-10-14 18:09:30 +02:00
const Divider(thickness: 1),
2021-04-15 08:48:26 +02:00
ListTile(
title: Text(
L10n.of(context).configureChat,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
),
),
if (eventsPowerLevels != null)
for (var entry in eventsPowerLevels.entries)
PermissionsListTile(
permissionKey: entry.key,
category: 'events',
permission: entry.value,
onTap: () => controller.editPowerLevel(
context, entry.key, entry.value,
category: 'events'),
),
if (room.canSendEvent(EventTypes.RoomTombstone)) ...{
2021-10-14 18:09:30 +02:00
const Divider(thickness: 1),
FutureBuilder<Capabilities>(
2021-05-20 13:59:55 +02:00
future: room.client.getCapabilities(),
2021-04-15 08:48:26 +02:00
builder: (context, snapshot) {
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-15 08:48:26 +02:00
}
final String roomVersion = room
.getState(EventTypes.RoomCreate)
.content['room_version'] ??
'1';
return ListTile(
title: Text(
'${L10n.of(context).roomVersion}: $roomVersion'),
onTap: () =>
controller.updateRoomAction(snapshot.data),
);
},
),
},
],
),
],
);
},
),
),
);
}
}