payfrit-app/lib/models/chat_message.dart
John Mizerek 65b5b82546 Add customer-to-staff chat feature and group order invites
- Add real-time chat between customers and staff via WebSocket
- Add HTTP polling fallback when WebSocket unavailable
- Chat auto-closes when worker ends conversation with dialog notification
- Add user search API for group order invites (phone/email/name)
- Store group order invites in app state
- Add login check before starting chat with sign-in prompt
- Remove table change button (not allowed currently)
- Fix About screen to show dynamic version from pubspec
- Update snackbar styling to green with black text

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 12:08:09 -08:00

52 lines
1.8 KiB
Dart

class ChatMessage {
final int messageId;
final int taskId;
final int senderUserId;
final String senderType; // 'customer' or 'worker'
final String senderName;
final String text;
final DateTime createdOn;
final bool isRead;
const ChatMessage({
required this.messageId,
required this.taskId,
required this.senderUserId,
required this.senderType,
required this.senderName,
required this.text,
required this.createdOn,
this.isRead = false,
});
factory ChatMessage.fromJson(Map<String, dynamic> json) {
return ChatMessage(
messageId: (json["MessageID"] as num?)?.toInt() ?? (json["messageId"] as num?)?.toInt() ?? 0,
taskId: (json["TaskID"] as num?)?.toInt() ?? (json["taskId"] as num?)?.toInt() ?? 0,
senderUserId: (json["SenderUserID"] as num?)?.toInt() ?? (json["senderUserId"] as num?)?.toInt() ?? 0,
senderType: json["SenderType"] as String? ?? json["senderType"] as String? ?? "customer",
senderName: json["SenderName"] as String? ?? json["senderName"] as String? ?? "",
text: json["Text"] as String? ?? json["MessageText"] as String? ?? json["text"] as String? ?? "",
createdOn: DateTime.tryParse(
json["CreatedOn"] as String? ?? json["timestamp"] as String? ?? ""
) ?? DateTime.now(),
isRead: json["IsRead"] == 1 || json["IsRead"] == true || json["isRead"] == true,
);
}
Map<String, dynamic> toJson() {
return {
"messageId": messageId,
"taskId": taskId,
"senderUserId": senderUserId,
"senderType": senderType,
"senderName": senderName,
"text": text,
"timestamp": createdOn.toIso8601String(),
"isRead": isRead,
};
}
/// Check if this message was sent by the current user
bool isMine(String userType) => senderType == userType;
}