Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

133 行
3.6 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. channelType = msgModel.channelType;
  31. type = ChatType.valueOf(msgModel.msgType);
  32. msgContent = msgModel.msgContent;
  33. if (type == ChatType.TextChatType) {
  34. if (msgModel.translateContent != null &&
  35. msgModel.translateContent.length > 0) {
  36. msgContent = msgModel.translateContent;
  37. }
  38. }
  39. updateAt = msgModel.time;
  40. }
  41. updateWithMessage(MsgModel msgModel) {
  42. fromId = msgModel.from;
  43. type = ChatType.valueOf(msgModel.msgType);
  44. msgContent = msgModel.msgContent;
  45. if (type == ChatType.TextChatType) {
  46. if (msgModel.translateContent != null &&
  47. msgModel.translateContent.length > 0) {
  48. msgContent = msgModel.translateContent;
  49. }
  50. }
  51. updateAt = msgModel.time;
  52. }
  53. LastMessageModel.fromUnreadMsg(UserUnreadMsgNotice notice) {
  54. var lastMsg = notice.lastUnreadMsg;
  55. sessionId = notice.targetId;
  56. fromId = lastMsg.sendUserId;
  57. friendId = fromId;
  58. channelType = notice.channelType.value;
  59. print('未读$sessionId from:$fromId');
  60. type = lastMsg.cType;
  61. msgContent = lastMsg.contentBuff;
  62. if (lastMsg.hasTencentTranslate()) {
  63. msgContent = lastMsg.tencentTranslate;
  64. }
  65. ///解析红包消息
  66. if(lastMsg.cType== ChatType.RedWalletChatType){
  67. RedWallet wallet = RedWallet.fromBuffer(lastMsg.contentBuff);
  68. var myId = UserData().basicInfo.userId;
  69. if (myId == wallet.suId) {
  70. friendId = wallet.tuId;
  71. } else {
  72. friendId = wallet.suId;
  73. }
  74. }else if(lastMsg.cType == ChatType.GroupChatNoticeType){
  75. GroupChatNotice notice = GroupChatNotice.fromBuffer(lastMsg.contentBuff);
  76. var optId = notice.operatuId;
  77. print('### gourp add optid ${optId.id}');
  78. List<BaseUserInfo> optedIds = notice.operateduId;
  79. for(int k=0;k<optedIds.length;k++){
  80. print('### gourp add optedIds ${optedIds[k].id}');
  81. }
  82. }
  83. updateAt = lastMsg.sendTime.toInt();
  84. }
  85. updateWithUnreadMsg(UserUnreadMsgNotice notice) {
  86. var lastMsg = notice.lastUnreadMsg;
  87. fromId = lastMsg.sendUserId;
  88. type = lastMsg.cType;
  89. msgContent = lastMsg.contentBuff;
  90. if (lastMsg.hasTencentTranslate()) {
  91. msgContent = lastMsg.tencentTranslate;
  92. }
  93. ///解析红包消息
  94. if(lastMsg.cType== ChatType.RedWalletChatType){
  95. RedWallet wallet = RedWallet.fromBuffer(lastMsg.contentBuff);
  96. var myId = UserData().basicInfo.userId;
  97. if (myId == wallet.suId) {
  98. friendId = wallet.tuId;
  99. } else {
  100. friendId = wallet.suId;
  101. }
  102. }
  103. updateAt = lastMsg.sendTime.toInt();
  104. }
  105. }