Skip to content

Commit

Permalink
chore: Bring back add to space feature
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Aug 8, 2024
1 parent 641343d commit 8407513
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ class ChatListController extends State<ChatList>
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<ChatContextAction>(
context: posContext,
position: position,
Expand Down Expand Up @@ -661,6 +670,18 @@ class ChatListController extends State<ChatList>
],
),
),
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(
Expand Down Expand Up @@ -723,6 +744,25 @@ class ChatListController extends State<ChatList>
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),
);
}
}

Expand Down Expand Up @@ -927,4 +967,5 @@ enum ChatContextAction {
markUnread,
mute,
leave,
addToSpace,
}

0 comments on commit 8407513

Please sign in to comment.