mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Merge commit 'e5d30a9f6d0854e20049309333c2f637cd03025c' as 'frontend'
This commit is contained in:
55
frontend/lib/models/chat.dart
Normal file
55
frontend/lib/models/chat.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:auto_gpt_flutter_client/models/message_type.dart';
|
||||
|
||||
/// Represents a chat message related to a specific task.
|
||||
class Chat {
|
||||
final String id;
|
||||
final String taskId;
|
||||
final String message;
|
||||
final DateTime timestamp;
|
||||
final MessageType messageType;
|
||||
final Map<String, dynamic>? jsonResponse;
|
||||
|
||||
Chat({
|
||||
required this.id,
|
||||
required this.taskId,
|
||||
required this.message,
|
||||
required this.timestamp,
|
||||
required this.messageType,
|
||||
this.jsonResponse,
|
||||
});
|
||||
|
||||
// Convert a Map (usually from JSON) to a Chat object
|
||||
factory Chat.fromMap(Map<String, dynamic> map) {
|
||||
return Chat(
|
||||
id: map['id'],
|
||||
taskId: map['taskId'],
|
||||
message: map['message'],
|
||||
timestamp: DateTime.parse(map['timestamp']),
|
||||
messageType: MessageType.values.firstWhere(
|
||||
(e) => e.toString() == 'MessageType.${map['messageType']}'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Chat &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
taskId == other.taskId &&
|
||||
message == other.message &&
|
||||
timestamp == other.timestamp &&
|
||||
messageType == other.messageType;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
id.hashCode ^
|
||||
taskId.hashCode ^
|
||||
message.hashCode ^
|
||||
timestamp.hashCode ^
|
||||
messageType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'Chat(id: $id, taskId: $taskId, message: $message, timestamp: $timestamp, messageType: $messageType)';
|
||||
}
|
||||
Reference in New Issue
Block a user