fix: improve chat message deduplication, add conversation refresh logic, and update UI components for consistency
This commit is contained in:
@@ -77,6 +77,9 @@ class SupportChatNotifier extends StateNotifier<SupportChatState> {
|
||||
}
|
||||
}
|
||||
|
||||
// Track message IDs we've sent via REST to avoid socket echo duplicates
|
||||
final Set<String> _sentMessageIds = {};
|
||||
|
||||
Future<void> sendMessage(String content) async {
|
||||
final chat = state.chat;
|
||||
if (chat == null || content.trim().isEmpty) return;
|
||||
@@ -85,6 +88,7 @@ class SupportChatNotifier extends StateNotifier<SupportChatState> {
|
||||
state = state.copyWith(isSending: true);
|
||||
try {
|
||||
final message = await _repo.sendMessage(chat.id, content.trim());
|
||||
_sentMessageIds.add(message.id);
|
||||
// Dedup — socket broadcast may have already added this message
|
||||
if (!state.messages.any((m) => m.id == message.id)) {
|
||||
state = state.copyWith(
|
||||
@@ -121,7 +125,9 @@ class SupportChatNotifier extends StateNotifier<SupportChatState> {
|
||||
|
||||
void addIncomingMessage(SupportMessage message) {
|
||||
if (state.chat == null || message.chatId != state.chat!.id) return;
|
||||
// Skip if already in list OR if we sent this via REST (socket echo)
|
||||
if (state.messages.any((m) => m.id == message.id)) return;
|
||||
if (_sentMessageIds.contains(message.id)) return;
|
||||
|
||||
state = state.copyWith(messages: [...state.messages, message]);
|
||||
_repo.markAsRead(state.chat!.id);
|
||||
|
||||
Reference in New Issue
Block a user