fix: implement safe map casting for socket events and add support for conversation deletion updates
This commit is contained in:
@@ -240,6 +240,27 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
state = state.copyWith(conversations: updatedConversations, messages: newMessages);
|
||||
}));
|
||||
|
||||
// Conversation deleted by other party — remove from local state
|
||||
_subscriptions.add(_socket.onConversationDeleted.listen((data) {
|
||||
if (!mounted) return;
|
||||
final convId = data['conversationId'] as String?;
|
||||
if (convId == null) return;
|
||||
|
||||
final updatedMessages =
|
||||
Map<String, List<ChatMessage>>.from(state.messages)..remove(convId);
|
||||
final updatedConversations =
|
||||
state.conversations.where((c) => c.id != convId).toList();
|
||||
final totalUnread = updatedConversations.fold<int>(
|
||||
0, (sum, c) => sum + c.unreadCount,
|
||||
);
|
||||
state = state.copyWith(
|
||||
messages: updatedMessages,
|
||||
conversations: updatedConversations,
|
||||
unreadCount: totalUnread,
|
||||
clearActiveConversation: state.activeConversationId == convId,
|
||||
);
|
||||
}));
|
||||
|
||||
// Reconnection: re-join active conversation room and catch up missed messages
|
||||
_subscriptions.add(_socket.onConnectionChange.listen((connected) {
|
||||
if (!mounted || !connected) return;
|
||||
|
||||
Reference in New Issue
Block a user