Nessuna descrizione

MessageModelManager.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /************************************************************
  2. * * EaseMob CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of EaseMob Technologies.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from EaseMob Technologies.
  11. */
  12. #import "MessageModelManager.h"
  13. #import "ConvertToCommonEmoticonsHelper.h"
  14. #import "MessageModel.h"
  15. @implementation MessageModelManager
  16. + (id)modelWithMessage:(EMMessage *)message
  17. {
  18. EMMessageBody *messageBody = message.body;
  19. NSString *login = [EMClient sharedClient].currentUsername;
  20. BOOL isSender = [login isEqualToString:message.from] ? YES : NO;
  21. MessageModel *model = [[MessageModel alloc] init];
  22. model.isRead = message.isRead;
  23. model.messageBody = messageBody;
  24. model.message = message;
  25. model.type = messageBody.type;
  26. model.messageId = message.messageId;
  27. model.isSender = isSender;
  28. model.isPlaying = NO;
  29. model.isChatGroup = (message.chatType == EMChatTypeGroupChat);
  30. if (model.isChatGroup) {
  31. model.username = message.from;
  32. }
  33. else{
  34. model.username = message.from;
  35. }
  36. switch (messageBody.type) {
  37. case EMMessageBodyTypeText:
  38. {
  39. // 表情映射。
  40. NSString *didReceiveText = [ConvertToCommonEmoticonsHelper
  41. convertToSystemEmoticons:((EMTextMessageBody *)messageBody).text];
  42. model.content = didReceiveText;
  43. }
  44. break;
  45. case EMMessageBodyTypeImage:
  46. {
  47. EMImageMessageBody *imgMessageBody = (EMImageMessageBody*)messageBody;
  48. model.thumbnailSize = imgMessageBody.thumbnailSize;
  49. model.size = imgMessageBody.size;
  50. model.localPath = imgMessageBody.localPath;
  51. model.thumbnailImage = [UIImage imageWithContentsOfFile:imgMessageBody.thumbnailLocalPath];
  52. if (isSender)
  53. {
  54. model.image = [UIImage imageWithContentsOfFile:imgMessageBody.thumbnailLocalPath];
  55. }else {
  56. model.imageRemoteURL = [NSURL URLWithString:imgMessageBody.remotePath];
  57. }
  58. }
  59. break;
  60. case EMMessageBodyTypeLocation:
  61. {
  62. model.address = ((EMLocationMessageBody *)messageBody).address;
  63. model.latitude = ((EMLocationMessageBody *)messageBody).latitude;
  64. model.longitude = ((EMLocationMessageBody *)messageBody).longitude;
  65. }
  66. break;
  67. case EMMessageBodyTypeVoice:
  68. {
  69. // model.time = ((EMVoiceMessageBody *)messageBody).duration;
  70. // model.chatVoice = (EMChatVoice *)((EMVoiceMessageBody *)messageBody).chatObject;
  71. // if (message.ext) {
  72. // NSDictionary *dict = message.ext;
  73. // BOOL isPlayed = [[dict objectForKey:@"isPlayed"] boolValue];
  74. // model.isPlayed = isPlayed;
  75. // }else {
  76. // NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@NO,@"isPlayed", nil];
  77. // message.ext = dict;
  78. // [[EaseMob sharedInstance].chatManager insertMessageToDB:message];
  79. // }
  80. // // 本地音频路径
  81. // model.localPath = ((EMVoiceMessageBody *)messageBody).localPath;
  82. // model.remotePath = ((EMVoiceMessageBody *)messageBody).remotePath;
  83. }
  84. break;
  85. case EMMessageBodyTypeVideo:{
  86. // EMVideoMessageBody *videoMessageBody = (EMVideoMessageBody*)messageBody;
  87. // model.thumbnailSize = videoMessageBody.size;
  88. // model.size = videoMessageBody.size;
  89. // model.localPath = videoMessageBody.thumbnailLocalPath;
  90. // model.thumbnailImage = [UIImage imageWithContentsOfFile:videoMessageBody.thumbnailLocalPath];
  91. // model.image = model.thumbnailImage;
  92. }
  93. break;
  94. default:
  95. break;
  96. }
  97. return model;
  98. }
  99. @end