diff --git a/lib/data/chat_data_mgr.dart b/lib/data/chat_data_mgr.dart index 956bfdb..0000f3f 100644 --- a/lib/data/chat_data_mgr.dart +++ b/lib/data/chat_data_mgr.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:chat/data/group_data_mgr.dart'; import 'package:chat/models/ChatMsg.dart'; import 'package:chat/models/last_msg_provider.dart'; @@ -112,6 +114,38 @@ class ChatDataMgr { return record; } + //获取该记录之前的前3条聊天记录 + getForeChatRecord(MsgModel msgModel) { + List res = []; + + List record; + if (msgModel.channelType == ChatChannelType.Group.value) { + record = groupRecordMap[msgModel.sessionId]; + } else { + record = msgRecordMap[msgModel.sessionId]; + } + + int curIndex = 0; + if (record != null && record.length > 0) { + for (var i = 0; i < record.length; i++) { + if (record[i].time == msgModel.time) { + curIndex = i; + break; + } + } + } + + int maxLen = min(curIndex + 1, record.length); + + for (var i = curIndex + 1; i < maxLen; i++) { + var shortDesc = record[i].shortRecordForTranslator(); + print(shortDesc); + res.add(shortDesc); + } + + return res; + } + //获取企业号聊天记录 List getCompanyRecord() { var record = msgRecordMap[MsgHandler.curActiveSession]; diff --git a/lib/data/group_data_mgr.dart b/lib/data/group_data_mgr.dart index 052abfe..11ba197 100644 --- a/lib/data/group_data_mgr.dart +++ b/lib/data/group_data_mgr.dart @@ -176,6 +176,32 @@ class GroupInfoMgr { return ''; } + //获取群名 + getGroupName(int groupId) { + for (var i = 0; i < groupInfoList.length; i++) { + var info = groupInfoList[i]; + if (info.sessionId == groupId) { + if (info.name != null && info.name != '') { + return info.name; + } else { + var members = info.getMembersInGroup(); + String res = ''; + int nums = members.length > 4 ? 4 : members.length; + for (int i = 0; i < nums; i++) { + if (i != 0) { + res += '、'; + } + String name = members[i].refName; + res += name.length > 8 ? name.substring(0, 8) + '..' : name; + } + return res; + } + } + } + + return ''; + } + //获取群信息 Future getGroupInfo(int sessionId, {bool isSave = true}) async { diff --git a/lib/models/ChatMsg.dart b/lib/models/ChatMsg.dart index b8162cf..863cb32 100644 --- a/lib/models/ChatMsg.dart +++ b/lib/models/ChatMsg.dart @@ -1,10 +1,17 @@ import 'dart:typed_data'; import 'dart:convert'; +import 'package:chat/data/UserData.dart'; +import 'package:chat/data/constants.dart'; +import 'package:chat/generated/i18n.dart'; +import 'package:chat/proto/chat.pb.dart'; import 'package:chat/proto/chat.pbenum.dart'; +import 'package:chat/proto/transhousekeeper.pb.dart'; +import 'package:chat/utils/date_utils.dart'; import 'package:chat/utils/file_cache_mgr.dart'; import 'package:chat/utils/sql_util.dart'; import 'package:chat/data/group_data_mgr.dart'; +import 'package:chat/utils/upload_util.dart'; class MsgState { static const int None = 0; //默认 @@ -196,4 +203,84 @@ class MsgModel { return textList.length == 0 ? [''] : textList; } + + getFileUrl() { + var fullUrl = UploadUtil().getFullUrl(extraFile, sessionId, channelType); + if (extraFile.contains('http://')) { + fullUrl = extraFile; + } + + return fullUrl; + } + + //发送给翻译人员的记录 + shortRecordForTranslator() { + String desc = ''; + switch (ChatType.valueOf(msgType)) { + case ChatType.TextChatType: + desc = utf8.decode(msgContent); + break; + case ChatType.EmoticonType: + desc = '[${I18n.of(Constants.getCurrentContext()).emoji}]'; + break; + case ChatType.ImageChatType: + case ChatType.ShortVideoChatType: + case ChatType.ShortVoiceChatType: + case ChatType.FileChatType: + desc = getFileUrl(); + break; + + case ChatType.PlaceChatType: + desc = '[${I18n.of(Constants.getCurrentContext()).locate}]'; + break; + + case ChatType.GiftChatType: + GiftChat giftChat = GiftChat.fromBuffer(msgContent); + + if (giftChat.tuId == UserData().basicInfo.userId) { + desc = I18n.of(Constants.getCurrentContext()).you_get; + } else { + desc = I18n.of(Constants.getCurrentContext()).you_give; + } + + break; + + case ChatType.RedWalletChatType: + if (from == 0) { + //服务器通知消息 + RedWallet wallet = RedWallet.fromBuffer(msgContent); + if (wallet.state == RedWalletState.Received) { + var myId = UserData().basicInfo.userId; + if (wallet.suId == myId) { + desc = I18n.of(Constants.getCurrentContext()) + .get_money + .replaceFirst('/s1', '好友'); + } else { + desc = I18n.of(Constants.getCurrentContext()) + .you_get_money + .replaceFirst('/s1', '好友'); + } + } else if (wallet.state == RedWalletState.Expire) { + desc = I18n.of(Constants.getCurrentContext()).money_over; + } else { + print('WWWWW${wallet.state}'); + } + } else { + desc = '[${I18n.of(Constants.getCurrentContext()).red_money}]'; + } + break; + + case ChatType.GroupChatNoticeType: + desc = '群聊通知消息'; + break; + default: + } + + return { + 'SendTime' : + DateUtils().getFormartData(timeSamp: time, format: 'yyyy:MM:dd hh:mm:ss'); + 'Content' : desc, + 'UserId':from + }; + } } diff --git a/lib/utils/HttpUtil.dart b/lib/utils/HttpUtil.dart index 35d40a1..23292a4 100644 --- a/lib/utils/HttpUtil.dart +++ b/lib/utils/HttpUtil.dart @@ -1102,11 +1102,20 @@ class HttpUtil { showToast('请稍后再试'); return; } - data['content'] = base64Encode(File(msgModel.localFile).readAsBytesSync()); + data['content'] = + base64Encode(File(msgModel.localFile).readAsBytesSync()); print('语音转换的文字: ${utf8.decode(msgModel.enTranslateContent)}'); data['vcontent'] = base64Encode(msgModel.enTranslateContent); } + if (msgModel.channelType == ChatChannelType.Group.value) { + data['theme'] = GroupInfoMgr().getGroupName(msgModel.sessionId); + } else { + data['theme'] = ''; + } + + data['list'] = ChatDataMgr().getForeChatRecord(msgModel); + data["tuserids"] = [UserData().basicInfo.userId]; data['duration'] = msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0;