fix: improve chat message deduplication, add conversation refresh logic, and update UI components for consistency

This commit is contained in:
pradeepkumar
2026-04-18 11:34:48 +05:30
parent 164d590d31
commit afa1f3489a
6 changed files with 47 additions and 8 deletions

View File

@@ -54,6 +54,9 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
final notifier = ref.read(messagingProvider.notifier);
notifier.setActiveConversation(widget.conversationId);
notifier.loadMessages(widget.conversationId);
// Refetch conversation to get fresh presence (isOnline/lastSeenAt) —
// the list snapshot may be stale. Matches web's selectConversation flow.
notifier.refreshConversation(widget.conversationId);
// Initialize mute/star state from conversation data
final conversations = ref.read(messagingProvider).conversations;
final conv = conversations.where((c) => c.id == widget.conversationId).firstOrNull;
@@ -120,6 +123,9 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
});
// Refresh messages to catch anything missed while in background
ref.read(messagingProvider.notifier).loadMessages(widget.conversationId);
// Refresh conversation to pick up any presence changes that happened
// while the app was backgrounded (socket status events were missed)
ref.read(messagingProvider.notifier).refreshConversation(widget.conversationId);
// Now that user is actively viewing, mark as read
ref.read(messagingProvider.notifier).markAsRead(widget.conversationId);
}