diff --git a/lib/features/support_chat/presentation/providers/support_chat_provider.dart b/lib/features/support_chat/presentation/providers/support_chat_provider.dart index b881d48..6d2fc28 100644 --- a/lib/features/support_chat/presentation/providers/support_chat_provider.dart +++ b/lib/features/support_chat/presentation/providers/support_chat_provider.dart @@ -80,14 +80,20 @@ class SupportChatNotifier extends StateNotifier { Future sendMessage(String content) async { final chat = state.chat; if (chat == null || content.trim().isEmpty) return; + if (state.isSending) return; // Prevent double-send state = state.copyWith(isSending: true); try { final message = await _repo.sendMessage(chat.id, content.trim()); - state = state.copyWith( - messages: [...state.messages, message], - isSending: false, - ); + // Dedup — socket broadcast may have already added this message + if (!state.messages.any((m) => m.id == message.id)) { + state = state.copyWith( + messages: [...state.messages, message], + isSending: false, + ); + } else { + state = state.copyWith(isSending: false); + } } catch (e) { state = state.copyWith(isSending: false); rethrow; diff --git a/lib/features/support_chat/presentation/screens/support_chat_screen.dart b/lib/features/support_chat/presentation/screens/support_chat_screen.dart index af31b02..31c07d8 100644 --- a/lib/features/support_chat/presentation/screens/support_chat_screen.dart +++ b/lib/features/support_chat/presentation/screens/support_chat_screen.dart @@ -55,9 +55,14 @@ class _SupportChatScreenState extends ConsumerState { socket.emitRaw('support_join', {'chatId': chatId}); } - // Listen for new support messages + // Listen for new support messages — skip own (added via REST) _messageSub?.cancel(); _messageSub = socket.onSupportMessage.listen((message) { + // Get fresh userId — currentUserId from build() may have been empty at capture time + final myId = currentUserId.isNotEmpty + ? currentUserId + : ref.read(authProvider).user?.id ?? ''; + if (message.senderId == myId) return; ref.read(supportChatProvider.notifier).addIncomingMessage(message); _scrollToBottom(); }); @@ -199,9 +204,7 @@ class _SupportChatScreenState extends ConsumerState { } }); - return Scaffold( - body: SafeArea( - child: Column( + return Column( children: [ // Chat header _buildHeader(context, state.chat), @@ -223,8 +226,6 @@ class _SupportChatScreenState extends ConsumerState { if (!state.isLoading && state.error == null) _buildInputArea(state), ], - ), - ), ); } @@ -232,8 +233,7 @@ class _SupportChatScreenState extends ConsumerState { return Container( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), decoration: const BoxDecoration( - color: AppColors.primaryDark, - borderRadius: BorderRadius.vertical(top: Radius.circular(0)), + color: Color(0xFF648188), ), child: Row( children: [ @@ -457,7 +457,7 @@ class _SupportChatScreenState extends ConsumerState { maxWidth: MediaQuery.of(context).size.width * 0.75, ), decoration: BoxDecoration( - color: isOwn ? AppColors.primaryDark : Colors.white, + color: isOwn ? const Color(0xFF648188) : Colors.white, borderRadius: BorderRadius.only( topLeft: const Radius.circular(15), topRight: const Radius.circular(15),