TXGroupNoticeMessage.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // TXGroupNoticeMessage.m
  3. // TUIChat
  4. //
  5. // Created by 王智 on 2024/8/30.
  6. //
  7. #import "TXGroupNoticeMessage.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 TXGroupNoticeMessage
  10. + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message {
  11. NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil];
  12. TXGroupNoticeMessage *cellData = [[TXGroupNoticeMessage alloc] initWithDirection:message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming];
  13. cellData.innerMessage = message;
  14. cellData.msgID = message.msgID;
  15. cellData.noticeId = param[@"msgId"];
  16. cellData.msgTitle = param[@"msgTitle"];
  17. cellData.msgContent = param[@"msgContent"];
  18. return cellData;
  19. }
  20. + (NSString *)getDisplayString:(V2TIMMessage *)message {
  21. return @"[群公告]";
  22. }
  23. - (CGSize)contentSize {
  24. CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width);
  25. if (![self isEmptyString:self.msgContent]) {
  26. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  27. paragraphStyle.maximumLineHeight = 21;
  28. paragraphStyle.minimumLineHeight = 21;
  29. UIFont *font = [UIFont systemFontOfSize:16.0f];
  30. CGFloat height = [self.msgContent boundingRectWithSize:CGSizeMake(221, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font,NSForegroundColorAttributeName:TXHexRGB(0x333333)} context:nil].size.height + 1;
  31. CGFloat contentHeight = height + 64 + 11;
  32. return CGSizeMake(width, contentHeight);
  33. }
  34. else {
  35. return CGSizeMake(width, 64 + 11);
  36. }
  37. }
  38. - (BOOL)isEmptyString:(NSString *)str {
  39. if (str == nil || str.length == 0) {
  40. return YES;
  41. }
  42. return NO;
  43. }
  44. @end