39 lines
1.0 KiB
Dart
39 lines
1.0 KiB
Dart
class Conversation {
|
|
final String id;
|
|
final String? title;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final int messageCount;
|
|
|
|
Conversation({
|
|
required this.id,
|
|
this.title,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
this.messageCount = 0,
|
|
});
|
|
|
|
factory Conversation.fromJson(Map<String, dynamic> json) {
|
|
return Conversation(
|
|
id: json['id'],
|
|
title: json['title'],
|
|
createdAt: DateTime.parse(json['created_at']),
|
|
updatedAt: DateTime.parse(json['updated_at']),
|
|
messageCount: json['message_count'] ?? 0,
|
|
);
|
|
}
|
|
|
|
String get displayTitle => title ?? 'New Conversation';
|
|
|
|
String get timeAgo {
|
|
final now = DateTime.now();
|
|
final diff = now.difference(updatedAt);
|
|
|
|
if (diff.inMinutes < 1) return 'Just now';
|
|
if (diff.inMinutes < 60) return '${diff.inMinutes}m ago';
|
|
if (diff.inHours < 24) return '${diff.inHours}h ago';
|
|
if (diff.inDays < 7) return '${diff.inDays}d ago';
|
|
return '${updatedAt.day}/${updatedAt.month}/${updatedAt.year}';
|
|
}
|
|
}
|