diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 7b89f0997..9df247e4c 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -563,6 +563,15 @@ class ChatListController extends State final displayname = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)); + final spacesWithPowerLevels = room.client.rooms + .where( + (space) => + space.isSpace && + space.canChangeStateEvent(EventTypes.SpaceChild) && + !space.spaceChildren.any((c) => c.roomId == room.id), + ) + .toList(); + final action = await showMenu( context: posContext, position: position, @@ -661,6 +670,18 @@ class ChatListController extends State ], ), ), + if (spacesWithPowerLevels.isNotEmpty) + PopupMenuItem( + value: ChatContextAction.addToSpace, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Icon(Icons.group_work_outlined), + const SizedBox(width: 12), + Text(L10n.of(context)!.addToSpace), + ], + ), + ), PopupMenuItem( value: ChatContextAction.leave, child: Row( @@ -723,6 +744,25 @@ class ChatListController extends State await showFutureLoadingDialog(context: context, future: room.leave); return; + case ChatContextAction.addToSpace: + final space = await showConfirmationDialog( + context: context, + title: L10n.of(context)!.space, + actions: spacesWithPowerLevels + .map( + (space) => AlertDialogAction( + key: space, + label: space + .getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)), + ), + ) + .toList(), + ); + if (space == null) return; + await showFutureLoadingDialog( + context: context, + future: () => space.setSpaceChild(room.id), + ); } } @@ -927,4 +967,5 @@ enum ChatContextAction { markUnread, mute, leave, + addToSpace, }