JCHATMessageTableViewCell.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. //
  2. // JCHATMessageTableViewCell.m
  3. // JChat
  4. //
  5. // Created by HuminiOS on 15/7/13.
  6. // Copyright (c) 2015年 HXHG. All rights reserved.
  7. //
  8. #import "JCHATMessageTableViewCell.h"
  9. #import "JChatConstants.h"
  10. #import "ChatBubbleLayer.h"
  11. #import "AppDelegate.h"
  12. #import "JCHATSendMsgManager.h"
  13. #import "OutsideGoodsDetailVC.h"
  14. #import "CommodityDetailVC.h"
  15. //#define ReceivedBubbleColor UIColorFromRGB(0xd3fab4)
  16. //#define sendedBubbleColor [UIColor whiteColor]
  17. #define messageStatusBtnFrame [_model.message isReceived]?CGRectMake(_voiceTimeLabel.frame.origin.x + 5, _messageContent.frame.size.height/2 - 8, 17, 15):CGRectMake(_voiceTimeLabel.frame.origin.x - 20, _messageContent.frame.size.height/2 - 8, 17, 15)
  18. #define messagePercentLabelFrame [_model.message isReceived]?CGPointMake(_messageContent.frame.size.width/2 + crossgrap/2, _messageContent.frame.size.height/2):CGPointMake(_messageContent.frame.size.width/2 - crossgrap/2, _messageContent.frame.size.height/2)
  19. #define kVoiceTimeLabelFrame [_model.message isReceived]?CGRectMake(_messageContent.frame.origin.x + _messageContent.frame.size.width + 10, _messageContent.frame.size.height/2 - 8, 35, 17):CGRectMake(_messageContent.frame.origin.x - 45, _messageContent.frame.size.height/2 - 8, 35, 17)
  20. #define kVoiceTimeLabelHidenFrame [_model.message isReceived]?CGRectMake(_messageContent.frame.origin.x + _messageContent.frame.size.width + 5, _messageContent.frame.size.height/2 - 8, 35, 17):CGRectMake(_messageContent.frame.origin.x, _messageContent.frame.size.height/2 - 8, 35, 17)
  21. static NSInteger const headHeight = 46;
  22. static NSInteger const gapWidth = 5;
  23. static NSInteger const chatBgViewHeight = 50;
  24. static NSInteger const readViewRadius = 4;
  25. @implementation JCHATMessageTableViewCell
  26. - (id)initWithStyle:(UITableViewCellStyle)style
  27. reuseIdentifier:(NSString *)reuseIdentifier {
  28. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  29. if (self) {
  30. self.selectionStyle = UITableViewCellSelectionStyleNone;
  31. self.backgroundColor = [UIColor clearColor];
  32. _headView = [UIImageView new];
  33. [_headView setImage:[UIImage imageNamed:@"headDefalt.png"]];
  34. _headView.layer.cornerRadius = headHeight/2;
  35. _headView.layer.masksToBounds = YES;
  36. _headView.contentMode = UIViewContentModeScaleAspectFill;
  37. _messageContent = [JCHATMessageContentView new];
  38. [self.contentView addSubview:_headView];
  39. [self.contentView addSubview:_messageContent];
  40. _readView = [UIView new];
  41. [_readView setBackgroundColor:[UIColor redColor]];
  42. _readView.layer.cornerRadius = readViewRadius;
  43. [self.contentView addSubview:self.readView];
  44. self.continuePlayer = NO;
  45. self.sendFailView = [UIImageView new];
  46. [self.sendFailView setUserInteractionEnabled:YES];
  47. [self.sendFailView setImage:[UIImage imageNamed:@"fail05"]];
  48. [self.contentView addSubview:self.sendFailView];
  49. _circleView = [UIActivityIndicatorView new];
  50. [_circleView setBackgroundColor:[UIColor clearColor]];
  51. [_circleView setHidden:NO];
  52. _circleView.hidesWhenStopped = YES;
  53. [self.contentView addSubview:_circleView];
  54. _voiceTimeLabel = [UILabel new];
  55. _voiceTimeLabel.backgroundColor = [UIColor clearColor];
  56. _voiceTimeLabel.textColor = RGB_COLOR(@"#646464", 1);
  57. _voiceTimeLabel.font = [UIFont systemFontOfSize:18];
  58. [self.contentView addSubview:_voiceTimeLabel];
  59. _percentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, chatBgViewHeight, chatBgViewHeight)];
  60. _percentLabel.hidden = NO;
  61. _percentLabel.font =[UIFont systemFontOfSize:18];
  62. _percentLabel.textAlignment=NSTextAlignmentCenter;
  63. _percentLabel.textColor=[UIColor whiteColor];
  64. [_messageContent addSubview:_percentLabel];
  65. [_percentLabel setBackgroundColor:[UIColor clearColor]];
  66. CommodityDetailModel *commodityModel ;
  67. _goodsView =[[ShareGoodView alloc]initWithFrame:CGRectMake(0, 0, _window_width*0.6 + 10, _window_width*0.6 + 10) andGoodsData:commodityModel];
  68. _goodsView.hidden = YES;
  69. [self.contentView addSubview:_goodsView];
  70. [self addGestureForAllView];
  71. }
  72. return self;
  73. }
  74. //rk20201030
  75. - (void)setPassRKTextView:(JCHATMessageTextView *)passRKTextView {
  76. _passRKTextView = passRKTextView;
  77. _messageContent.passRKTextView = _passRKTextView;
  78. }
  79. - (void)addGestureForAllView {
  80. UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self
  81. action:@selector(tapContent:)];
  82. [_messageContent addGestureRecognizer:gesture];
  83. [_messageContent setUserInteractionEnabled:YES];
  84. UITapGestureRecognizer *tapHeadGesture =[[UITapGestureRecognizer alloc] initWithTarget:self
  85. action:@selector(pushPersonInfoCtlClick)];
  86. [_headView addGestureRecognizer:tapHeadGesture];
  87. [_headView setUserInteractionEnabled:YES];
  88. UITapGestureRecognizer *tapFailViewGesture =[[UITapGestureRecognizer alloc] initWithTarget:self
  89. action:@selector(reSendMessage)];
  90. [_sendFailView addGestureRecognizer:tapFailViewGesture];
  91. [_sendFailView setUserInteractionEnabled:YES];
  92. UITapGestureRecognizer *goodsGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goodsTap)];
  93. [_goodsView addGestureRecognizer:goodsGesture];
  94. [_goodsView setUserInteractionEnabled:YES];
  95. }
  96. -(void)goodsTap{
  97. if ([YBYoungManager shareInstance].youngSwitch == 1) {
  98. [MBProgressHUD showError:YZMsg(@"青少年模式下不支持该功能")];
  99. return;
  100. }
  101. NSString *goodsID = [_model.message.content.extras valueForKey:@"goodsid"];
  102. [PublicObj checkGoodsExistenceWithID:goodsID Existence:^(int code, NSString *msg) {
  103. if (code == 0) {
  104. if ([_commodityModel.type isEqual:@"1"]) {
  105. OutsideGoodsDetailVC *detail = [[OutsideGoodsDetailVC alloc]init];
  106. detail.goodsID = minstr(_commodityModel.goodsid);
  107. detail.liveUid = @"0";
  108. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:detail animated:YES];
  109. }else{
  110. CommodityDetailVC *detail = [[CommodityDetailVC alloc]init];
  111. detail.goodsID = minstr(_commodityModel.goodsid);
  112. detail.liveUid = @"0";
  113. detail.shareuid = _model.uidStr;
  114. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:detail animated:YES];
  115. }
  116. }else{
  117. [MBProgressHUD showError:msg];
  118. }
  119. }];
  120. }
  121. - (void)setCellData:(JCHATChatModel *)model
  122. delegate:(id <playVoiceDelegate>)delegate
  123. indexPath:(NSIndexPath *)indexPath{
  124. _model = model;
  125. _indexPath = indexPath;
  126. _delegate = delegate;
  127. //极光的头像
  128. //[self reloadAvatarImage];
  129. //业务服务器头像
  130. [_headView sd_setImageWithURL:[NSURL URLWithString:_model.uiconStr]];
  131. if ([_model.message.flag isEqualToNumber:@1] || ![_model.message isReceived]) {
  132. [self.readView setHidden:YES];
  133. } else {
  134. [self.readView setHidden:NO];
  135. }
  136. [self updateFrameWithContentFrame:model.contentSize];
  137. [self layoutAllView];
  138. }
  139. - (void)layoutAllView {
  140. if (_model.message.status == kJMSGMessageStatusSending
  141. || _model.message.status == kJMSGMessageStatusSendDraft
  142. || _model.message.status == kJMSGMessageStatusReceiving) {
  143. [_circleView startAnimating];
  144. [self.sendFailView setHidden:YES];
  145. [self.percentLabel setHidden:NO];
  146. if (_model.message.contentType == kJMSGContentTypeImage) {
  147. _messageContent.alpha = 0.5;
  148. } else {
  149. _messageContent.alpha = 1;
  150. }
  151. [self addUpLoadHandler];
  152. } else if (_model.message.status == kJMSGMessageStatusSendFailed
  153. || _model.message.status == kJMSGMessageStatusSendUploadFailed
  154. || _model.message.status == kJMSGMessageStatusReceiveDownloadFailed) {
  155. [_circleView stopAnimating];
  156. if ([_model.message isReceived]) {
  157. [self.sendFailView setHidden:YES];
  158. } else {
  159. [self.sendFailView setHidden:NO];
  160. }
  161. _messageContent.alpha = 1;
  162. } else {
  163. _messageContent.alpha = 1;
  164. [_circleView stopAnimating];
  165. [self.sendFailView setHidden:YES];
  166. [self.percentLabel setHidden:YES];
  167. }
  168. if (_model.message.contentType != kJMSGContentTypeVoice) {
  169. _readView.hidden = YES;
  170. }
  171. _messageContent.hidden = NO;
  172. _goodsView.hidden = YES;
  173. switch (_model.message.contentType) {
  174. case kJMSGContentTypeUnknown:
  175. _messageContent.backgroundColor = [UIColor redColor];
  176. _messageContent.textContent.text = st_receiveUnknowMessageDes;
  177. break;
  178. case kJMSGContentTypeText:
  179. if (_model.message.content.extras && [[_model.message.content.extras allKeys]containsObject:@"goodsid"]) {
  180. _messageContent.textContent.hidden = YES;
  181. _messageContent.hidden = YES;
  182. _goodsView.hidden = NO;
  183. [self getGoodInfo:[_model.message.content.extras valueForKey:@"goodsid"]];
  184. }else{
  185. _percentLabel.hidden = YES;
  186. _readView.hidden = YES;
  187. _voiceTimeLabel.hidden = YES;
  188. }
  189. break;
  190. case kJMSGContentTypeImage:
  191. _readView.hidden = YES;
  192. _voiceTimeLabel.hidden = YES;
  193. break;
  194. case kJMSGContentTypeLocation:
  195. case kJMSGContentTypeFile:
  196. _readView.hidden = YES;
  197. _voiceTimeLabel.hidden = YES;
  198. break;
  199. case kJMSGContentTypeVoice:
  200. _percentLabel.hidden = YES;
  201. _voiceTimeLabel.hidden = NO;
  202. _voiceTimeLabel.text = [NSString stringWithFormat:@"%@''",((JMSGVoiceContent *)_model.message.content).duration];
  203. if (_model.message.isReceived) {
  204. _voiceTimeLabel.textAlignment = NSTextAlignmentLeft;
  205. } else {
  206. _voiceTimeLabel.textAlignment = NSTextAlignmentRight;
  207. }
  208. break;
  209. case kJMSGContentTypeCustom:
  210. {
  211. NSLog(@"sssssssss");
  212. }
  213. break;
  214. case kJMSGContentTypeEventNotification:
  215. break;
  216. default:
  217. break;
  218. }
  219. }
  220. -(void)getGoodInfo:(NSString *)goodsID{
  221. NSDictionary *dic = @{
  222. @"uid":[Config getOwnID],
  223. @"token":[Config getOwnToken],
  224. @"goodsid":goodsID,
  225. };
  226. [YBNetworking postWithUrl:@"Shop.getGoodsInfo" Dic:dic Suc:^(int code, id info, NSString *msg) {
  227. if (code == 0) {
  228. _commodityModel = [CommodityDetailModel modelWithDic:[info firstObject]];
  229. // _messageContent.hidden = YES;
  230. // _goodsView.hidden = NO;
  231. _goodsView.goodsModel = _commodityModel;
  232. }else{
  233. [MBProgressHUD showError:msg];
  234. }
  235. } Fail:^(id fail) {
  236. }];
  237. }
  238. - (void)addUpLoadHandler {
  239. if (_model.message.contentType != kJMSGContentTypeImage) {
  240. return;
  241. }
  242. __weak __typeof(self)weakSelfUpload = self;
  243. ((JMSGImageContent *)_model.message.content).uploadHandler = ^(float percent, NSString *msgId) {
  244. dispatch_async(dispatch_get_main_queue(), ^{
  245. __strong __typeof(weakSelfUpload)strongSelfUpload = weakSelfUpload;
  246. if ([strongSelfUpload.model.message.msgId isEqualToString:msgId]) {
  247. NSString *percentString = [NSString stringWithFormat:@"%d%%", (int)(percent * 100)];
  248. strongSelfUpload.percentLabel.text = percentString;
  249. }
  250. });
  251. };
  252. }
  253. - (void)updateFrameWithContentFrame:(CGSize)contentSize {
  254. BOOL isRecive = [_model.message isReceived];
  255. if (isRecive) {
  256. [_headView setFrame:CGRectMake(gapWidth, 0, headHeight, headHeight)];
  257. //[_messageContent setBubbleSide:isRecive];
  258. [_messageContent setFrame:CGRectMake(headHeight + 2*gapWidth, 0, contentSize.width, contentSize.height)];
  259. [_readView setFrame:CGRectMake(_messageContent.frame.origin.x + _messageContent.frame.size.width + 10, 5, 2 * readViewRadius, 2 * readViewRadius)];
  260. _goodsView.frame = CGRectMake(_headView.right + 5, 0, _window_width*0.6 + 10, _window_width*0.6 + 10);
  261. } else {
  262. [_headView setFrame:CGRectMake(kApplicationWidth - headHeight - gapWidth, 0, headHeight, headHeight)];//头像位置
  263. //[_messageContent setBubbleSide:isRecive];
  264. [_messageContent setFrame:CGRectMake(kApplicationWidth - headHeight - 2*gapWidth - contentSize.width, 0, contentSize.width, contentSize.height)];
  265. [_readView setFrame:CGRectMake(_messageContent.frame.origin.x - 10, 5, 8, 8)];
  266. _goodsView.frame =CGRectMake(_window_width-headHeight-(_window_width*0.6 + 10)*0.8 - gapWidth, 0, _window_width*0.6 + 10, _window_width*0.6 + 10);
  267. }
  268. __weak __typeof__(self) weakSelf = self;
  269. [_messageContent setMessageContentWith:_model.message handler:^(NSUInteger messageMediaDataLength) {
  270. __strong __typeof__(weakSelf) strongSelf = weakSelf;
  271. BOOL isShouldRefresh = NO;
  272. if (weakSelf.model.messageMediaDataLength != messageMediaDataLength) {
  273. isShouldRefresh = YES;
  274. weakSelf.model.messageMediaDataLength = messageMediaDataLength;
  275. if (strongSelf.messageTableViewCellRefreshMediaMessage) {
  276. strongSelf.messageTableViewCellRefreshMediaMessage(strongSelf.model,isShouldRefresh);
  277. }
  278. [strongSelf layoutAllView];
  279. }
  280. }];
  281. [_voiceTimeLabel setFrame:kVoiceTimeLabelFrame];
  282. if (_model.message.contentType != kJMSGContentTypeVoice) {
  283. _voiceTimeLabel.frame = kVoiceTimeLabelHidenFrame;
  284. }
  285. [_circleView setFrame:messageStatusBtnFrame];
  286. [_sendFailView setFrame:messageStatusBtnFrame];
  287. [_percentLabel setCenter:messagePercentLabelFrame];
  288. }
  289. - (void)tapContent:(UIGestureRecognizer *)gesture {
  290. if (_model.message.contentType == kJMSGContentTypeVoice) {
  291. [self playVoice];
  292. }
  293. if (_model.message.contentType == kJMSGContentTypeImage) {
  294. if (self.model.message.status == kJMSGMessageStatusReceiveDownloadFailed) {
  295. NSLog(@"正在下载缩略图");
  296. JPIMLog(@"Action");
  297. [_circleView startAnimating];
  298. } else {
  299. if (self.delegate && [(id<PictureDelegate>)self.delegate respondsToSelector:@selector(tapPicture:tapView:tableViewCell:)]) {
  300. [(id<PictureDelegate>)self.delegate tapPicture:_indexPath tapView:(UIImageView *)gesture.view tableViewCell:self];
  301. }
  302. }
  303. }
  304. }
  305. #pragma -mark gesture
  306. - (void)pushPersonInfoCtlClick {
  307. if (self.delegate && [self.delegate respondsToSelector:@selector(selectHeadView:)]) {
  308. [self.delegate selectHeadView:self.model];
  309. }
  310. }
  311. - (void)reSendMessage {//重发消息
  312. YBWeakSelf;
  313. NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),@"msg":YZMsg(@"是否重新发送消息"),@"left":YZMsg(@"取消"),@"right":YZMsg(@"确定")};
  314. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  315. if (eventType == 1) {
  316. [weakSelf clickSureBtn];
  317. }
  318. }];
  319. }
  320. -(void)clickSureBtn {
  321. [self.sendFailView setHidden:YES];
  322. [self.circleView setHidden:NO];
  323. [self.circleView startAnimating];
  324. if (_model.message.contentType == kJMSGContentTypeImage) {
  325. _messageContent.alpha = 0.5;
  326. } else {
  327. _messageContent.alpha = 1;
  328. }
  329. __weak typeof(self)weakSelf = self;
  330. if (_model.message.contentType == kJMSGContentTypeImage) {
  331. JMSGImageContent *imgContent = ((JMSGImageContent *)_model.message.content);
  332. imgContent.uploadHandler = ^(float percent, NSString *msgID){
  333. __strong __typeof(weakSelf)strongSelf = weakSelf;
  334. if ([strongSelf.model.message.msgId isEqualToString:msgID]) {
  335. dispatch_async(dispatch_get_main_queue(), ^{
  336. strongSelf.percentLabel.text = [NSString stringWithFormat:@"%d%%",(int)(percent*100)];
  337. });
  338. }
  339. };
  340. [[JCHATSendMsgManager ins] addMessage:weakSelf.model.message withConversation:_conversation];
  341. } else {
  342. [weakSelf.conversation sendMessage:weakSelf.model.message];
  343. [weakSelf layoutAllView];
  344. }
  345. }
  346. #pragma mark --连续播放语音
  347. - (void)playVoice {
  348. DDLogDebug(@"Action - playVoice");
  349. __block NSString *status = nil;
  350. self.continuePlayer = NO;
  351. if ([(id<playVoiceDelegate>)(self.delegate) respondsToSelector:@selector(getContinuePlay:indexPath:)]) {
  352. [(id<playVoiceDelegate>)(self.delegate) getContinuePlay:self indexPath:self.indexPath];
  353. }
  354. [self.readView setHidden:YES];
  355. if (![_model.message.flag isEqual: @1]) {
  356. [_model.message updateFlag:@1];
  357. }
  358. [((JMSGVoiceContent *)_model.message.content) voiceData:^(NSData *data, NSString *objectId, NSError *error) {
  359. if (error == nil) {
  360. if (data != nil) {
  361. status = YZMsg(@"下载语音成功");
  362. self.index = 0;
  363. if (!_isPlaying) {
  364. if ([[JCHATAudioPlayerHelper shareInstance] isPlaying]) {
  365. [[JCHATAudioPlayerHelper shareInstance] stopAudio];
  366. [[JCHATAudioPlayerHelper shareInstance] setDelegate:nil];
  367. }
  368. [[JCHATAudioPlayerHelper shareInstance] setDelegate:(id) self];
  369. _isPlaying = YES;
  370. } else {
  371. _isPlaying = NO;
  372. self.continuePlayer = NO;
  373. [[JCHATAudioPlayerHelper shareInstance] stopAudio];
  374. [[JCHATAudioPlayerHelper shareInstance] setDelegate:nil];
  375. }
  376. [[JCHATAudioPlayerHelper shareInstance] managerAudioWithData:data toplay:YES];
  377. [self changeVoiceImage];
  378. }
  379. } else {
  380. DDLogDebug(@"Action voiceData");
  381. [self AlertInCurrentViewWithString:YZMsg(@"下载语音数据失败")];
  382. status = @"获取消息失败。。。";
  383. }
  384. }];
  385. return;
  386. }
  387. - (void)AlertInCurrentViewWithString:(NSString *)string {
  388. AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
  389. //[MBProgressHUD showMessage:string view:appDelegate.window];
  390. [MBProgressHUD showMessage:string toView:appDelegate.window];
  391. }
  392. - (void)changeVoiceImage {
  393. if (!_isPlaying) {
  394. return;
  395. }
  396. NSString *voiceImagePreStr = @"";
  397. if ([_model.message isReceived]) {
  398. voiceImagePreStr = @"ReceiverVoiceNodePlaying00";
  399. } else {
  400. voiceImagePreStr = @"SenderVoiceNodePlaying00";
  401. }
  402. _messageContent.voiceConent.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%zd", voiceImagePreStr, self.index % 3]];
  403. if (_isPlaying) {
  404. self.index++;
  405. [self performSelector:@selector(changeVoiceImage) withObject:nil afterDelay:0.25];
  406. }
  407. }
  408. - (void)prepare {
  409. [(id<playVoiceDelegate>)self.delegate successionalPlayVoice:self indexPath:self.indexPath];
  410. }
  411. #pragma mark ---播放完成后
  412. - (void)didAudioPlayerStopPlay:(AVAudioPlayer *)audioPlayer {
  413. [[JCHATAudioPlayerHelper shareInstance] setDelegate:nil];
  414. _isPlaying = NO;
  415. self.index = 0;
  416. if ([_model.message isReceived]) {
  417. [_messageContent.voiceConent setImage:[UIImage imageNamed:@"ReceiverVoiceNodePlaying.png"]];
  418. } else {
  419. [_messageContent.voiceConent setImage:[UIImage imageNamed:@"SenderVoiceNodePlaying.png"]];
  420. }
  421. if (self.continuePlayer) {
  422. self.continuePlayer = NO;
  423. if ([self.delegate respondsToSelector:@selector(successionalPlayVoice:indexPath:)]) {
  424. [self performSelector:@selector(prepare) withObject:nil afterDelay:0.5];
  425. }
  426. }
  427. }
  428. #pragma mark --发送消息响应
  429. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  430. [super setSelected:selected animated:animated];
  431. // Configure the view for the selected state
  432. }
  433. #pragma mark - 极光IM存储的头像(业务服务器未使用)
  434. - (void)reloadAvatarImage {
  435. kWEAKSELF
  436. [_model.message.fromUser thumbAvatarData:^(NSData *data, NSString *objectId, NSError *error) {
  437. kSTRONGSELF
  438. if (error == nil) {
  439. JMSGUser *user = ((JMSGUser *)strongSelf.model.message.fromUser);
  440. if ([objectId isEqualToString:user.username]) {
  441. if (data != nil) {
  442. _model.isDefaultAvatar = NO;
  443. _model.avatarDataLength = data.length;
  444. [strongSelf.headView setImage:[UIImage imageWithData:data]];
  445. } else {
  446. [strongSelf.headView setImage:[UIImage imageNamed:@"headDefalt"]];
  447. }
  448. }
  449. } else {
  450. DDLogDebug(@"Action -- get thumbavatar fail");
  451. [strongSelf.headView setImage:[UIImage imageNamed:@"headDefalt"]];
  452. }
  453. }];
  454. }
  455. @end