YOUPAILZLiveChatMessageCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. //
  2. // YOUPAILZLiveChatMessageCell.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/11.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveChatMessageCell.h"
  9. #import "NIMKitUtil.h"
  10. #import "YOUPAILCGiftAttachment.h"
  11. #import "YOUPAILZGuardAttachment.h"
  12. #import "YOUPAILZLiveFollowAttachment.h"
  13. #import "YOUPAILZLiveManageAttachment.h"
  14. #import "SNKNinePatchImageView.h"
  15. #import "YOUPAILZLiveManagerListUtils.h"
  16. #import "YOUPAILZLevelView.h"
  17. #import "YOUPAIChatRoomManagerTagView.h"
  18. #import "YOUPAINIMInputEmoticonParser.h"
  19. #import "YOUPAINIMInputEmoticonManager.h"
  20. #import "UIImage+NIMKit.h"
  21. @interface YOUPAILZLiveChatMessageCell ()
  22. @property (nonatomic,weak) SNKNinePatchImageView *youpaipbubbleImgV;
  23. @property (nonatomic, weak) UILabel *youpaipcontentL;
  24. //@property (nonatomic, weak) UIImageView *youpaipmanageImgV;
  25. @property (nonatomic, weak) UIImageView *youpaipvipImgV;
  26. @property (nonatomic, weak) UIImageView *youpaipboardImgV;
  27. @property (nonatomic, weak) UIImageView *youpaipbadgeImgV;
  28. @property (nonatomic, weak) YOUPAILZLevelView *youpaiplevelView;
  29. @property (nonatomic, weak) YOUPAIChatRoomManagerTagView *youpaipmanagerTagView;
  30. @property (nonatomic, strong) NSIndexPath *youpaipindexPath;
  31. @property (nonatomic, assign) NSInteger youpaiptagCount;
  32. @end
  33. @implementation YOUPAILZLiveChatMessageCell
  34. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  35. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  36. self.transform = CGAffineTransformMakeScale(1, -1);
  37. self.backgroundColor = [UIColor clearColor];
  38. [self youpaifinitUI];
  39. }
  40. return self;
  41. }
  42. - (void)youpaifinitUI{
  43. SNKNinePatchImageView *youpaipbubbleImgV = [SNKNinePatchImageView new];
  44. // youpaipbubbleImgV.imageScale = 2;
  45. youpaipbubbleImgV.userInteractionEnabled = YES;
  46. [self.contentView addSubview:youpaipbubbleImgV];
  47. self.youpaipbubbleImgV = youpaipbubbleImgV;
  48. UITapGestureRecognizer* tapGes =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftapOneAct)];
  49. tapGes.numberOfTapsRequired = 1;
  50. [youpaipbubbleImgV addGestureRecognizer:tapGes];
  51. [youpaipbubbleImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.offset(0.0f);
  53. make.top.offset(6.0f);
  54. make.bottom.offset(0.0f);
  55. make.height.greaterThanOrEqualTo(38.0f);
  56. }];
  57. UILabel *contentL = [[UILabel alloc] init];
  58. contentL.textColor = [UIColor whiteColor];
  59. contentL.font = LCFont12;
  60. contentL.numberOfLines = 0;
  61. [self.contentView addSubview:contentL];
  62. self.youpaipcontentL = contentL;
  63. contentL.userInteractionEnabled = NO;
  64. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.width.lessThanOrEqualTo(226.0f);
  66. }];
  67. [youpaipbubbleImgV addConstraintsWithPaddingView:contentL];
  68. YOUPAIChatRoomManagerTagView *youpaipmanagerTagView = [[YOUPAIChatRoomManagerTagView alloc] init];
  69. [self.youpaipcontentL addSubview:youpaipmanagerTagView];
  70. self.youpaipmanagerTagView = youpaipmanagerTagView;
  71. UIImageView *youpaipvipImgV = [[UIImageView alloc] init];
  72. [self.youpaipcontentL addSubview:youpaipvipImgV];
  73. self.youpaipvipImgV = youpaipvipImgV;
  74. UIImageView *youpaipboardImgV = [[UIImageView alloc] init];
  75. [self.youpaipcontentL addSubview:youpaipboardImgV];
  76. self.youpaipboardImgV = youpaipboardImgV;
  77. UIImageView *youpaipbadgeImgV = [[UIImageView alloc] init];
  78. [self.youpaipcontentL addSubview:youpaipbadgeImgV];
  79. self.youpaipbadgeImgV = youpaipbadgeImgV;
  80. YOUPAILZLevelView *youpaiplevelView = [[YOUPAILZLevelView alloc] init];
  81. [self.youpaipcontentL addSubview:youpaiplevelView];
  82. self.youpaiplevelView = youpaiplevelView;
  83. }
  84. - (void)youpaifreloadWithModel:(NIMMessage *)message font:(nonnull UIFont *)font indexPath:(nonnull NSIndexPath *)indexPath{
  85. self.youpaipindexPath = indexPath;
  86. self.youpaipcontentL.font = font;
  87. NSString *giftImgStr = @"";
  88. self.userInteractionEnabled = YES;
  89. if(message.from == nil){
  90. self.youpaipcontentL.textColor = HexColorFromRGB(0xFF3065);
  91. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:message.text];
  92. attributedString1 = [self youpaifhandleUserLevelWithFrom:message.from attributedStr:attributedString1 sendGiftHide:1];
  93. self.youpaipcontentL.attributedText = attributedString1;
  94. self.userInteractionEnabled = NO;
  95. }else if (message.messageType == NIMMessageTypeText) {
  96. self.youpaipcontentL.textColor = [UIColor whiteColor];
  97. NSString *nick = [NIMKitUtil showNick:message.from inMessage:message];
  98. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@:%@",nick,message.text]];
  99. attributedString1 = [self youpaifhandleUserLevelWithFrom:message.from attributedStr:attributedString1 sendGiftHide:0];
  100. [attributedString1 addAttributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xFFDD8D)} range:NSMakeRange(self.youpaiptagCount, nick.length + 2)];
  101. self.youpaipcontentL.attributedText = attributedString1;
  102. }else if (message.session.sessionType == NIMSessionTypeChatroom
  103. && message.messageType == NIMMessageTypeNotification){
  104. NIMNotificationObject *object = message.messageObject;
  105. NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)object.content;
  106. NSMutableArray *targetNicks = [[NSMutableArray alloc] init];
  107. for (NIMChatroomNotificationMember *memebr in content.targets) {
  108. [targetNicks addObject:memebr.nick];
  109. message.from = memebr.userId;
  110. }
  111. NSString *text = @"";
  112. NSString *targetText = [targetNicks componentsJoinedByString:@","];
  113. switch (content.eventType) {
  114. case NIMChatroomEventTypeEnter: //成员进入聊天室
  115. text = [NSString stringWithFormat:@" %@ 来了!",targetText];
  116. break;
  117. case NIMChatroomEventTypeExit: //成员离开聊天室
  118. text = [NSString stringWithFormat:@" %@ 离开了直播间",targetText];
  119. break;
  120. // case NIMChatroomEventTypeAddBlack: //成员被拉黑
  121. //
  122. // break;
  123. // case NIMChatroomEventTypeRemoveBlack: //成员被取消拉黑
  124. //
  125. // break;
  126. // case NIMChatroomEventTypeAddMute://成员被设置禁言
  127. //
  128. // break;
  129. // case NIMChatroomEventTypeRemoveMute://成员被取消禁言
  130. //
  131. // break;
  132. // case NIMChatroomEventTypeAddManager://设置为管理员
  133. //
  134. // break;
  135. // case NIMChatroomEventTypeRemoveManager://移除管理员
  136. //
  137. // break;
  138. case NIMChatroomEventTypeAddMute://成员被禁言
  139. text = [NSString stringWithFormat:@" %@ 被禁言了",targetText];
  140. break;
  141. case NIMChatroomEventTypeRemoveMute://成员被取消禁言
  142. text = [NSString stringWithFormat:@" %@ 被取消了禁言",targetText];
  143. break;
  144. case NIMChatroomEventTypeAddManager://设置为管理员
  145. text = [NSString stringWithFormat:@" %@ 被设置为管理员",targetText];
  146. break;
  147. case NIMChatroomEventTypeRemoveManager://移除管理员
  148. text = [NSString stringWithFormat:@" %@ 被取消设置为管理员",targetText];
  149. break;
  150. case NIMChatroomEventTypeAddMuteTemporarily://聊天室成员被临时禁言
  151. text = [NSString stringWithFormat:@" %@ 被禁言了",targetText];
  152. break;
  153. case NIMChatroomEventTypeRemoveMuteTemporarily://聊天室成员被解除临时禁言
  154. text = [NSString stringWithFormat:@" %@ 被取消了禁言",targetText];
  155. break;
  156. default:
  157. break;
  158. }
  159. if (text.length != 0) {
  160. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFDD8D);
  161. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:text];
  162. attributedString1 = [self youpaifhandleUserLevelWithFrom:message.from attributedStr:attributedString1 sendGiftHide:0];
  163. [attributedString1 addAttributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xFFDD8D)} range:NSMakeRange(self.youpaiptagCount, targetText.length + 1)];
  164. self.youpaipcontentL.attributedText = attributedString1;
  165. }
  166. }else if(message.messageType == NIMMessageTypeCustom){ // 自定义消息
  167. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  168. NSInteger sendGiftHide = 0;
  169. NSString *nick = [NIMKitUtil showNick:message.from inMessage:message];
  170. NSString *text = [NSString stringWithFormat:@"%@",nick];
  171. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]]){ // 礼物
  172. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  173. nick = attachment.from_nickname;
  174. sendGiftHide = attachment.send_gift_hide;
  175. if (sendGiftHide == 1) {
  176. self.userInteractionEnabled = NO;
  177. }
  178. text = [NSString stringWithFormat:@"%@",nick];
  179. text = [NSString stringWithFormat:@" %@ 送了%@个%@",text,@(attachment.gift_count),attachment.gift_name];
  180. giftImgStr = attachment.gift_url;
  181. }
  182. if ([object.attachment isKindOfClass:[YOUPAILZGuardAttachment class]]){ // 守护
  183. YOUPAILZGuardAttachment* attachment = (YOUPAILZGuardAttachment*)object.attachment;
  184. text = [NSString stringWithFormat:@" %@ 送了%@个%@",text,@(attachment.guard_count),attachment.guard_name];
  185. giftImgStr = attachment.guard_url;
  186. }
  187. if ([object.attachment isKindOfClass:[YOUPAILZLiveFollowAttachment class]]) { // 关注
  188. YOUPAILZLiveFollowAttachment* attachment = (YOUPAILZLiveFollowAttachment*)object.attachment;
  189. nick = @"";
  190. text = [NSString stringWithFormat:@" %@",attachment.msg];
  191. }
  192. if ([object.attachment isKindOfClass:[YOUPAILZLiveManageAttachment class]]) { // 管理
  193. YOUPAILZLiveManageAttachment* attachment = (YOUPAILZLiveManageAttachment*)object.attachment;
  194. text = [NSString stringWithFormat:@" %@",attachment.des];
  195. }
  196. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFDD8D);
  197. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:text];
  198. attributedString1 = [self youpaifhandleUserLevelWithFrom:message.from attributedStr:attributedString1 sendGiftHide:sendGiftHide];
  199. [attributedString1 addAttributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xFFDD8D)} range:NSMakeRange(self.youpaiptagCount, nick.length + 1)];
  200. self.youpaipcontentL.attributedText = attributedString1;
  201. }
  202. self.youpaipcontentL.lineBreakMode = NSLineBreakByCharWrapping;
  203. }
  204. - (void)youpaifreloadWithAttachment:(YOUPAILZChatRoomGiftAttachment *)attachment font:(UIFont *)font indexPath:(NSIndexPath *)indexPath{
  205. self.youpaipindexPath = indexPath;
  206. self.youpaipcontentL.font = font;
  207. self.userInteractionEnabled = YES;
  208. NSInteger sendGiftHide = attachment.send_gift_hide;
  209. if (sendGiftHide == 1) {
  210. self.userInteractionEnabled = NO;
  211. }
  212. NSString *text = [NSString stringWithFormat:@" %@ 送给 %@ %@个%@",attachment.from_nickname,attachment.to_nickname,@(attachment.gift_count),attachment.gift_name];
  213. self.youpaipcontentL.textColor = HexColorFromRGB(0xFFDD8D);
  214. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:text];
  215. attributedString1 = [self youpaifhandleUserLevelWithFrom:[NSString stringWithFormat:@"%@",@(attachment.from_uid)] attributedStr:attributedString1 sendGiftHide:sendGiftHide];
  216. self.youpaipcontentL.attributedText = attributedString1;
  217. self.youpaipcontentL.lineBreakMode = NSLineBreakByCharWrapping;
  218. }
  219. - (NSMutableAttributedString *)youpaifhandleUserLevelWithFrom:(NSString *)from attributedStr:(NSMutableAttributedString *)attributedStr sendGiftHide:(NSInteger)sendGiftHide{
  220. NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  221. self.youpaipmanagerTagView.hidden = YES;
  222. self.youpaipvipImgV.hidden = YES;
  223. self.youpaipboardImgV.hidden = YES;
  224. self.youpaipbadgeImgV.hidden = YES;
  225. self.youpaiplevelView.hidden = YES;
  226. if (sendGiftHide == 0) {
  227. CGFloat width = 0.0f;
  228. UIView *frontView = nil;
  229. self.youpaipmanagerTagView.hidden = NO;
  230. self.youpaipvipImgV.hidden = NO;
  231. self.youpaipboardImgV.hidden = NO;
  232. self.youpaipbadgeImgV.hidden = NO;
  233. self.youpaiplevelView.hidden = NO;
  234. NSString *ext = [self youpaifgetExtByUserId:from];
  235. NSInteger grade = 0;
  236. NSInteger vipLevel = 0;
  237. NSString *badge = @"";
  238. if (ext.length != 0) {
  239. NSData *data = [ext dataUsingEncoding:NSUTF8StringEncoding];
  240. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  241. if ([dict.allKeys containsObject:@"grade"]) {
  242. grade = [dict integerValueForKey:@"grade" defaultValue:0];
  243. }
  244. if ([dict.allKeys containsObject:@"bubble"]) {
  245. NSString *bubble = [NSString stringWithFormat:@"%@",[dict stringValueForKey:@"bubble" defaultValue:@""]];
  246. if (bubble.length != 0) {
  247. self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:bubble].absoluteString] scale:2];
  248. }
  249. }
  250. if ([dict.allKeys containsObject:@"vip"]) {
  251. vipLevel = [dict integerValueForKey:@"vip" defaultValue:0];
  252. }
  253. if ([dict.allKeys containsObject:@"badge"]) {
  254. badge = [NSString stringWithFormat:@"%@",[dict stringValueForKey:@"badge" defaultValue:@""]];
  255. }
  256. }
  257. NSMutableArray <NSTextAttachment *>*textAttachments = [NSMutableArray array];
  258. /// 管理员
  259. BOOL hasManage = NO;
  260. if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaipmanagers.allKeys containsObject:from]) {
  261. hasManage = YES;
  262. }
  263. if (hasManage) {
  264. self.youpaipmanagerTagView.hidden = NO;
  265. [self.youpaipmanagerTagView youpaifreloadWithModel:[YOUPAILZChatroomManagerTagModel mj_objectWithKeyValues:[[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaipmanagers objectForKey:from]]];
  266. self.youpaipmanagerTagView.mj_x = width;
  267. width += self.youpaipmanagerTagView.mj_w;
  268. frontView = self.youpaipmanagerTagView;
  269. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  270. attch.image = [UIImage new];
  271. attch.bounds = CGRectMake(0.0f, 0.0f, self.youpaipmanagerTagView.mj_w, 14.0f);
  272. [textAttachments addObject:attch];
  273. }else{
  274. self.youpaipmanagerTagView.hidden = YES;
  275. }
  276. if (frontView != nil) {
  277. width += 3.0f;
  278. frontView = nil;
  279. }
  280. /// 贵族
  281. NSDictionary *vipInfo = [LCSaveData getNobleInfo];
  282. BOOL hasVip = NO;
  283. if ([vipInfo.allKeys containsObject:[NSString stringWithFormat:@"%@",@(vipLevel)]]) {
  284. hasVip = YES;
  285. }
  286. if (hasVip) {
  287. NSDictionary *vipItemInfo = [vipInfo objectForKey:[NSString stringWithFormat:@"%@",@(vipLevel)]];
  288. self.youpaipvipImgV.hidden = NO;
  289. [self.youpaipvipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:[vipItemInfo stringValueForKey:@"mini_icon" defaultValue:@""]]];
  290. self.youpaipvipImgV.frame = CGRectMake(width, -1.0f, 30.0f, 19.0f);
  291. width += 30.0f;
  292. frontView = self.youpaipvipImgV;
  293. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  294. attch.image = [UIImage new];
  295. attch.bounds = CGRectMake(0.0f, 0.0f, self.youpaipvipImgV.mj_w, 14.0f);
  296. [textAttachments addObject:attch];
  297. }else{
  298. self.youpaipvipImgV.hidden = YES;
  299. }
  300. if (frontView != nil) {
  301. width += 3.0f;
  302. frontView = nil;
  303. }
  304. /// 排行
  305. NSDictionary *rankTopThere = [LCSaveData getLiveRankTopThere];
  306. BOOL hasRank = NO;
  307. if ([rankTopThere.allKeys containsObject:from]) {
  308. hasRank = YES;
  309. }
  310. if (hasRank) {
  311. NSDictionary *rankInfo = [rankTopThere objectForKey:from];
  312. self.youpaipboardImgV.hidden = NO;
  313. [self.youpaipboardImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:[rankInfo objectForKey:@"img"]]];
  314. self.youpaipboardImgV.frame = CGRectMake(width, 0.0f, 21.0f, 18.0f);
  315. width += 21.0f;
  316. frontView = self.youpaipboardImgV;
  317. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  318. attch.image = [UIImage new];
  319. attch.bounds = CGRectMake(0.0f, 0.0f, self.youpaipboardImgV.mj_w, 14.0f);
  320. [textAttachments addObject:attch];
  321. }else{
  322. self.youpaipboardImgV.hidden = YES;
  323. }
  324. if (frontView != nil) {
  325. width += 3.0f;
  326. frontView = nil;
  327. }
  328. /// 勋章
  329. NSDictionary *badgeInfo = [LCSaveData getBadgeInfo];
  330. BOOL hasBadge = NO;
  331. if (badge.length != 0) {
  332. hasBadge = YES;
  333. }
  334. if (hasBadge) {
  335. NSDictionary *badgeItemInfo = [badgeInfo objectForKey:badge];
  336. self.youpaipbadgeImgV.hidden = NO;
  337. [self.youpaipbadgeImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:[badgeItemInfo stringValueForKey:@"file" defaultValue:@""]]];
  338. CGFloat badgeIconWidth = [badgeItemInfo floatValueForKey:@"width" defaultValue:0];
  339. self.youpaipbadgeImgV.frame = CGRectMake(width, -0.0f, badgeIconWidth, 17.0f);
  340. width += badgeIconWidth;
  341. frontView = self.youpaipbadgeImgV;
  342. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  343. attch.image = [UIImage new];
  344. attch.bounds = CGRectMake(0.0f, 0.0f, self.youpaipbadgeImgV.mj_w, 14.0f);
  345. [textAttachments addObject:attch];
  346. }else{
  347. self.youpaipbadgeImgV.hidden = YES;
  348. }
  349. if (frontView != nil) {
  350. width += 3.0f;
  351. frontView = nil;
  352. }
  353. /// 等级
  354. NSDictionary *levelInfo = [LCSaveData getLevelInfo]?:@{};
  355. NSArray *grades = [levelInfo arrayValueForKey:@"grade" defaultValue:@[]];
  356. NSDictionary *levelDict = [levelInfo dictionaryValueForKey:@"info" defaultValue:@{}];
  357. NSString *levelName = [grades objectAtIndex:grade];
  358. NSDictionary *levelItem = [levelDict objectForKey:levelName];
  359. NSString *levelIcon = [levelItem stringValueForKey:@"img1" defaultValue:@""];
  360. CGFloat levelIconWidth = [levelItem floatValueForKey:@"icon_width" defaultValue:0];
  361. NSString *levelBg = [levelItem stringValueForKey:@"img2" defaultValue:@""];
  362. CGFloat levelBgWidth = [levelItem floatValueForKey:@"icon1_width" defaultValue:0];
  363. [self.youpaiplevelView youpaifreloadWithIcon:levelIcon iconWidth:levelIconWidth bgImg:levelBg bgImgWidth:levelBgWidth levelName:levelName level:grade];
  364. self.youpaiplevelView.mj_y = -0.0f;
  365. self.youpaiplevelView.mj_x = width;
  366. width += self.youpaiplevelView.mj_w;
  367. if (width >= 246.0f) {
  368. self.youpaiplevelView.mj_y = -0.0f + 14.0f + 4.0f;
  369. self.youpaiplevelView.mj_x = 0.0f;
  370. }
  371. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  372. attch.image = [UIImage new];
  373. attch.bounds = CGRectMake(0.0f, 0.0f, self.youpaiplevelView.mj_w, 14.0f);
  374. [textAttachments addObject:attch];
  375. if (self.youpaipbubbleImgV.ninePatchImage == nil) {
  376. self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:@"/v1.3/dress/bubble/lALPD3zUOqg7eJA7bg_110_59.png"].absoluteString] scale:2];
  377. }
  378. for (NSInteger i = 0; i < textAttachments.count; i ++) {
  379. NSTextAttachment *textAttachment = textAttachments[i];
  380. NSAttributedString *attr = [NSAttributedString attributedStringWithAttachment:textAttachment];
  381. [attributedStr insertAttributedString:attr atIndex:i];
  382. }
  383. {
  384. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  385. attch.image = [UIImage new];
  386. attch.bounds = CGRectMake(0.0f, 0.0f, 5.0f, 14.0f);
  387. [textAttachments addObject:attch];
  388. NSAttributedString *attr = [NSAttributedString attributedStringWithAttachment:attch];
  389. [attributedStr insertAttributedString:attr atIndex:textAttachments.count];
  390. }
  391. self.youpaiptagCount = textAttachments.count;
  392. }else{
  393. self.youpaipbubbleImgV.ninePatchImage = [SNKNinePatchImage ninePatchImageWithImageData:[LCSaveData getBubbleWithKey:[LCTools getImageUrlWithAddress:@"/v1.3/dress/bubble/lALPD3zUOqg7eJA7bg_110_59.png"].absoluteString] scale:2];
  394. }
  395. paragraphStyle1.alignment = NSTextAlignmentJustified;
  396. paragraphStyle1.lineSpacing = 3.0f;
  397. [attributedStr addAttributes:@{NSParagraphStyleAttributeName:paragraphStyle1} range:NSMakeRange(0, attributedStr.string.length)];
  398. [self youpaifHandleAmojiForText:attributedStr];
  399. return attributedStr;
  400. }
  401. - (void)youpaifHandleAmojiForText:(NSMutableAttributedString *)attributedStr{
  402. NSArray *tokens = [[YOUPAINIMInputEmoticonParser currentParser] tokens:attributedStr.string];
  403. for (NIMInputTextToken *token in tokens)
  404. {
  405. if (token.type == NIMInputTokenTypeEmoticon)
  406. {
  407. NIMInputEmoticon *emoticon = [[YOUPAINIMInputEmoticonManager sharedManager] emoticonByTag:token.text];
  408. UIImage *image = [UIImage nim_emoticonInKit:emoticon.filename];
  409. if (image)
  410. {
  411. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  412. attch.image = image;
  413. attch.bounds = CGRectMake(0.0f, 0.0f, 16.0f, 16.0f);
  414. NSRange range = [attributedStr.string rangeOfString:token.text];
  415. NSAttributedString *attr = [NSAttributedString attributedStringWithAttachment:attch];
  416. [attributedStr deleteCharactersInRange:range];
  417. [attributedStr insertAttributedString:attr atIndex:range.location];
  418. }
  419. }
  420. }
  421. }
  422. - (NSString *)youpaifgetExtByUserId:(NSString *)userId{
  423. NIMUser *nimUser = [[[NIMSDK sharedSDK] userManager] userInfo:userId];
  424. return nimUser.userInfo.ext;
  425. }
  426. - (void)youpaiftapOneAct{
  427. if(self.showUserInfoBlock != nil){
  428. self.showUserInfoBlock(self.youpaipindexPath);
  429. }
  430. }
  431. - (void)youpaiftapTwoAct{
  432. if(self.youpaipreplyBlock != nil){
  433. self.youpaipreplyBlock(self.youpaipindexPath);
  434. }
  435. }
  436. @end