mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-18 02:42:34 +01:00
feat: Multiple mute, pin and mark unread
This commit is contained in:
parent
ff8bba03ae
commit
4c97044f1c
@ -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 {
|
||||||
.client
|
for (final roomId in selectedRoomIds) {
|
||||||
.getRoomById(selectedSpace)
|
await Matrix.of(context)
|
||||||
.setSpaceChild(selectedRoomIds.single),
|
.client
|
||||||
|
.getRoomById(selectedSpace)
|
||||||
|
.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 {
|
||||||
|
@ -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,37 +129,28 @@ 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(
|
||||||
icon: Icon(Matrix.of(context)
|
controller.anySelectedRoomNotMarkedUnread
|
||||||
.client
|
? Icons.mark_chat_read_outlined
|
||||||
.getRoomById(
|
: Icons.mark_chat_unread_outlined),
|
||||||
controller.selectedRoomIds.single)
|
onPressed: controller.toggleUnread,
|
||||||
.isUnread
|
),
|
||||||
? Icons.mark_chat_read_outlined
|
IconButton(
|
||||||
: Icons.mark_chat_unread_outlined),
|
tooltip: L10n.of(context).toggleFavorite,
|
||||||
onPressed: controller.toggleUnread,
|
icon: Icon(controller.anySelectedRoomNotFavorite
|
||||||
),
|
? Icons.push_pin_outlined
|
||||||
if (controller.selectedRoomIds.length == 1)
|
: Icons.push_pin),
|
||||||
IconButton(
|
onPressed: controller.toggleFavouriteRoom,
|
||||||
tooltip: L10n.of(context).toggleFavorite,
|
),
|
||||||
icon: const Icon(Icons.push_pin_outlined),
|
IconButton(
|
||||||
onPressed: controller.toggleFavouriteRoom,
|
icon: Icon(controller.anySelectedRoomNotMuted
|
||||||
),
|
? Icons.notifications_off_outlined
|
||||||
if (controller.selectedRoomIds.length == 1)
|
: Icons.notifications_outlined),
|
||||||
IconButton(
|
tooltip: L10n.of(context).toggleMuted,
|
||||||
icon: Icon(Matrix.of(context)
|
onPressed: controller.toggleMuted,
|
||||||
.client
|
),
|
||||||
.getRoomById(controller
|
|
||||||
.selectedRoomIds.single)
|
|
||||||
.pushRuleState ==
|
|
||||||
PushRuleState.notify
|
|
||||||
? Icons.notifications_off_outlined
|
|
||||||
: Icons.notifications_outlined),
|
|
||||||
tooltip: L10n.of(context).toggleMuted,
|
|
||||||
onPressed: controller.toggleMuted,
|
|
||||||
),
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.delete_outlined),
|
icon: const Icon(Icons.delete_outlined),
|
||||||
tooltip: L10n.of(context).archive,
|
tooltip: L10n.of(context).archive,
|
||||||
|
Loading…
Reference in New Issue
Block a user