add auth, format
This commit is contained in:
@@ -7,18 +7,39 @@ part 'chat_room_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.chatRoomModel)
|
||||
class ChatRoomModel extends HiveObject {
|
||||
ChatRoomModel({required this.chatRoomId, required this.roomType, this.relatedQuoteId, this.relatedOrderId, required this.participants, this.roomName, required this.isActive, this.lastActivity, required this.createdAt, this.createdBy});
|
||||
|
||||
@HiveField(0) final String chatRoomId;
|
||||
@HiveField(1) final RoomType roomType;
|
||||
@HiveField(2) final String? relatedQuoteId;
|
||||
@HiveField(3) final String? relatedOrderId;
|
||||
@HiveField(4) final String participants;
|
||||
@HiveField(5) final String? roomName;
|
||||
@HiveField(6) final bool isActive;
|
||||
@HiveField(7) final DateTime? lastActivity;
|
||||
@HiveField(8) final DateTime createdAt;
|
||||
@HiveField(9) final String? createdBy;
|
||||
ChatRoomModel({
|
||||
required this.chatRoomId,
|
||||
required this.roomType,
|
||||
this.relatedQuoteId,
|
||||
this.relatedOrderId,
|
||||
required this.participants,
|
||||
this.roomName,
|
||||
required this.isActive,
|
||||
this.lastActivity,
|
||||
required this.createdAt,
|
||||
this.createdBy,
|
||||
});
|
||||
|
||||
@HiveField(0)
|
||||
final String chatRoomId;
|
||||
@HiveField(1)
|
||||
final RoomType roomType;
|
||||
@HiveField(2)
|
||||
final String? relatedQuoteId;
|
||||
@HiveField(3)
|
||||
final String? relatedOrderId;
|
||||
@HiveField(4)
|
||||
final String participants;
|
||||
@HiveField(5)
|
||||
final String? roomName;
|
||||
@HiveField(6)
|
||||
final bool isActive;
|
||||
@HiveField(7)
|
||||
final DateTime? lastActivity;
|
||||
@HiveField(8)
|
||||
final DateTime createdAt;
|
||||
@HiveField(9)
|
||||
final String? createdBy;
|
||||
|
||||
factory ChatRoomModel.fromJson(Map<String, dynamic> json) => ChatRoomModel(
|
||||
chatRoomId: json['chat_room_id'] as String,
|
||||
@@ -28,7 +49,9 @@ class ChatRoomModel extends HiveObject {
|
||||
participants: jsonEncode(json['participants']),
|
||||
roomName: json['room_name'] as String?,
|
||||
isActive: json['is_active'] as bool? ?? true,
|
||||
lastActivity: json['last_activity'] != null ? DateTime.parse(json['last_activity']?.toString() ?? '') : null,
|
||||
lastActivity: json['last_activity'] != null
|
||||
? DateTime.parse(json['last_activity']?.toString() ?? '')
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
createdBy: json['created_by'] as String?,
|
||||
);
|
||||
|
||||
@@ -7,27 +7,56 @@ part 'message_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.messageModel)
|
||||
class MessageModel extends HiveObject {
|
||||
MessageModel({required this.messageId, required this.chatRoomId, required this.senderId, required this.contentType, required this.content, this.attachmentUrl, this.productReference, required this.isRead, required this.isEdited, required this.isDeleted, this.readBy, required this.timestamp, this.editedAt});
|
||||
|
||||
@HiveField(0) final String messageId;
|
||||
@HiveField(1) final String chatRoomId;
|
||||
@HiveField(2) final String senderId;
|
||||
@HiveField(3) final ContentType contentType;
|
||||
@HiveField(4) final String content;
|
||||
@HiveField(5) final String? attachmentUrl;
|
||||
@HiveField(6) final String? productReference;
|
||||
@HiveField(7) final bool isRead;
|
||||
@HiveField(8) final bool isEdited;
|
||||
@HiveField(9) final bool isDeleted;
|
||||
@HiveField(10) final String? readBy;
|
||||
@HiveField(11) final DateTime timestamp;
|
||||
@HiveField(12) final DateTime? editedAt;
|
||||
MessageModel({
|
||||
required this.messageId,
|
||||
required this.chatRoomId,
|
||||
required this.senderId,
|
||||
required this.contentType,
|
||||
required this.content,
|
||||
this.attachmentUrl,
|
||||
this.productReference,
|
||||
required this.isRead,
|
||||
required this.isEdited,
|
||||
required this.isDeleted,
|
||||
this.readBy,
|
||||
required this.timestamp,
|
||||
this.editedAt,
|
||||
});
|
||||
|
||||
@HiveField(0)
|
||||
final String messageId;
|
||||
@HiveField(1)
|
||||
final String chatRoomId;
|
||||
@HiveField(2)
|
||||
final String senderId;
|
||||
@HiveField(3)
|
||||
final ContentType contentType;
|
||||
@HiveField(4)
|
||||
final String content;
|
||||
@HiveField(5)
|
||||
final String? attachmentUrl;
|
||||
@HiveField(6)
|
||||
final String? productReference;
|
||||
@HiveField(7)
|
||||
final bool isRead;
|
||||
@HiveField(8)
|
||||
final bool isEdited;
|
||||
@HiveField(9)
|
||||
final bool isDeleted;
|
||||
@HiveField(10)
|
||||
final String? readBy;
|
||||
@HiveField(11)
|
||||
final DateTime timestamp;
|
||||
@HiveField(12)
|
||||
final DateTime? editedAt;
|
||||
|
||||
factory MessageModel.fromJson(Map<String, dynamic> json) => MessageModel(
|
||||
messageId: json['message_id'] as String,
|
||||
chatRoomId: json['chat_room_id'] as String,
|
||||
senderId: json['sender_id'] as String,
|
||||
contentType: ContentType.values.firstWhere((e) => e.name == json['content_type']),
|
||||
contentType: ContentType.values.firstWhere(
|
||||
(e) => e.name == json['content_type'],
|
||||
),
|
||||
content: json['content'] as String,
|
||||
attachmentUrl: json['attachment_url'] as String?,
|
||||
productReference: json['product_reference'] as String?,
|
||||
@@ -36,7 +65,9 @@ class MessageModel extends HiveObject {
|
||||
isDeleted: json['is_deleted'] as bool? ?? false,
|
||||
readBy: json['read_by'] != null ? jsonEncode(json['read_by']) : null,
|
||||
timestamp: DateTime.parse(json['timestamp']?.toString() ?? ''),
|
||||
editedAt: json['edited_at'] != null ? DateTime.parse(json['edited_at']?.toString() ?? '') : null,
|
||||
editedAt: json['edited_at'] != null
|
||||
? DateTime.parse(json['edited_at']?.toString() ?? '')
|
||||
: null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
|
||||
@@ -117,8 +117,7 @@ class Message {
|
||||
bool get isSystemMessage => contentType == ContentType.system;
|
||||
|
||||
/// Check if message has attachment
|
||||
bool get hasAttachment =>
|
||||
attachmentUrl != null && attachmentUrl!.isNotEmpty;
|
||||
bool get hasAttachment => attachmentUrl != null && attachmentUrl!.isNotEmpty;
|
||||
|
||||
/// Check if message references a product
|
||||
bool get hasProductReference =>
|
||||
|
||||
@@ -112,10 +112,16 @@ class _ChatListPageState extends ConsumerState<ChatListPage> {
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Tìm kiếm cuộc trò chuyện...',
|
||||
prefixIcon: const Icon(Icons.search, color: AppColors.grey500),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, color: AppColors.grey500),
|
||||
icon: const Icon(
|
||||
Icons.clear,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_searchController.clear();
|
||||
@@ -148,7 +154,10 @@ class _ChatListPageState extends ConsumerState<ChatListPage> {
|
||||
// Conversation 1 - Order Reference
|
||||
_ConversationItem(
|
||||
avatarIcon: Icons.inventory_2,
|
||||
avatarGradient: const [AppColors.primaryBlue, AppColors.lightBlue],
|
||||
avatarGradient: const [
|
||||
AppColors.primaryBlue,
|
||||
AppColors.lightBlue,
|
||||
],
|
||||
contactName: 'Đơn hàng #SO001234',
|
||||
messageTime: '14:30',
|
||||
lastMessage: 'Đơn hàng đang được giao - Dự kiến đến 16:00',
|
||||
@@ -183,7 +192,10 @@ class _ChatListPageState extends ConsumerState<ChatListPage> {
|
||||
// Conversation 3 - Support Team
|
||||
_ConversationItem(
|
||||
avatarIcon: Icons.headset_mic,
|
||||
avatarGradient: const [AppColors.primaryBlue, AppColors.lightBlue],
|
||||
avatarGradient: const [
|
||||
AppColors.primaryBlue,
|
||||
AppColors.lightBlue,
|
||||
],
|
||||
contactName: 'Tổng đài hỗ trợ',
|
||||
messageTime: '13:45',
|
||||
lastMessage: 'Thông tin về quy trình đổi trả sản phẩm',
|
||||
@@ -319,8 +331,8 @@ class _ConversationItem extends StatelessWidget {
|
||||
color: isOnline
|
||||
? AppColors.success
|
||||
: isAway
|
||||
? AppColors.warning
|
||||
: AppColors.grey500,
|
||||
? AppColors.warning
|
||||
: AppColors.grey500,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: AppColors.white, width: 2),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user