|
|
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
class Message {
|
|
|
|
int id;
|
|
|
|
|
|
|
|
String conversationId;
|
|
|
|
|
|
|
|
String fromId;
|
|
|
|
|
|
|
|
String toId;
|
|
|
|
|
|
|
|
String replyId;
|
|
|
|
|
|
|
|
String content;
|
|
|
|
|
|
|
|
String attach;
|
|
|
|
|
|
|
|
int msgType;
|
|
|
|
|
|
|
|
String time;
|
|
|
|
|
|
|
|
/// 0 unread, 1 read, 2
|
|
|
|
int state;
|
|
|
|
|
|
|
|
int isDelete;
|
|
|
|
|
|
|
|
bool showTime = false;
|
|
|
|
|
|
|
|
Message(this.id, this.conversationId, this.fromId, this.toId, this.replyId, this.content, this.attach, this.msgType, this.time, this.state, this.isDelete);
|
|
|
|
|
|
|
|
factory Message.fromJson(Map<String, dynamic> json) => Message(
|
|
|
|
json["id"],
|
|
|
|
json["conversationId"],
|
|
|
|
json["fromId"],
|
|
|
|
json["toId"],
|
|
|
|
json["replyId"],
|
|
|
|
json["content"],
|
|
|
|
json["attach"],
|
|
|
|
json["msgType"],
|
|
|
|
json["time"],
|
|
|
|
json["state"],
|
|
|
|
json["isDelete"]);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => <String, dynamic>{
|
|
|
|
"id": id,
|
|
|
|
"conversationId": conversationId,
|
|
|
|
"fromId": fromId,
|
|
|
|
"toId": toId,
|
|
|
|
"replyId": replyId,
|
|
|
|
"content": content,
|
|
|
|
"attach": attach,
|
|
|
|
"msgType": msgType,
|
|
|
|
"time": time,
|
|
|
|
"state": state,
|
|
|
|
"isDelete": isDelete == null ? 0 : isDelete
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
createMessage(var toId, String content, {String attach, int msgType, userId, replyId}) {
|
|
|
|
return <String, dynamic>{
|
|
|
|
"conversationId": conversationId(userId, toId),
|
|
|
|
"fromId": userId,
|
|
|
|
"toId": toId,
|
|
|
|
"replyId": replyId,
|
|
|
|
"content": content,
|
|
|
|
"attach": attach,
|
|
|
|
"msgType": msgType ?? 1,
|
|
|
|
"time": "${DateTime.now().millisecondsSinceEpoch}",
|
|
|
|
"state": 0,
|
|
|
|
"isDelete": 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
conversationId(tid, fid) {
|
|
|
|
num itid = num.parse(tid);
|
|
|
|
num ifid = num.parse(fid);
|
|
|
|
if (itid > ifid) {
|
|
|
|
return "$ifid-$itid";
|
|
|
|
}
|
|
|
|
return "$itid-$ifid";
|
|
|
|
}
|