TXGroupNoticeMessage.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. CGFloat height = [self.msgContent boundingRectWithSize:CGSizeMake(225, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f],NSForegroundColorAttributeName:TXHexRGB(0x333333)} context:nil].size.height + 1;
  27. CGFloat contentHeight = height + 64 + 11;
  28. return CGSizeMake(width, contentHeight);
  29. }
  30. else {
  31. return CGSizeMake(width, 64 + 11);
  32. }
  33. }
  34. - (BOOL)isEmptyString:(NSString *)str {
  35. if (str == nil || str.length == 0) {
  36. return YES;
  37. }
  38. return NO;
  39. }
  40. @end