Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

139 righe
3.7 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/models/ChatMsg.dart';
  3. import 'package:chat/proto/all.pbserver.dart';
  4. class LastMessageModel {
  5. int channelType;
  6. int friendId;
  7. int sessionId;
  8. int fromId;
  9. int updateAt;
  10. ChatType type;
  11. List<int> msgContent;
  12. LastMessageModel(
  13. {this.sessionId,
  14. this.friendId,
  15. this.fromId,
  16. this.updateAt,
  17. this.type,
  18. this.msgContent,
  19. this.channelType = 0});
  20. LastMessageModel.fromChatMsg(MsgModel msgModel) {
  21. // print('### gg msgModel from:${msgModel.from} msgModel.friendId ${ msgModel.friendId} msgModel.sessionId ${msgModel.sessionId} msgtype ${msgModel.msgType}');
  22. sessionId = msgModel.sessionId;
  23. fromId = msgModel.from;
  24. if (msgModel.from == UserData().basicInfo.userId) {
  25. //自己
  26. friendId = msgModel.friendId;
  27. } else {
  28. friendId = msgModel.from;
  29. }
  30. ///翻译管家
  31. if(msgModel.channelType==ChatChannelType.Session.value && msgModel.msgType==ChatType.GroupChatNoticeType.value){
  32. friendId = msgModel.friendId;
  33. }
  34. channelType = msgModel.channelType;
  35. type = ChatType.valueOf(msgModel.msgType);
  36. msgContent = msgModel.msgContent;
  37. if (type == ChatType.TextChatType) {
  38. if (msgModel.translateContent != null &&
  39. msgModel.translateContent.length > 0) {
  40. msgContent = msgModel.translateContent;
  41. }
  42. }
  43. updateAt = msgModel.time;
  44. }
  45. updateWithMessage(MsgModel msgModel) {
  46. fromId = msgModel.from;
  47. type = ChatType.valueOf(msgModel.msgType);
  48. msgContent = msgModel.msgContent;
  49. if (type == ChatType.TextChatType) {
  50. if (msgModel.translateContent != null &&
  51. msgModel.translateContent.length > 0) {
  52. msgContent = msgModel.translateContent;
  53. }
  54. }
  55. updateAt = msgModel.time;
  56. }
  57. LastMessageModel.fromUnreadMsg(UserUnreadMsgNotice notice) {
  58. var lastMsg = notice.lastUnreadMsg;
  59. sessionId = notice.targetId;
  60. fromId = lastMsg.sendUserId;
  61. friendId = fromId;
  62. channelType = notice.channelType.value;
  63. print('未读$sessionId from:$fromId');
  64. type = lastMsg.cType;
  65. msgContent = lastMsg.contentBuff;
  66. if (lastMsg.hasTencentTranslate()) {
  67. msgContent = lastMsg.tencentTranslate;
  68. }
  69. ///解析红包消息
  70. if(lastMsg.cType== ChatType.RedWalletChatType){
  71. RedWallet wallet = RedWallet.fromBuffer(lastMsg.contentBuff);
  72. var myId = UserData().basicInfo.userId;
  73. if (myId == wallet.suId) {
  74. friendId = wallet.tuId;
  75. } else {
  76. friendId = wallet.suId;
  77. }
  78. }else if(lastMsg.cType == ChatType.GroupChatNoticeType){
  79. GroupChatNotice notice = GroupChatNotice.fromBuffer(lastMsg.contentBuff);
  80. var optId = notice.operatuId;
  81. print('### gourp add optid ${optId.id}');
  82. List<BaseUserInfo> optedIds = notice.operateduId;
  83. for(int k=0;k<optedIds.length;k++){
  84. print('### gourp add optedIds ${optedIds[k].id}');
  85. }
  86. }
  87. updateAt = lastMsg.sendTime.toInt();
  88. }
  89. updateWithUnreadMsg(UserUnreadMsgNotice notice) {
  90. var lastMsg = notice.lastUnreadMsg;
  91. fromId = lastMsg.sendUserId;
  92. type = lastMsg.cType;
  93. msgContent = lastMsg.contentBuff;
  94. if (lastMsg.hasTencentTranslate()) {
  95. msgContent = lastMsg.tencentTranslate;
  96. }
  97. ///解析红包消息
  98. if(lastMsg.cType== ChatType.RedWalletChatType){
  99. RedWallet wallet = RedWallet.fromBuffer(lastMsg.contentBuff);
  100. var myId = UserData().basicInfo.userId;
  101. if (myId == wallet.suId) {
  102. friendId = wallet.tuId;
  103. } else {
  104. friendId = wallet.suId;
  105. }
  106. }
  107. updateAt = lastMsg.sendTime.toInt();
  108. }
  109. }