feat: Multiple mute, pin and mark unread

This commit is contained in:
Krille Fear 2021-11-14 20:59:25 +01:00
parent ff8bba03ae
commit 4c97044f1c
2 changed files with 84 additions and 53 deletions

View File

@ -228,31 +228,54 @@ class ChatListController extends State<ChatList> {
: selectedRoomIds.add(roomId));
}
Future<void> toggleUnread() {
final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single);
return showFutureLoadingDialog(
Future<void> 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<void> toggleFavouriteRoom() {
final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single);
return showFutureLoadingDialog(
Future<void> 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<void> toggleMuted() {
final room = Matrix.of(context).client.getRoomById(selectedRoomIds.single);
return showFutureLoadingDialog(
Future<void> toggleMuted() async {
await showFutureLoadingDialog(
context: context,
future: () => room.setPushRuleState(
room.pushRuleState == PushRuleState.notify
future: () async {
final newState = anySelectedRoomNotMuted
? PushRuleState.mentionsOnly
: PushRuleState.notify),
: 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<void> archiveAction() async {
@ -338,7 +361,11 @@ class ChatListController extends State<ChatList> {
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<ChatList> {
if (selectedSpace == null) return;
final result = await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context)
future: () async {
for (final roomId in selectedRoomIds) {
await Matrix.of(context)
.client
.getRoomById(selectedSpace)
.setSpaceChild(selectedRoomIds.single),
.setSpaceChild(roomId);
}
},
);
if (result.error == null) {
ScaffoldMessenger.of(context).showSnackBar(
@ -381,6 +412,16 @@ class ChatListController extends State<ChatList> {
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<void> waitForFirstSync;
Future<void> _waitForFirstSync() async {

View File

@ -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,32 +129,23 @@ 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
icon: Icon(
controller.anySelectedRoomNotMarkedUnread
? 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),
icon: Icon(controller.anySelectedRoomNotFavorite
? Icons.push_pin_outlined
: Icons.push_pin),
onPressed: controller.toggleFavouriteRoom,
),
if (controller.selectedRoomIds.length == 1)
IconButton(
icon: Icon(Matrix.of(context)
.client
.getRoomById(controller
.selectedRoomIds.single)
.pushRuleState ==
PushRuleState.notify
icon: Icon(controller.anySelectedRoomNotMuted
? Icons.notifications_off_outlined
: Icons.notifications_outlined),
tooltip: L10n.of(context).toggleMuted,