You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.0 KiB

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<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, fromId, replyId}) {
return <String, dynamic>{
"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";
}