// // TXGroupNoticeMessage.m // TUIChat // // Created by 王智 on 2024/8/30. // #import "TXGroupNoticeMessage.h" #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] @implementation TXGroupNoticeMessage + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message { NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil]; TXGroupNoticeMessage *cellData = [[TXGroupNoticeMessage alloc] initWithDirection:message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming]; cellData.innerMessage = message; cellData.msgID = message.msgID; cellData.noticeId = param[@"msgId"]; cellData.msgTitle = param[@"msgTitle"]; cellData.msgContent = param[@"msgContent"]; return cellData; } + (NSString *)getDisplayString:(V2TIMMessage *)message { return @"[群公告]"; } - (CGSize)contentSize { CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width); if (![self isEmptyString:self.msgContent]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.maximumLineHeight = 21; paragraphStyle.minimumLineHeight = 21; UIFont *font = [UIFont systemFontOfSize:16.0f]; 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; CGFloat contentHeight = height + 64 + 11; return CGSizeMake(width, contentHeight); } else { return CGSizeMake(width, 64 + 11); } } - (BOOL)isEmptyString:(NSString *)str { if (str == nil || str.length == 0) { return YES; } return NO; } @end