From 689e2988658188ece3513de4e44983d7ea1174a0 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 12 Aug 2021 20:46:21 +0200 Subject: [PATCH] feat: Add remove rooms to and from spaces --- assets/l10n/intl_en.arb | 7 +++++ lib/pages/chat_list.dart | 48 +++++++++++++++++++++++++++++ lib/pages/views/chat_list_view.dart | 7 +++++ 3 files changed, 62 insertions(+) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 63d89cb0..04c4c541 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -6,11 +6,18 @@ "type": "text", "placeholders": {} }, + "addToSpace": "Add to space", "accept": "Accept", + "chatHasBeenAddedToThisSpace": "Chat has been added to this space", "@accept": { "type": "text", "placeholders": {} }, + "chatHasBeenRemovedFromThisSpace": "Chat has been removed from this space", + "@chatHasBeenRemovedFromThisSpace": { + "type": "text", + "placeholders": {} + }, "cantOpenUri": "Can't open the URI {uri}", "@cantOpenUri": { "type": "text", diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 5331c04a..575d2e97 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -321,6 +321,54 @@ class ChatListController extends State { } } + Future addOrRemoveToSpace() async { + if (activeSpaceId != null) { + final space = Matrix.of(context).client.getRoomById(activeSpaceId); + final result = await showFutureLoadingDialog( + context: context, + future: () => space.removeSpaceChild(selectedRoomIds.single), + ); + if (result.error == null) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(L10n.of(context).chatHasBeenRemovedFromThisSpace), + ), + ); + } + } else { + final selectedSpace = await showConfirmationDialog( + context: context, + title: L10n.of(context).addToSpace, + actions: Matrix.of(context) + .client + .rooms + .where((r) => r.isSpace) + .map( + (space) => AlertDialogAction( + key: space.id, + label: space.displayname, + ), + ) + .toList()); + if (selectedSpace == null) return; + final result = await showFutureLoadingDialog( + context: context, + future: () => Matrix.of(context) + .client + .getRoomById(selectedSpace) + .setSpaceChild(selectedRoomIds.single), + ); + if (result.error == null) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(L10n.of(context).chatHasBeenAddedToThisSpace), + ), + ); + } + } + setState(() => selectedRoomIds.clear()); + } + Future waitForFirstSync() async { final client = Matrix.of(context).client; if (client.prevBatch?.isEmpty ?? true) { diff --git a/lib/pages/views/chat_list_view.dart b/lib/pages/views/chat_list_view.dart index 56678d5a..7414a860 100644 --- a/lib/pages/views/chat_list_view.dart +++ b/lib/pages/views/chat_list_view.dart @@ -50,6 +50,13 @@ class ChatListView extends StatelessWidget { ? null : selectMode == SelectMode.select ? [ + if (controller.selectedRoomIds.length == 1 && + controller.spaces.isNotEmpty) + IconButton( + tooltip: L10n.of(context).addToSpace, + icon: Icon(Icons.group_work_outlined), + onPressed: controller.addOrRemoveToSpace, + ), if (controller.selectedRoomIds.length == 1) IconButton( tooltip: L10n.of(context).toggleUnread,