Skip to content

Commit

Permalink
feat: Change room when config is changed #2872
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 4, 2024
1 parent 33e2c38 commit 3c7dc33
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/chat_room/cubit/chat_room_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {
);
}

Future<String?> getRoomIdFromStorage() async {
final savedRoomId = await matrixChat.getRoomIdFromStorage(roomIdStoredKey);
return savedRoomId;
}

Future<void> clearRoomIdFromStorage() async {
await matrixChat.clearRoomIdInStorage(roomIdStoredKey);
}

Future<void> init() async {
try {
emit(state.copyWith(status: AppStatus.loading));
Expand Down
5 changes: 5 additions & 0 deletions lib/chat_room/matrix_chat/matrix_chat_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class MatrixChatImpl extends MatrixChatInterface {
await secureStorageProvider.set(roomIdStoredKey, roomId);
}

@override
Future<void> clearRoomIdInStorage(String roomIdStoredKey) async {
await secureStorageProvider.delete(roomIdStoredKey);
}

@override
int getUnreadMessageCount(String? roomId) =>
client?.getRoomById(roomId ?? '')?.notificationCount ?? 0;
Expand Down
1 change: 1 addition & 0 deletions lib/chat_room/matrix_chat/matrix_chat_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class MatrixChatInterface {
Future<void> init(ProfileCubit profileCubit);
Future<String?> getRoomIdFromStorage(String roomIdStoredKey);
Future<void> setRoomIdInStorage(String roomIdStoredKey, String roomId);
Future<void> clearRoomIdInStorage(String roomIdStoredKey);
int getUnreadMessageCount(String? roomId);
Future<List<Message>> retriveMessagesFromDB(String roomId);
Future<void> markMessageAsRead(
Expand Down
9 changes: 9 additions & 0 deletions lib/enterprise/cubit/enterprise_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
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();
}

Expand Down

0 comments on commit 3c7dc33

Please sign in to comment.