// // MessageSkillCardModel.m // YUMI // // Created by YUMI on 2023/1/30. // #import "MessageSkillCardModel.h" #import "AttachmentModel.h" #import "GuildMessageModel.h" #import "NSObject+MJExtension.h" #import "DJDKMIMOMColor.h" @implementation MessageSkillCardModel - (instancetype)initWithMessage:(NIMMessage *)message { if (self = [super initWithMessage:message]) { self.messageType = SessionMessageType_Custom; NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; AttachmentModel * attach = obj.attachment; GuildMessageModel * info = [GuildMessageModel modelWithDictionary:attach.data]; self.guildInfo = info; 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(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, CGFLOAT_MAX); YYTextLayout * contentLayout = [YYTextLayout layoutWithContainerSize:maxSize text:attr]; self.attribute = attr; ///顶部的距离 20 title的高度15 title到content的高度 CGFloat contentHeight = contentLayout.textBoundingSize.height+ 20 + 15 + MESSAGE_PADDING * 4; self.textHeight = contentLayout.textBoundingSize.height + 5; self.height = contentHeight + CONTENT_PADDING_V_TOTAL; } return self; } - (NSDictionary *)messageTextAttibutes:(UIFont *)font { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:2.5]; return @{ NSFontAttributeName:font, NSParagraphStyleAttributeName: paragraphStyle }; } - (NSString *)cellContent:(MessageBaseModel *)model { return @"MessageContentSkillCardView"; } @end