81 lines
1.8 KiB
Dart
81 lines
1.8 KiB
Dart
import '../profileData/user_data.dart';
|
|
|
|
class ChatModel {
|
|
static const stateNone = 0;
|
|
static const stateError = -1;
|
|
static const stateLoading = 1;
|
|
static const stateSuccess = 2;
|
|
|
|
static const String fileTypeLocalPath = "localPath";
|
|
|
|
ChatModel({
|
|
this.id,
|
|
this.from,
|
|
this.to,
|
|
this.message,
|
|
this.messageType,
|
|
this.filePath,
|
|
this.date,
|
|
this.archived,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
this.localId,
|
|
this.fileType,
|
|
this.state = stateNone,
|
|
});
|
|
|
|
ChatModel.fromJson(dynamic json) {
|
|
from = json['from'] != null ? UserData.fromJson(json['from']) : null;
|
|
to = json['to'] != null ? UserData.fromJson(json['to']) : null;
|
|
id = json['_id'];
|
|
message = json['message'];
|
|
messageType = json['messageType'];
|
|
filePath = json['filePath'];
|
|
date = json['date'];
|
|
localId = json['localId'];
|
|
archived = json['archived'];
|
|
createdAt = json['createdAt'];
|
|
updatedAt = json['updatedAt'];
|
|
|
|
date = DateTime.tryParse(createdAt ?? "")?.millisecondsSinceEpoch ?? 0;
|
|
}
|
|
|
|
String? id;
|
|
UserData? from;
|
|
UserData? to;
|
|
String? message;
|
|
String? messageType;
|
|
String? filePath;
|
|
int? date;
|
|
bool? archived;
|
|
String? createdAt;
|
|
String? updatedAt;
|
|
|
|
//Local usage variables
|
|
int state = stateNone;
|
|
String? fileType;
|
|
String? localId;
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final map = <String, dynamic>{};
|
|
if (from != null) {
|
|
map['from'] = from?.toJson();
|
|
}
|
|
if (to != null) {
|
|
map['to'] = to?.toJson();
|
|
}
|
|
map['_id'] = id;
|
|
map['message'] = message;
|
|
map['messageType'] = messageType;
|
|
map['filePath'] = filePath;
|
|
map['date'] = date;
|
|
map['archived'] = archived;
|
|
map['createdAt'] = createdAt;
|
|
map['updatedAt'] = updatedAt;
|
|
map['localId'] = localId;
|
|
map['state'] = state;
|
|
map['isSent'] = state;
|
|
return map;
|
|
}
|
|
}
|