2021-04-15 06:48:26 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2021-04-15 06:48:26 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-04-15 06:48:26 +00:00
|
|
|
|
2024-04-15 08:12:37 +00:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
|
2021-04-15 06:48:26 +00:00
|
|
|
class PermissionsListTile extends StatelessWidget {
|
|
|
|
final String permissionKey;
|
|
|
|
final int permission;
|
2022-01-29 11:35:03 +00:00
|
|
|
final String? category;
|
2024-04-15 07:32:06 +00:00
|
|
|
final void Function(int? level)? onChanged;
|
|
|
|
final bool canEdit;
|
2021-04-15 06:48:26 +00:00
|
|
|
|
|
|
|
const PermissionsListTile({
|
2023-10-28 11:03:16 +00:00
|
|
|
super.key,
|
2022-01-29 11:35:03 +00:00
|
|
|
required this.permissionKey,
|
|
|
|
required this.permission,
|
2021-04-15 06:48:26 +00:00
|
|
|
this.category,
|
2024-04-15 07:32:06 +00:00
|
|
|
required this.onChanged,
|
|
|
|
required this.canEdit,
|
2023-10-28 11:03:16 +00:00
|
|
|
});
|
2021-04-15 06:48:26 +00:00
|
|
|
|
|
|
|
String getLocalizedPowerLevelString(BuildContext context) {
|
|
|
|
if (category == null) {
|
|
|
|
switch (permissionKey) {
|
|
|
|
case 'users_default':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.defaultPermissionLevel;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'events_default':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.sendMessages;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'state_default':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.configureChat;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'ban':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.banFromChat;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'kick':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.kickFromChat;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'redact':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.deleteMessage;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'invite':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.inviteContact;
|
2021-04-15 06:48:26 +00:00
|
|
|
}
|
|
|
|
} else if (category == 'notifications') {
|
|
|
|
switch (permissionKey) {
|
|
|
|
case 'rooms':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.notifications;
|
2021-04-15 06:48:26 +00:00
|
|
|
}
|
|
|
|
} else if (category == 'events') {
|
|
|
|
switch (permissionKey) {
|
|
|
|
case EventTypes.RoomName:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.changeTheNameOfTheGroup;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.RoomPowerLevels:
|
2023-08-13 14:25:56 +00:00
|
|
|
return L10n.of(context)!.chatPermissions;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.HistoryVisibility:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.visibilityOfTheChatHistory;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.RoomCanonicalAlias:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.setInvitationLink;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.RoomAvatar:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.editRoomAvatar;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.RoomTombstone:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.replaceRoomWithNewerVersion;
|
2021-04-15 06:48:26 +00:00
|
|
|
case EventTypes.Encryption:
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.enableEncryption;
|
2021-04-15 06:48:26 +00:00
|
|
|
case 'm.room.server_acl':
|
2022-01-29 11:35:03 +00:00
|
|
|
return L10n.of(context)!.editBlockedServers;
|
2021-04-15 06:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissionKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(getLocalizedPowerLevelString(context)),
|
2024-04-15 07:32:06 +00:00
|
|
|
subtitle: Text(
|
|
|
|
L10n.of(context)!.minimumPowerLevel(permission.toString()),
|
|
|
|
),
|
2024-04-15 08:12:37 +00:00
|
|
|
trailing: Material(
|
|
|
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
|
|
|
|
color: Theme.of(context).colorScheme.onInverseSurface,
|
|
|
|
child: DropdownButton<int>(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
|
|
|
|
underline: const SizedBox.shrink(),
|
|
|
|
onChanged: canEdit ? onChanged : null,
|
|
|
|
value: {0, 50, 100}.contains(permission) ? permission : null,
|
|
|
|
items: [
|
|
|
|
DropdownMenuItem(
|
|
|
|
value: 0,
|
|
|
|
child: Text(L10n.of(context)!.user),
|
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
value: 50,
|
|
|
|
child: Text(L10n.of(context)!.moderator),
|
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
value: 100,
|
|
|
|
child: Text(L10n.of(context)!.admin),
|
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
value: null,
|
|
|
|
child: Text(L10n.of(context)!.custom),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-04-15 06:48:26 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|