Initial commit: Captain Claude Mobile App
- Flutter app with chat and terminal screens - WebSocket integration for real-time chat - xterm integration for screen sessions - Markdown rendering with code blocks - JWT authentication Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
65
lib/models/message.dart
Normal file
65
lib/models/message.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Message {
|
||||
final String id;
|
||||
final String role; // 'user' or 'assistant'
|
||||
final String content;
|
||||
final DateTime timestamp;
|
||||
final bool isStreaming;
|
||||
final List<String>? attachments;
|
||||
|
||||
Message({
|
||||
String? id,
|
||||
required this.role,
|
||||
required this.content,
|
||||
DateTime? timestamp,
|
||||
this.isStreaming = false,
|
||||
this.attachments,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
timestamp = timestamp ?? DateTime.now();
|
||||
|
||||
Message copyWith({
|
||||
String? id,
|
||||
String? role,
|
||||
String? content,
|
||||
DateTime? timestamp,
|
||||
bool? isStreaming,
|
||||
List<String>? attachments,
|
||||
}) {
|
||||
return Message(
|
||||
id: id ?? this.id,
|
||||
role: role ?? this.role,
|
||||
content: content ?? this.content,
|
||||
timestamp: timestamp ?? this.timestamp,
|
||||
isStreaming: isStreaming ?? this.isStreaming,
|
||||
attachments: attachments ?? this.attachments,
|
||||
);
|
||||
}
|
||||
|
||||
factory Message.fromJson(Map<String, dynamic> json) {
|
||||
return Message(
|
||||
id: json['id'],
|
||||
role: json['role'],
|
||||
content: json['content'],
|
||||
timestamp: json['timestamp'] != null
|
||||
? DateTime.parse(json['timestamp'])
|
||||
: DateTime.now(),
|
||||
attachments: json['attachments'] != null
|
||||
? List<String>.from(json['attachments'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'role': role,
|
||||
'content': content,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
'attachments': attachments,
|
||||
};
|
||||
}
|
||||
|
||||
bool get isUser => role == 'user';
|
||||
bool get isAssistant => role == 'assistant';
|
||||
}
|
||||
Reference in New Issue
Block a user