From 3c7dc33d468e7bdd2e7989e05e2cead76b49f7bc Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Wed, 4 Sep 2024 12:33:57 +0545 Subject: [PATCH] feat: Change room when config is changed #2872 --- lib/chat_room/cubit/chat_room_cubit.dart | 9 +++++++++ lib/chat_room/matrix_chat/matrix_chat_impl.dart | 5 +++++ lib/chat_room/matrix_chat/matrix_chat_interface.dart | 1 + lib/enterprise/cubit/enterprise_cubit.dart | 9 +++++++++ 4 files changed, 24 insertions(+) diff --git a/lib/chat_room/cubit/chat_room_cubit.dart b/lib/chat_room/cubit/chat_room_cubit.dart index 3b3bed2e3..ce5603239 100644 --- a/lib/chat_room/cubit/chat_room_cubit.dart +++ b/lib/chat_room/cubit/chat_room_cubit.dart @@ -134,6 +134,15 @@ abstract class ChatRoomCubit extends Cubit { ); } + Future getRoomIdFromStorage() async { + final savedRoomId = await matrixChat.getRoomIdFromStorage(roomIdStoredKey); + return savedRoomId; + } + + Future clearRoomIdFromStorage() async { + await matrixChat.clearRoomIdInStorage(roomIdStoredKey); + } + Future init() async { try { emit(state.copyWith(status: AppStatus.loading)); diff --git a/lib/chat_room/matrix_chat/matrix_chat_impl.dart b/lib/chat_room/matrix_chat/matrix_chat_impl.dart index 9376b65f0..6a98d5be3 100644 --- a/lib/chat_room/matrix_chat/matrix_chat_impl.dart +++ b/lib/chat_room/matrix_chat/matrix_chat_impl.dart @@ -137,6 +137,11 @@ class MatrixChatImpl extends MatrixChatInterface { await secureStorageProvider.set(roomIdStoredKey, roomId); } + @override + Future clearRoomIdInStorage(String roomIdStoredKey) async { + await secureStorageProvider.delete(roomIdStoredKey); + } + @override int getUnreadMessageCount(String? roomId) => client?.getRoomById(roomId ?? '')?.notificationCount ?? 0; diff --git a/lib/chat_room/matrix_chat/matrix_chat_interface.dart b/lib/chat_room/matrix_chat/matrix_chat_interface.dart index f7c9638d3..607b4cac2 100644 --- a/lib/chat_room/matrix_chat/matrix_chat_interface.dart +++ b/lib/chat_room/matrix_chat/matrix_chat_interface.dart @@ -47,6 +47,7 @@ abstract class MatrixChatInterface { Future init(ProfileCubit profileCubit); Future getRoomIdFromStorage(String roomIdStoredKey); Future setRoomIdInStorage(String roomIdStoredKey, String roomId); + Future clearRoomIdInStorage(String roomIdStoredKey); int getUnreadMessageCount(String? roomId); Future> retriveMessagesFromDB(String roomId); Future markMessageAsRead( diff --git a/lib/enterprise/cubit/enterprise_cubit.dart b/lib/enterprise/cubit/enterprise_cubit.dart index afcc1eda7..2a9ca17f2 100644 --- a/lib/enterprise/cubit/enterprise_cubit.dart +++ b/lib/enterprise/cubit/enterprise_cubit.dart @@ -514,6 +514,15 @@ class EnterpriseCubit extends Cubit { helpCenterOptions.customNotification != null && helpCenterOptions.customNotification! && helpCenterOptions.customNotificationRoom != null) { + final roomName = helpCenterOptions.customNotificationRoom; + + final savedRoomName = + await matrixNotificationCubit.getRoomIdFromStorage(); + + if (roomName != savedRoomName) { + await matrixNotificationCubit.clearRoomIdFromStorage(); + } + await matrixNotificationCubit.init(); }