feat: Add remove rooms to and from spaces

This commit is contained in:
Christian Pauly 2021-08-12 20:46:21 +02:00
parent 3ebf3ed26c
commit 689e298865
3 changed files with 62 additions and 0 deletions

View File

@ -6,11 +6,18 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"addToSpace": "Add to space",
"accept": "Accept", "accept": "Accept",
"chatHasBeenAddedToThisSpace": "Chat has been added to this space",
"@accept": { "@accept": {
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"chatHasBeenRemovedFromThisSpace": "Chat has been removed from this space",
"@chatHasBeenRemovedFromThisSpace": {
"type": "text",
"placeholders": {}
},
"cantOpenUri": "Can't open the URI {uri}", "cantOpenUri": "Can't open the URI {uri}",
"@cantOpenUri": { "@cantOpenUri": {
"type": "text", "type": "text",

View File

@ -321,6 +321,54 @@ class ChatListController extends State<ChatList> {
} }
} }
Future<void> 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<String>(
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<void> waitForFirstSync() async { Future<void> waitForFirstSync() async {
final client = Matrix.of(context).client; final client = Matrix.of(context).client;
if (client.prevBatch?.isEmpty ?? true) { if (client.prevBatch?.isEmpty ?? true) {

View File

@ -50,6 +50,13 @@ class ChatListView extends StatelessWidget {
? null ? null
: selectMode == SelectMode.select : 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) if (controller.selectedRoomIds.length == 1)
IconButton( IconButton(
tooltip: L10n.of(context).toggleUnread, tooltip: L10n.of(context).toggleUnread,