diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 60be9cfe..84f7738d 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -228,31 +228,54 @@ class ChatListController extends State { : selectedRoomIds.add(roomId)); } - Future toggleUnread() { - final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single); - return showFutureLoadingDialog( + Future toggleUnread() async { + await showFutureLoadingDialog( context: context, - future: () => room.markUnread(!room.isUnread), + future: () async { + final markUnread = anySelectedRoomNotMarkedUnread; + final client = Matrix.of(context).client; + for (final roomId in selectedRoomIds) { + final room = client.getRoomById(roomId); + if (room.markedUnread == markUnread) continue; + await client.getRoomById(roomId).markUnread(markUnread); + } + }, ); + cancelAction(); } - Future toggleFavouriteRoom() { - final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single); - return showFutureLoadingDialog( + Future toggleFavouriteRoom() async { + await showFutureLoadingDialog( context: context, - future: () => room.setFavourite(!room.isFavourite), + future: () async { + final makeFavorite = anySelectedRoomNotFavorite; + final client = Matrix.of(context).client; + for (final roomId in selectedRoomIds) { + final room = client.getRoomById(roomId); + if (room.isFavourite == makeFavorite) continue; + await client.getRoomById(roomId).setFavourite(makeFavorite); + } + }, ); + cancelAction(); } - Future toggleMuted() { - final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single); - return showFutureLoadingDialog( + Future toggleMuted() async { + await showFutureLoadingDialog( context: context, - future: () => room.setPushRuleState( - room.pushRuleState == PushRuleState.notify - ? PushRuleState.mentionsOnly - : PushRuleState.notify), + future: () async { + final newState = anySelectedRoomNotMuted + ? PushRuleState.mentionsOnly + : PushRuleState.notify; + final client = Matrix.of(context).client; + for (final roomId in selectedRoomIds) { + final room = client.getRoomById(roomId); + if (room.pushRuleState == newState) continue; + await client.getRoomById(roomId).setPushRuleState(newState); + } + }, ); + cancelAction(); } Future archiveAction() async { @@ -338,7 +361,11 @@ class ChatListController extends State { final space = Matrix.of(context).client.getRoomById(activeSpaceId); final result = await showFutureLoadingDialog( context: context, - future: () => space.removeSpaceChild(selectedRoomIds.single), + future: () async { + for (final roomId in selectedRoomIds) { + await space.removeSpaceChild(roomId); + } + }, ); if (result.error == null) { ScaffoldMessenger.of(context).showSnackBar( @@ -365,10 +392,14 @@ class ChatListController extends State { if (selectedSpace == null) return; final result = await showFutureLoadingDialog( context: context, - future: () => Matrix.of(context) - .client - .getRoomById(selectedSpace) - .setSpaceChild(selectedRoomIds.single), + future: () async { + for (final roomId in selectedRoomIds) { + await Matrix.of(context) + .client + .getRoomById(selectedSpace) + .setSpaceChild(roomId); + } + }, ); if (result.error == null) { ScaffoldMessenger.of(context).showSnackBar( @@ -381,6 +412,16 @@ class ChatListController extends State { setState(() => selectedRoomIds.clear()); } + bool get anySelectedRoomNotMarkedUnread => selectedRoomIds.any( + (roomId) => !Matrix.of(context).client.getRoomById(roomId).markedUnread); + + bool get anySelectedRoomNotFavorite => selectedRoomIds.any( + (roomId) => !Matrix.of(context).client.getRoomById(roomId).isFavourite); + + bool get anySelectedRoomNotMuted => selectedRoomIds.any((roomId) => + Matrix.of(context).client.getRoomById(roomId).pushRuleState == + PushRuleState.notify); + Future waitForFirstSync; Future _waitForFirstSync() async { diff --git a/lib/pages/chat_list/chat_list_view.dart b/lib/pages/chat_list/chat_list_view.dart index 3899ff4f..fe2a4272 100644 --- a/lib/pages/chat_list/chat_list_view.dart +++ b/lib/pages/chat_list/chat_list_view.dart @@ -118,8 +118,7 @@ class ChatListView extends StatelessWidget { ? null : selectMode == SelectMode.select ? [ - if (controller.selectedRoomIds.length == 1 && - controller.spaces.isNotEmpty && + if (controller.spaces.isNotEmpty && !Matrix.of(context) .client .getRoomById( @@ -130,37 +129,28 @@ class ChatListView extends StatelessWidget { icon: const Icon(Icons.group_work_outlined), onPressed: controller.addOrRemoveToSpace, ), - if (controller.selectedRoomIds.length == 1) - IconButton( - tooltip: L10n.of(context).toggleUnread, - icon: Icon(Matrix.of(context) - .client - .getRoomById( - controller.selectedRoomIds.single) - .isUnread - ? Icons.mark_chat_read_outlined - : Icons.mark_chat_unread_outlined), - onPressed: controller.toggleUnread, - ), - if (controller.selectedRoomIds.length == 1) - IconButton( - tooltip: L10n.of(context).toggleFavorite, - icon: const Icon(Icons.push_pin_outlined), - onPressed: controller.toggleFavouriteRoom, - ), - if (controller.selectedRoomIds.length == 1) - IconButton( - icon: Icon(Matrix.of(context) - .client - .getRoomById(controller - .selectedRoomIds.single) - .pushRuleState == - PushRuleState.notify - ? Icons.notifications_off_outlined - : Icons.notifications_outlined), - tooltip: L10n.of(context).toggleMuted, - onPressed: controller.toggleMuted, - ), + IconButton( + tooltip: L10n.of(context).toggleUnread, + icon: Icon( + controller.anySelectedRoomNotMarkedUnread + ? Icons.mark_chat_read_outlined + : Icons.mark_chat_unread_outlined), + onPressed: controller.toggleUnread, + ), + IconButton( + tooltip: L10n.of(context).toggleFavorite, + icon: Icon(controller.anySelectedRoomNotFavorite + ? Icons.push_pin_outlined + : Icons.push_pin), + onPressed: controller.toggleFavouriteRoom, + ), + IconButton( + icon: Icon(controller.anySelectedRoomNotMuted + ? Icons.notifications_off_outlined + : Icons.notifications_outlined), + tooltip: L10n.of(context).toggleMuted, + onPressed: controller.toggleMuted, + ), IconButton( icon: const Icon(Icons.delete_outlined), tooltip: L10n.of(context).archive,