// // MessageGuildModel.m // YUMI // // Created by YUMI on 2023/1/30. // #import "MessageGuildModel.h" #import "AttachmentModel.h" #import "GuildMessageModel.h" #import "DJDKMIMOMColor.h" #import "NSObject+MJExtension.h" @implementation MessageGuildModel - (instancetype)initWithMessage:(NIMMessage *)message { if (self = [super initWithMessage:message]) { self.messageType = SessionMessageType_Custom; NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; AttachmentModel * attach = (AttachmentModel *)obj.attachment; GuildMessageModel * info = [GuildMessageModel modelWithDictionary:attach.data]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]init]; GuildMessageLayoutModel *layout = info.layout; for (GuildMessageLayoutInfoModel *params in layout.contents) { if (params.content.length > 0) { if ([params.content containsString:@"/r/n"]) { params.content = @"\r\n"; } NSMutableAttributedString *subAttr = [[NSMutableAttributedString alloc]initWithString:params.content]; if (params.fontSize > 0) { [subAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:params.fontSize weight:params.fontBold?UIFontWeightBold:UIFontWeightRegular] range:NSMakeRange(0, subAttr.length)]; } if (params.fontColor.length > 0) { [subAttr addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor colorWithHexString:params.fontColor] range:NSMakeRange(0, subAttr.length)]; } [attr appendAttributedString:subAttr]; } } attr.yy_lineSpacing = 5; CGSize maxSize = CGSizeMake(230 - MESSAGE_PADDING * 2, CGFLOAT_MAX); YYTextLayout * contentLayout = [YYTextLayout layoutWithContainerSize:maxSize text:attr]; ///顶部的距离 20 title的高度15 title到content的高度 CGFloat contentHeight = contentLayout.textBoundingSize.height + 5 + 20 + 15 + 15 + MESSAGE_PADDING; ///44 底部操作栏的高度 BOOL isCommonNotice = (attach.second == Custom_Message_Sub_Hall_Notice || attach.second == Custom_Message_Sub_Hall_Become_Hall); if (!isCommonNotice) { contentHeight += (10+44); } self.height = contentHeight + CONTENT_PADDING_V_TOTAL; self.contentSize = CGSizeMake(CONTENT_WIDTH_MAX, contentHeight + 20 + 15 + 15); } return self; } - (NSDictionary *)messageTextAttibutes { UIFont *font = [UIFont systemFontOfSize:13.f]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:2.5]; return @{ NSFontAttributeName:font, NSParagraphStyleAttributeName: paragraphStyle }; } - (NSString *)cellContent:(MessageBaseModel *)model { return @"MessageContentGuildView"; } @end