Skip to content

Commit

Permalink
Mark chats as read before leaving them
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelrap committed May 22, 2024
1 parent 10bc0e6 commit f79203a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ class ChatListController extends State<ChatList>
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);
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/chat_list/chat_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/chat_list/space_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ class _SpaceViewState extends State<SpaceView> {
// #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');
}
Expand Down
13 changes: 7 additions & 6 deletions lib/pages/chat_list/utils/on_chat_tap.dart
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions lib/pangea/utils/archive_space.dart
Original file line number Diff line number Diff line change
@@ -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<void> archiveSpace(Room? space, Client client) async {
if (space == null) {
Expand All @@ -14,6 +13,9 @@ Future<void> archiveSpace(Room? space, Client client) async {

final List<Room> children = await space.getChildRooms();
for (final Room child in children) {
if (child.isUnread) {
await child.markUnread(false);
}
await child.leave();
}
await space.leave();
Expand Down
5 changes: 4 additions & 1 deletion lib/pangea/utils/delete_room.dart
Original file line number Diff line number Diff line change
@@ -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<void> deleteRoom(String? roomID, Client client) async {
Expand Down Expand Up @@ -79,6 +79,9 @@ Future<void> deleteRoom(String? roomID, Client client) async {
}

try {
if (room.isUnread) {
await room.markUnread(false);
}
await room.leave();
} catch (err) {
ErrorHandler.logError(
Expand Down

0 comments on commit f79203a

Please sign in to comment.