From f79203a47ebc4842b53fe5e57109fa4df731754a Mon Sep 17 00:00:00 2001 From: Kelrap Date: Wed, 22 May 2024 16:12:10 -0400 Subject: [PATCH] Mark chats as read before leaving them --- lib/pages/chat_list/chat_list.dart | 3 +++ lib/pages/chat_list/chat_list_item.dart | 3 +++ lib/pages/chat_list/space_view.dart | 5 ++++- lib/pages/chat_list/utils/on_chat_tap.dart | 13 +++++++------ lib/pangea/utils/archive_space.dart | 6 ++++-- lib/pangea/utils/delete_room.dart | 5 ++++- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index f96baa040e..9a6345c6a3 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -728,6 +728,9 @@ class ChatListController extends State while (selectedRoomIds.isNotEmpty) { final roomId = selectedRoomIds.first; try { + if (client.getRoomById(roomId)!.isUnread) { + await client.getRoomById(roomId)!.markUnread(false); + } await client.getRoomById(roomId)!.leave(); } finally { toggleSelection(roomId); diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index 447b5f6c33..71d5d558b5 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -53,6 +53,9 @@ class ChatListItem extends StatelessWidget { message: L10n.of(context)!.archiveRoomDescription, ); if (confirmed == OkCancelResult.cancel) return; + if (room.isUnread) { + await room.markUnread(false); + } await showFutureLoadingDialog( context: context, future: () => room.leave(), diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 348550c65f..48be9eb04d 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -288,7 +288,10 @@ class _SpaceViewState extends State { // #Pangea // future: room!.leave, future: () async { - await room!.leave(); + if (room!.isUnread) { + await room.markUnread(false); + } + await room.leave(); if (Matrix.of(context).activeRoomId == room.id) { context.go('/rooms'); } diff --git a/lib/pages/chat_list/utils/on_chat_tap.dart b/lib/pages/chat_list/utils/on_chat_tap.dart index d24af1fb42..3869cd60d5 100644 --- a/lib/pages/chat_list/utils/on_chat_tap.dart +++ b/lib/pages/chat_list/utils/on_chat_tap.dart @@ -1,15 +1,13 @@ -import 'package:flutter/material.dart'; - import 'package:adaptive_dialog/adaptive_dialog.dart'; +import 'package:fluffychat/pages/chat/send_file_dialog.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; +import 'package:fluffychat/widgets/matrix.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:fluffychat/pages/chat/send_file_dialog.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; -import 'package:fluffychat/widgets/matrix.dart'; - void onChatTap(Room room, BuildContext context) async { if (room.membership == Membership.invite) { final inviterId = @@ -47,6 +45,9 @@ void onChatTap(Room room, BuildContext context) async { return; } if (inviteAction == InviteActions.decline) { + if (room.isUnread) { + await room.markUnread(false); + } await showFutureLoadingDialog( context: context, future: room.leave, diff --git a/lib/pangea/utils/archive_space.dart b/lib/pangea/utils/archive_space.dart index 72f10fae40..ac83980fbb 100644 --- a/lib/pangea/utils/archive_space.dart +++ b/lib/pangea/utils/archive_space.dart @@ -1,7 +1,6 @@ -import 'package:matrix/matrix.dart'; - import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:matrix/matrix.dart'; Future archiveSpace(Room? space, Client client) async { if (space == null) { @@ -14,6 +13,9 @@ Future archiveSpace(Room? space, Client client) async { final List children = await space.getChildRooms(); for (final Room child in children) { + if (child.isUnread) { + await child.markUnread(false); + } await child.leave(); } await space.leave(); diff --git a/lib/pangea/utils/delete_room.dart b/lib/pangea/utils/delete_room.dart index f8e168779c..d2a0acae98 100644 --- a/lib/pangea/utils/delete_room.dart +++ b/lib/pangea/utils/delete_room.dart @@ -1,6 +1,6 @@ +import 'package:fluffychat/pangea/constants/class_default_values.dart'; import 'package:matrix/matrix.dart'; -import 'package:fluffychat/pangea/constants/class_default_values.dart'; import 'error_handler.dart'; Future deleteRoom(String? roomID, Client client) async { @@ -79,6 +79,9 @@ Future deleteRoom(String? roomID, Client client) async { } try { + if (room.isUnread) { + await room.markUnread(false); + } await room.leave(); } catch (err) { ErrorHandler.logError(