@@ -1,3 +1,5 @@ | |||||
import 'dart:math'; | |||||
import 'package:chat/data/group_data_mgr.dart'; | import 'package:chat/data/group_data_mgr.dart'; | ||||
import 'package:chat/models/ChatMsg.dart'; | import 'package:chat/models/ChatMsg.dart'; | ||||
import 'package:chat/models/last_msg_provider.dart'; | import 'package:chat/models/last_msg_provider.dart'; | ||||
@@ -112,6 +114,38 @@ class ChatDataMgr { | |||||
return record; | 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<MsgModel> getCompanyRecord() { | List<MsgModel> getCompanyRecord() { | ||||
var record = msgRecordMap[MsgHandler.curActiveSession]; | var record = msgRecordMap[MsgHandler.curActiveSession]; | ||||
@@ -176,6 +176,32 @@ class GroupInfoMgr { | |||||
return ''; | 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<GroupInfoModel> getGroupInfo(int sessionId, | Future<GroupInfoModel> getGroupInfo(int sessionId, | ||||
{bool isSave = true}) async { | {bool isSave = true}) async { | ||||
@@ -1,10 +1,17 @@ | |||||
import 'dart:typed_data'; | import 'dart:typed_data'; | ||||
import 'dart:convert'; | 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/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/file_cache_mgr.dart'; | ||||
import 'package:chat/utils/sql_util.dart'; | import 'package:chat/utils/sql_util.dart'; | ||||
import 'package:chat/data/group_data_mgr.dart'; | import 'package:chat/data/group_data_mgr.dart'; | ||||
import 'package:chat/utils/upload_util.dart'; | |||||
class MsgState { | class MsgState { | ||||
static const int None = 0; //默认 | static const int None = 0; //默认 | ||||
@@ -196,4 +203,84 @@ class MsgModel { | |||||
return textList.length == 0 ? [''] : textList; | 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 | |||||
}; | |||||
} | |||||
} | } |
@@ -1102,11 +1102,20 @@ class HttpUtil { | |||||
showToast('请稍后再试'); | showToast('请稍后再试'); | ||||
return; | return; | ||||
} | } | ||||
data['content'] = base64Encode(File(msgModel.localFile).readAsBytesSync()); | |||||
data['content'] = | |||||
base64Encode(File(msgModel.localFile).readAsBytesSync()); | |||||
print('语音转换的文字: ${utf8.decode(msgModel.enTranslateContent)}'); | print('语音转换的文字: ${utf8.decode(msgModel.enTranslateContent)}'); | ||||
data['vcontent'] = base64Encode(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["tuserids"] = [UserData().basicInfo.userId]; | ||||
data['duration'] = | data['duration'] = | ||||
msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0; | msgModel.extraInfo != null ? msgModel.extraInfo ~/ 1000 : 0; | ||||