update database
This commit is contained in:
186
lib/features/chat/domain/entities/chat_room.dart
Normal file
186
lib/features/chat/domain/entities/chat_room.dart
Normal file
@@ -0,0 +1,186 @@
|
||||
/// Domain Entity: Chat Room
|
||||
///
|
||||
/// Represents a chat conversation room.
|
||||
library;
|
||||
|
||||
/// Room type enum
|
||||
enum RoomType {
|
||||
/// Direct message between two users
|
||||
direct,
|
||||
|
||||
/// Group chat
|
||||
group,
|
||||
|
||||
/// Support chat with staff
|
||||
support,
|
||||
|
||||
/// Order-related chat
|
||||
order,
|
||||
|
||||
/// Quote-related chat
|
||||
quote;
|
||||
|
||||
/// Get display name for room type
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case RoomType.direct:
|
||||
return 'Direct';
|
||||
case RoomType.group:
|
||||
return 'Group';
|
||||
case RoomType.support:
|
||||
return 'Support';
|
||||
case RoomType.order:
|
||||
return 'Order';
|
||||
case RoomType.quote:
|
||||
return 'Quote';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Chat Room Entity
|
||||
///
|
||||
/// Contains information about a chat room:
|
||||
/// - Room type and participants
|
||||
/// - Related entities (order, quote)
|
||||
/// - Activity tracking
|
||||
class ChatRoom {
|
||||
/// Unique chat room identifier
|
||||
final String chatRoomId;
|
||||
|
||||
/// Room type
|
||||
final RoomType roomType;
|
||||
|
||||
/// Related quote ID (if quote chat)
|
||||
final String? relatedQuoteId;
|
||||
|
||||
/// Related order ID (if order chat)
|
||||
final String? relatedOrderId;
|
||||
|
||||
/// Participant user IDs
|
||||
final List<String> participants;
|
||||
|
||||
/// Room name (for group chats)
|
||||
final String? roomName;
|
||||
|
||||
/// Room is active
|
||||
final bool isActive;
|
||||
|
||||
/// Last activity timestamp
|
||||
final DateTime? lastActivity;
|
||||
|
||||
/// Room creation timestamp
|
||||
final DateTime createdAt;
|
||||
|
||||
/// User ID who created the room
|
||||
final String? createdBy;
|
||||
|
||||
const ChatRoom({
|
||||
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,
|
||||
});
|
||||
|
||||
/// Check if room is direct message
|
||||
bool get isDirect => roomType == RoomType.direct;
|
||||
|
||||
/// Check if room is group chat
|
||||
bool get isGroup => roomType == RoomType.group;
|
||||
|
||||
/// Check if room is support chat
|
||||
bool get isSupport => roomType == RoomType.support;
|
||||
|
||||
/// Check if room has order context
|
||||
bool get hasOrderContext =>
|
||||
roomType == RoomType.order && relatedOrderId != null;
|
||||
|
||||
/// Check if room has quote context
|
||||
bool get hasQuoteContext =>
|
||||
roomType == RoomType.quote && relatedQuoteId != null;
|
||||
|
||||
/// Get number of participants
|
||||
int get participantCount => participants.length;
|
||||
|
||||
/// Get display name for room
|
||||
String get displayName {
|
||||
if (roomName != null && roomName!.isNotEmpty) return roomName!;
|
||||
if (isSupport) return 'Customer Support';
|
||||
if (hasOrderContext) return 'Order Chat';
|
||||
if (hasQuoteContext) return 'Quote Discussion';
|
||||
return 'Chat';
|
||||
}
|
||||
|
||||
/// Get time since last activity
|
||||
Duration? get timeSinceLastActivity {
|
||||
if (lastActivity == null) return null;
|
||||
return DateTime.now().difference(lastActivity!);
|
||||
}
|
||||
|
||||
/// Check if user is participant
|
||||
bool isParticipant(String userId) {
|
||||
return participants.contains(userId);
|
||||
}
|
||||
|
||||
/// Copy with method for immutability
|
||||
ChatRoom copyWith({
|
||||
String? chatRoomId,
|
||||
RoomType? roomType,
|
||||
String? relatedQuoteId,
|
||||
String? relatedOrderId,
|
||||
List<String>? participants,
|
||||
String? roomName,
|
||||
bool? isActive,
|
||||
DateTime? lastActivity,
|
||||
DateTime? createdAt,
|
||||
String? createdBy,
|
||||
}) {
|
||||
return ChatRoom(
|
||||
chatRoomId: chatRoomId ?? this.chatRoomId,
|
||||
roomType: roomType ?? this.roomType,
|
||||
relatedQuoteId: relatedQuoteId ?? this.relatedQuoteId,
|
||||
relatedOrderId: relatedOrderId ?? this.relatedOrderId,
|
||||
participants: participants ?? this.participants,
|
||||
roomName: roomName ?? this.roomName,
|
||||
isActive: isActive ?? this.isActive,
|
||||
lastActivity: lastActivity ?? this.lastActivity,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is ChatRoom &&
|
||||
other.chatRoomId == chatRoomId &&
|
||||
other.roomType == roomType &&
|
||||
other.relatedQuoteId == relatedQuoteId &&
|
||||
other.relatedOrderId == relatedOrderId &&
|
||||
other.isActive == isActive;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
chatRoomId,
|
||||
roomType,
|
||||
relatedQuoteId,
|
||||
relatedOrderId,
|
||||
isActive,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChatRoom(chatRoomId: $chatRoomId, roomType: $roomType, '
|
||||
'displayName: $displayName, participantCount: $participantCount, '
|
||||
'isActive: $isActive)';
|
||||
}
|
||||
}
|
||||
212
lib/features/chat/domain/entities/message.dart
Normal file
212
lib/features/chat/domain/entities/message.dart
Normal file
@@ -0,0 +1,212 @@
|
||||
/// Domain Entity: Message
|
||||
///
|
||||
/// Represents a chat message in a conversation.
|
||||
library;
|
||||
|
||||
/// Content type enum
|
||||
enum ContentType {
|
||||
/// Plain text message
|
||||
text,
|
||||
|
||||
/// Image message
|
||||
image,
|
||||
|
||||
/// File attachment
|
||||
file,
|
||||
|
||||
/// Product reference
|
||||
product,
|
||||
|
||||
/// System notification
|
||||
system;
|
||||
|
||||
/// Get display name for content type
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case ContentType.text:
|
||||
return 'Text';
|
||||
case ContentType.image:
|
||||
return 'Image';
|
||||
case ContentType.file:
|
||||
return 'File';
|
||||
case ContentType.product:
|
||||
return 'Product';
|
||||
case ContentType.system:
|
||||
return 'System';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Message Entity
|
||||
///
|
||||
/// Contains information about a chat message:
|
||||
/// - Message content
|
||||
/// - Sender information
|
||||
/// - Attachments
|
||||
/// - Read status
|
||||
/// - Edit history
|
||||
class Message {
|
||||
/// Unique message identifier
|
||||
final String messageId;
|
||||
|
||||
/// Chat room ID this message belongs to
|
||||
final String chatRoomId;
|
||||
|
||||
/// Sender user ID
|
||||
final String senderId;
|
||||
|
||||
/// Content type
|
||||
final ContentType contentType;
|
||||
|
||||
/// Message content/text
|
||||
final String content;
|
||||
|
||||
/// Attachment URL (for images/files)
|
||||
final String? attachmentUrl;
|
||||
|
||||
/// Product reference ID (if product message)
|
||||
final String? productReference;
|
||||
|
||||
/// Message is read
|
||||
final bool isRead;
|
||||
|
||||
/// Message has been edited
|
||||
final bool isEdited;
|
||||
|
||||
/// Message has been deleted
|
||||
final bool isDeleted;
|
||||
|
||||
/// User IDs who have read this message
|
||||
final List<String> readBy;
|
||||
|
||||
/// Message timestamp
|
||||
final DateTime timestamp;
|
||||
|
||||
/// Edit timestamp
|
||||
final DateTime? editedAt;
|
||||
|
||||
const Message({
|
||||
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,
|
||||
required this.readBy,
|
||||
required this.timestamp,
|
||||
this.editedAt,
|
||||
});
|
||||
|
||||
/// Check if message is text
|
||||
bool get isText => contentType == ContentType.text;
|
||||
|
||||
/// Check if message is image
|
||||
bool get isImage => contentType == ContentType.image;
|
||||
|
||||
/// Check if message is file
|
||||
bool get isFile => contentType == ContentType.file;
|
||||
|
||||
/// Check if message is product reference
|
||||
bool get isProductReference => contentType == ContentType.product;
|
||||
|
||||
/// Check if message is system notification
|
||||
bool get isSystemMessage => contentType == ContentType.system;
|
||||
|
||||
/// Check if message has attachment
|
||||
bool get hasAttachment =>
|
||||
attachmentUrl != null && attachmentUrl!.isNotEmpty;
|
||||
|
||||
/// Check if message references a product
|
||||
bool get hasProductReference =>
|
||||
productReference != null && productReference!.isNotEmpty;
|
||||
|
||||
/// Get number of readers
|
||||
int get readerCount => readBy.length;
|
||||
|
||||
/// Check if user has read this message
|
||||
bool isReadBy(String userId) {
|
||||
return readBy.contains(userId);
|
||||
}
|
||||
|
||||
/// Check if message is sent by user
|
||||
bool isSentBy(String userId) {
|
||||
return senderId == userId;
|
||||
}
|
||||
|
||||
/// Get time since message was sent
|
||||
Duration get timeSinceSent {
|
||||
return DateTime.now().difference(timestamp);
|
||||
}
|
||||
|
||||
/// Copy with method for immutability
|
||||
Message copyWith({
|
||||
String? messageId,
|
||||
String? chatRoomId,
|
||||
String? senderId,
|
||||
ContentType? contentType,
|
||||
String? content,
|
||||
String? attachmentUrl,
|
||||
String? productReference,
|
||||
bool? isRead,
|
||||
bool? isEdited,
|
||||
bool? isDeleted,
|
||||
List<String>? readBy,
|
||||
DateTime? timestamp,
|
||||
DateTime? editedAt,
|
||||
}) {
|
||||
return Message(
|
||||
messageId: messageId ?? this.messageId,
|
||||
chatRoomId: chatRoomId ?? this.chatRoomId,
|
||||
senderId: senderId ?? this.senderId,
|
||||
contentType: contentType ?? this.contentType,
|
||||
content: content ?? this.content,
|
||||
attachmentUrl: attachmentUrl ?? this.attachmentUrl,
|
||||
productReference: productReference ?? this.productReference,
|
||||
isRead: isRead ?? this.isRead,
|
||||
isEdited: isEdited ?? this.isEdited,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
readBy: readBy ?? this.readBy,
|
||||
timestamp: timestamp ?? this.timestamp,
|
||||
editedAt: editedAt ?? this.editedAt,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is Message &&
|
||||
other.messageId == messageId &&
|
||||
other.chatRoomId == chatRoomId &&
|
||||
other.senderId == senderId &&
|
||||
other.contentType == contentType &&
|
||||
other.content == content &&
|
||||
other.isRead == isRead &&
|
||||
other.isEdited == isEdited &&
|
||||
other.isDeleted == isDeleted;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
messageId,
|
||||
chatRoomId,
|
||||
senderId,
|
||||
contentType,
|
||||
content,
|
||||
isRead,
|
||||
isEdited,
|
||||
isDeleted,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Message(messageId: $messageId, senderId: $senderId, '
|
||||
'contentType: $contentType, isRead: $isRead, timestamp: $timestamp)';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user