update database
This commit is contained in:
57
lib/features/chat/data/models/chat_room_model.dart
Normal file
57
lib/features/chat/data/models/chat_room_model.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
|
||||
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;
|
||||
|
||||
factory ChatRoomModel.fromJson(Map<String, dynamic> json) => ChatRoomModel(
|
||||
chatRoomId: json['chat_room_id'] as String,
|
||||
roomType: RoomType.values.firstWhere((e) => e.name == json['room_type']),
|
||||
relatedQuoteId: json['related_quote_id'] as String?,
|
||||
relatedOrderId: json['related_order_id'] as String?,
|
||||
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,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
createdBy: json['created_by'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'chat_room_id': chatRoomId,
|
||||
'room_type': roomType.name,
|
||||
'related_quote_id': relatedQuoteId,
|
||||
'related_order_id': relatedOrderId,
|
||||
'participants': jsonDecode(participants),
|
||||
'room_name': roomName,
|
||||
'is_active': isActive,
|
||||
'last_activity': lastActivity?.toIso8601String(),
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'created_by': createdBy,
|
||||
};
|
||||
|
||||
List<String>? get participantsList {
|
||||
try {
|
||||
final decoded = jsonDecode(participants) as List;
|
||||
return decoded.map((e) => e.toString()).toList();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
68
lib/features/chat/data/models/chat_room_model.g.dart
Normal file
68
lib/features/chat/data/models/chat_room_model.g.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_room_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ChatRoomModelAdapter extends TypeAdapter<ChatRoomModel> {
|
||||
@override
|
||||
final typeId = 18;
|
||||
|
||||
@override
|
||||
ChatRoomModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ChatRoomModel(
|
||||
chatRoomId: fields[0] as String,
|
||||
roomType: fields[1] as RoomType,
|
||||
relatedQuoteId: fields[2] as String?,
|
||||
relatedOrderId: fields[3] as String?,
|
||||
participants: fields[4] as String,
|
||||
roomName: fields[5] as String?,
|
||||
isActive: fields[6] as bool,
|
||||
lastActivity: fields[7] as DateTime?,
|
||||
createdAt: fields[8] as DateTime,
|
||||
createdBy: fields[9] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ChatRoomModel obj) {
|
||||
writer
|
||||
..writeByte(10)
|
||||
..writeByte(0)
|
||||
..write(obj.chatRoomId)
|
||||
..writeByte(1)
|
||||
..write(obj.roomType)
|
||||
..writeByte(2)
|
||||
..write(obj.relatedQuoteId)
|
||||
..writeByte(3)
|
||||
..write(obj.relatedOrderId)
|
||||
..writeByte(4)
|
||||
..write(obj.participants)
|
||||
..writeByte(5)
|
||||
..write(obj.roomName)
|
||||
..writeByte(6)
|
||||
..write(obj.isActive)
|
||||
..writeByte(7)
|
||||
..write(obj.lastActivity)
|
||||
..writeByte(8)
|
||||
..write(obj.createdAt)
|
||||
..writeByte(9)
|
||||
..write(obj.createdBy);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ChatRoomModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
67
lib/features/chat/data/models/message_model.dart
Normal file
67
lib/features/chat/data/models/message_model.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
|
||||
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;
|
||||
|
||||
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']),
|
||||
content: json['content'] as String,
|
||||
attachmentUrl: json['attachment_url'] as String?,
|
||||
productReference: json['product_reference'] as String?,
|
||||
isRead: json['is_read'] as bool? ?? false,
|
||||
isEdited: json['is_edited'] as bool? ?? false,
|
||||
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,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'message_id': messageId,
|
||||
'chat_room_id': chatRoomId,
|
||||
'sender_id': senderId,
|
||||
'content_type': contentType.name,
|
||||
'content': content,
|
||||
'attachment_url': attachmentUrl,
|
||||
'product_reference': productReference,
|
||||
'is_read': isRead,
|
||||
'is_edited': isEdited,
|
||||
'is_deleted': isDeleted,
|
||||
'read_by': readBy != null ? jsonDecode(readBy!) : null,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
'edited_at': editedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
List<String>? get readByList {
|
||||
if (readBy == null) return null;
|
||||
try {
|
||||
final decoded = jsonDecode(readBy!) as List;
|
||||
return decoded.map((e) => e.toString()).toList();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
lib/features/chat/data/models/message_model.g.dart
Normal file
77
lib/features/chat/data/models/message_model.g.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'message_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class MessageModelAdapter extends TypeAdapter<MessageModel> {
|
||||
@override
|
||||
final typeId = 19;
|
||||
|
||||
@override
|
||||
MessageModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return MessageModel(
|
||||
messageId: fields[0] as String,
|
||||
chatRoomId: fields[1] as String,
|
||||
senderId: fields[2] as String,
|
||||
contentType: fields[3] as ContentType,
|
||||
content: fields[4] as String,
|
||||
attachmentUrl: fields[5] as String?,
|
||||
productReference: fields[6] as String?,
|
||||
isRead: fields[7] as bool,
|
||||
isEdited: fields[8] as bool,
|
||||
isDeleted: fields[9] as bool,
|
||||
readBy: fields[10] as String?,
|
||||
timestamp: fields[11] as DateTime,
|
||||
editedAt: fields[12] as DateTime?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, MessageModel obj) {
|
||||
writer
|
||||
..writeByte(13)
|
||||
..writeByte(0)
|
||||
..write(obj.messageId)
|
||||
..writeByte(1)
|
||||
..write(obj.chatRoomId)
|
||||
..writeByte(2)
|
||||
..write(obj.senderId)
|
||||
..writeByte(3)
|
||||
..write(obj.contentType)
|
||||
..writeByte(4)
|
||||
..write(obj.content)
|
||||
..writeByte(5)
|
||||
..write(obj.attachmentUrl)
|
||||
..writeByte(6)
|
||||
..write(obj.productReference)
|
||||
..writeByte(7)
|
||||
..write(obj.isRead)
|
||||
..writeByte(8)
|
||||
..write(obj.isEdited)
|
||||
..writeByte(9)
|
||||
..write(obj.isDeleted)
|
||||
..writeByte(10)
|
||||
..write(obj.readBy)
|
||||
..writeByte(11)
|
||||
..write(obj.timestamp)
|
||||
..writeByte(12)
|
||||
..write(obj.editedAt);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is MessageModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
Reference in New Issue
Block a user