import 'dart:convert'; import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:huixiang/im/out/message.pb.dart'; import 'package:huixiang/im/out/message.pbenum.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:path_provider/path_provider.dart'; 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 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 toJson() => { "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, fromId, replyId}) { return { "conversationId": conversationId(fromId, toId), "fromId": fromId, "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"; }