feat: Implement socket-first message sending with REST fallback, enhance chat room re-joining on socket reconnect, and update 'Categories' to 'Specialization' in the hero section.
This commit is contained in:
@@ -291,7 +291,20 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
);
|
||||
|
||||
try {
|
||||
final realMessage = await _repository.sendMessage(
|
||||
// Send via socket so the backend broadcasts new_message to the other user.
|
||||
// The REST endpoint does NOT emit socket events, so using REST here
|
||||
// would prevent real-time delivery to the other participant.
|
||||
ChatMessage? realMessage;
|
||||
|
||||
if (_socket.isConnected) {
|
||||
realMessage = await _socket.sendMessage(conversationId, {
|
||||
'content': content,
|
||||
'messageType': 'TEXT',
|
||||
});
|
||||
}
|
||||
|
||||
// Fallback to REST if socket send failed or not connected
|
||||
realMessage ??= await _repository.sendMessage(
|
||||
conversationId,
|
||||
content: content,
|
||||
);
|
||||
@@ -311,7 +324,7 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
final updatedConversations = state.conversations.map((c) {
|
||||
if (c.id == conversationId) {
|
||||
return c.copyWith(
|
||||
lastMessageText: realMessage.content,
|
||||
lastMessageText: realMessage!.content,
|
||||
lastMessageAt: realMessage.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user