|
|
|
@ -208,8 +208,8 @@ class SocketClient {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Future<Message> sendMessage(String toId, String content) async { |
|
|
|
|
Map<String, dynamic> message = createMessage(toId, content, fromId: userId); |
|
|
|
|
Future<Message> sendMessage(String toId, String content, {String attach, int msgType, replyId}) async { |
|
|
|
|
Map<String, dynamic> message = createMessage(toId, content, fromId: userId, attach: attach, msgType: msgType, replyId: replyId); |
|
|
|
|
message["state"] = 1; |
|
|
|
|
int id = await hxDatabase.insert(message).catchError((error) { |
|
|
|
|
debugPrint("insertMessage: $error"); |
|
|
|
@ -223,8 +223,19 @@ class SocketClient {
|
|
|
|
|
return Message.fromJson(message); |
|
|
|
|
} |
|
|
|
|
message["id"] = id; |
|
|
|
|
Uint8List data = utf8.encode(content); |
|
|
|
|
MsgData msgData = MsgData(to: toId, from: userId, type: MsgType.TEXT, data: data); |
|
|
|
|
|
|
|
|
|
MsgType type = MsgType.values[msgType]; |
|
|
|
|
Uint8List data; |
|
|
|
|
if (type == MsgType.TEXT) { |
|
|
|
|
data = utf8.encode(content); |
|
|
|
|
} else if (type == MsgType.IMAGE || type == MsgType.VIDEO || type == MsgType.AUDIO) { |
|
|
|
|
File file = File(attach); |
|
|
|
|
data = await file.readAsBytes(); |
|
|
|
|
} else { |
|
|
|
|
data = utf8.encode(content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MsgData msgData = MsgData(to: toId, from: userId, type: type, data: data); |
|
|
|
|
final proto2 = Proto(5, 1, msgData.writeToBuffer()); |
|
|
|
|
try { |
|
|
|
|
_socket.add(proto2.toBytes()); |
|
|
|
@ -239,6 +250,8 @@ class SocketClient {
|
|
|
|
|
return Message.fromJson(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkSocket() { |
|
|
|
|
if (_socket == null) { |
|
|
|
|
reconnect(); |
|
|
|
|