fix: implement safe map casting for socket events and add support for conversation deletion updates

This commit is contained in:
pradeepkumar
2026-04-09 16:02:31 +05:30
parent f9c6d5e5da
commit 44278b7eb0
3 changed files with 63 additions and 16 deletions

View File

@@ -217,14 +217,21 @@ class MessageSender {
role: json['role'] as String? ?? '',
userProfile: json['userProfile'] != null
? SenderProfile.fromJson(
json['userProfile'] as Map<String, dynamic>)
_safeMap(json['userProfile']))
: null,
agentProfile: json['agentProfile'] != null
? SenderProfile.fromJson(
json['agentProfile'] as Map<String, dynamic>)
_safeMap(json['agentProfile']))
: null,
);
}
/// socket.io in Dart can deliver nested maps as Map<dynamic, dynamic>
static Map<String, dynamic> _safeMap(dynamic val) {
if (val is Map<String, dynamic>) return val;
if (val is Map) return Map<String, dynamic>.from(val);
return <String, dynamic>{};
}
}
class ChatMessage {
@@ -301,7 +308,7 @@ class ChatMessage {
createdAt: json['createdAt'] as String,
updatedAt: json['updatedAt'] as String,
sender: json['sender'] != null
? MessageSender.fromJson(json['sender'] as Map<String, dynamic>)
? MessageSender.fromJson(MessageSender._safeMap(json['sender']))
: MessageSender(id: json['senderId'] as String, role: ''),
);
}