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

View File

@ -118,8 +118,7 @@ class ChatListView extends StatelessWidget {
? null ? null
: selectMode == SelectMode.select : selectMode == SelectMode.select
? [ ? [
if (controller.selectedRoomIds.length == 1 && if (controller.spaces.isNotEmpty &&
controller.spaces.isNotEmpty &&
!Matrix.of(context) !Matrix.of(context)
.client .client
.getRoomById( .getRoomById(
@ -130,32 +129,23 @@ class ChatListView extends StatelessWidget {
icon: const Icon(Icons.group_work_outlined), icon: const Icon(Icons.group_work_outlined),
onPressed: controller.addOrRemoveToSpace, onPressed: controller.addOrRemoveToSpace,
), ),
if (controller.selectedRoomIds.length == 1)
IconButton( IconButton(
tooltip: L10n.of(context).toggleUnread, tooltip: L10n.of(context).toggleUnread,
icon: Icon(Matrix.of(context) icon: Icon(
.client controller.anySelectedRoomNotMarkedUnread
.getRoomById(
controller.selectedRoomIds.single)
.isUnread
? Icons.mark_chat_read_outlined ? Icons.mark_chat_read_outlined
: Icons.mark_chat_unread_outlined), : Icons.mark_chat_unread_outlined),
onPressed: controller.toggleUnread, onPressed: controller.toggleUnread,
), ),
if (controller.selectedRoomIds.length == 1)
IconButton( IconButton(
tooltip: L10n.of(context).toggleFavorite, 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, onPressed: controller.toggleFavouriteRoom,
), ),
if (controller.selectedRoomIds.length == 1)
IconButton( IconButton(
icon: Icon(Matrix.of(context) icon: Icon(controller.anySelectedRoomNotMuted
.client
.getRoomById(controller
.selectedRoomIds.single)
.pushRuleState ==
PushRuleState.notify
? Icons.notifications_off_outlined ? Icons.notifications_off_outlined
: Icons.notifications_outlined), : Icons.notifications_outlined),
tooltip: L10n.of(context).toggleMuted, tooltip: L10n.of(context).toggleMuted,