TXLiveShareMessage.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // TXLiveShareMessage.m
  3. // TUIChat
  4. //
  5. // Created by 王智 on 2023/8/10.
  6. //
  7. #import "TXLiveShareMessage.h"
  8. #define TXHexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  9. @implementation TXLiveShareMessage
  10. + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message {
  11. NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil];
  12. TXLiveShareMessage *cellData = [[TXLiveShareMessage alloc] initWithDirection:message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming];
  13. cellData.innerMessage = message;
  14. cellData.msgID = message.msgID;
  15. cellData.roomUID = param[@"roomUID"];
  16. cellData.teacherAvatar = param[@"teacherAvatar"];
  17. cellData.teacherName = param[@"teacherName"];
  18. cellData.liveDescMessage = param[@"liveDescMessage"];
  19. return cellData;
  20. }
  21. + (NSString *)getDisplayString:(V2TIMMessage *)message {
  22. return @"[直播分享]";
  23. }
  24. - (CGSize)contentSize {
  25. CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width);
  26. if (![self isEmptyString:self.liveDescMessage]) {
  27. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  28. [paragraphStyle setLineSpacing:4];//调整行间距
  29. CGFloat height = [self.liveDescMessage boundingRectWithSize:CGSizeMake(260, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:TXHexRGB(0x666666)} context:nil].size.height + 6;
  30. CGFloat contentHeight = height + 123 + 20;
  31. return CGSizeMake(width, contentHeight);
  32. }
  33. else {
  34. return CGSizeMake(width, 123 + 20);
  35. }
  36. }
  37. - (BOOL)isEmptyString:(NSString *)str {
  38. if (str == nil || str.length == 0) {
  39. return YES;
  40. }
  41. return NO;
  42. }
  43. @end