diff --git a/lib/features/push_notification/presentation/websocket/web_socket_queue_handler.dart b/lib/features/push_notification/presentation/websocket/web_socket_queue_handler.dart index 0e0dc25645..34855be4ad 100644 --- a/lib/features/push_notification/presentation/websocket/web_socket_queue_handler.dart +++ b/lib/features/push_notification/presentation/websocket/web_socket_queue_handler.dart @@ -38,9 +38,13 @@ class WebSocketQueueHandler { return; } - if (queueSize >= _maxQueueSize) { - log('WebSocketQueueHandler::enqueue:Queue full, removing oldest message'); - _messageQueue.removeFirst(); + try { + if (queueSize >= _maxQueueSize) { + log('WebSocketQueueHandler::enqueue:Queue full, removing oldest message'); + _messageQueue.removeFirst(); + } + } catch (e) { + logError('WebSocketQueueHandler::enqueue:Exception = $e'); } log('WebSocketQueueHandler::enqueue(): ${message.id}'); @@ -81,29 +85,39 @@ class WebSocketQueueHandler { void _addToProcessedMessages(String messageId) { log('WebSocketQueueHandler::_addToProcessedMessages(): adding message $messageId to processed messages'); - if (_processedMessageIds.length >= _maxProcessedIdsSize) { - _processedMessageIds.removeFirst(); + try { + if (_processedMessageIds.length >= _maxProcessedIdsSize) { + _processedMessageIds.removeFirst(); + } + } catch (e) { + logError('WebSocketQueueHandler::_addToProcessedMessages:Exception = $e'); } + _processedMessageIds.add(messageId); } void removeMessagesUpToCurrent(String messageId) { - log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing messages up to $messageId'); - final isCurrentStateExist = _messageQueue - .any((message) => message.id == messageId); + try { + log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing messages up to $messageId'); + final isCurrentStateExist = _messageQueue + .any((message) => message.id == messageId); - if (!isCurrentStateExist) { - log('WebSocketQueueHandler::removeMessagesUpToCurrent:Current state $messageId not found in the queue.'); - return; - } - while (queueSize > 0) { - final removedMessage = _messageQueue.removeFirst(); - log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing message ${removedMessage.id} up to $messageId'); - if (removedMessage.id == messageId) { - break; + if (!isCurrentStateExist) { + log('WebSocketQueueHandler::removeMessagesUpToCurrent:Current state $messageId not found in the queue.'); + return; + } + + while (queueSize > 0) { + final removedMessage = _messageQueue.removeFirst(); + log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing message ${removedMessage.id} up to $messageId'); + if (removedMessage.id == messageId) { + break; + } } + log('WebSocketQueueHandler::removeMessagesUpToCurrent:Updated Queue: $queueSize'); + } catch (e) { + logError('WebSocketQueueHandler::removeMessagesUpToCurrent:Exception = $e'); } - log('WebSocketQueueHandler::removeMessagesUpToCurrent:Updated Queue: $queueSize'); } @visibleForTesting diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 278a37dca3..3158a2ac64 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -541,7 +541,8 @@ class ThreadController extends BaseController with EmailActionController { return Future.value(); } - if (searchController.isSearchEmailRunning) { + if (searchController.isSearchEmailRunning && + mailboxDashBoardController.dashboardRoute.value == DashboardRoutes.thread) { await _refreshChangeSearchEmail(); } else { await _refreshChangeListEmail();