Gray out buttons for spaces user isn't admin for
This commit is contained in:
parent
aa5d09407e
commit
a2a31e526a
4 changed files with 35 additions and 10 deletions
|
|
@ -3970,5 +3970,8 @@
|
|||
"capacitySetTooLow": "Room capacity cannot be set below the current number of non-admins.",
|
||||
"roomCapacityExplanation": "Room capacity limits the number of non-admins allowed in a room.",
|
||||
"enterNumber": "Please enter a whole number value.",
|
||||
"buildTranslation": "Build your translation from the choices above"
|
||||
"buildTranslation": "Build your translation from the choices above",
|
||||
"nonexistentSelection": "Selection no longer exists.",
|
||||
"cantAddSpaceChild": "You do not have permission to add a child to this space.",
|
||||
"roomAddedToSpace": "Room(s) have been added to the selected space."
|
||||
}
|
||||
|
|
@ -797,6 +797,10 @@ class ChatListController extends State<ChatList>
|
|||
// Pangea#
|
||||
|
||||
Future<void> addToSpace() async {
|
||||
// #Pangea
|
||||
final firstSelectedRoom =
|
||||
Matrix.of(context).client.getRoomById(selectedRoomIds.toList().first);
|
||||
// Pangea#
|
||||
final selectedSpace = await showConfirmationDialog<String>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.addToSpace,
|
||||
|
|
@ -825,6 +829,12 @@ class ChatListController extends State<ChatList>
|
|||
// label: space
|
||||
// .getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
|
||||
label: space.nameIncludingParents(context),
|
||||
textStyle: TextStyle(
|
||||
color: (firstSelectedRoom == null ||
|
||||
(firstSelectedRoom.isSpace && !space.isRoomAdmin))
|
||||
? Theme.of(context).colorScheme.outline
|
||||
: Theme.of(context).colorScheme.surfaceTint,
|
||||
),
|
||||
// Pangea#
|
||||
),
|
||||
)
|
||||
|
|
@ -836,12 +846,19 @@ class ChatListController extends State<ChatList>
|
|||
future: () async {
|
||||
final space = Matrix.of(context).client.getRoomById(selectedSpace)!;
|
||||
// #Pangea
|
||||
if (firstSelectedRoom == null) {
|
||||
throw L10n.of(context)!.nonexistentSelection;
|
||||
}
|
||||
if (firstSelectedRoom.isSpace && !space.isRoomAdmin) {
|
||||
throw L10n.of(context)!.cantAddSpaceChild;
|
||||
}
|
||||
await pangeaAddToSpace(
|
||||
space,
|
||||
selectedRoomIds.toList(),
|
||||
context,
|
||||
pangeaController,
|
||||
);
|
||||
|
||||
// if (space.canSendDefaultStates) {
|
||||
// for (final roomId in selectedRoomIds) {
|
||||
// await space.setSpaceChild(roomId);
|
||||
|
|
@ -854,7 +871,10 @@ class ChatListController extends State<ChatList>
|
|||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.chatHasBeenAddedToThisSpace),
|
||||
// #Pangea
|
||||
// content: Text(L10n.of(context)!.chatHasBeenAddedToThisSpace),
|
||||
content: Text(L10n.of(context)!.roomAddedToSpace),
|
||||
// Pangea#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,15 +128,13 @@ extension ChildrenAndParentsRoomExtension on Room {
|
|||
return childIds;
|
||||
}
|
||||
|
||||
// Checks if has permissions to add child to space
|
||||
// And whether potential child space is ancestor of this
|
||||
// Checks if has permissions to add child chat
|
||||
// Or whether potential child space is ancestor of this
|
||||
bool _canAddAsParentOf(Room? child) {
|
||||
if (child == null || !child.isSpace) {
|
||||
return _canIAddSpaceChild(child);
|
||||
}
|
||||
if (id == child.id) return false;
|
||||
return _isRoomAdmin &&
|
||||
child._isRoomAdmin &&
|
||||
!child._allSpaceChildRoomIds.contains(id);
|
||||
return !child._allSpaceChildRoomIds.contains(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,9 +144,13 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
|
||||
Widget getAddToSpaceToggleItem(int index) {
|
||||
final Room possibleParent = possibleParents[index];
|
||||
final bool canAdd = !(!possibleParent.isRoomAdmin &&
|
||||
widget.mode == AddToClassMode.exchange) &&
|
||||
possibleParent.canAddAsParentOf(room);
|
||||
final bool canAdd = (room?.isSpace ?? false)
|
||||
// Room is space
|
||||
? possibleParent.isRoomAdmin &&
|
||||
room!.isRoomAdmin &&
|
||||
possibleParent.canAddAsParentOf(room)
|
||||
// Room is null or chat
|
||||
: possibleParent.canAddAsParentOf(room);
|
||||
|
||||
return Opacity(
|
||||
opacity: canAdd ? 1 : 0.5,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue