From 6f59274ca099fdf5f5ee5501db6370404bc428ac Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Wed, 25 Jun 2025 15:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20XPRoomMessageParser.m?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=88=BF=E9=97=B4=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=9B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20createImageAttribute:size:=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=BB=A5=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=E5=A4=A7=E5=B0=8F=EF=BC=8C=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E7=81=B5?= =?UTF-8?q?=E6=B4=BB=E6=80=A7=EF=BC=9B=E8=B0=83=E6=95=B4=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=9C=A8=E4=B8=8D=E5=90=8C=E6=9D=A1=E4=BB=B6=E4=B8=8B=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E5=B1=95=E7=A4=BA=E8=A1=A8=E6=83=85=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E6=8C=81=E4=BB=A3=E7=A0=81=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tool/XPRoomMessageParser.m | 79 ++++++++++++++----- 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m index e447ad26..d5323404 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m @@ -1040,32 +1040,57 @@ if ([attachment.data[@"data"] isKindOfClass:[NSArray class]]) { NSArray * array = [RoomFaceSendInfoModel modelsWithArray:attachment.data[@"data"]]; - for (int i = 0; i< array.count; i++) { - RoomFaceSendInfoModel * sendFaceInfo = [array xpSafeObjectAtIndex:i]; + if (array.count > 0) { + RoomFaceSendInfoModel * sendFaceInfo = [array xpSafeObjectAtIndex:0]; + [attribute appendAttributedString:[self createTextAttribute:sendFaceInfo.nick color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; + [attribute appendAttributedString:[self createTextAttribute:@":" color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; + [attribute appendAttributedString:[self createTextAttribute:@"\n" color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; + #if DEBUG - sendFaceInfo.faceId = 1; + NSInteger originalID = sendFaceInfo.faceId; + if (sendFaceInfo.faceId == 42) { + sendFaceInfo.faceId = 1; + } #endif if (sendFaceInfo.faceId == 1) { UIImage *image = kImage(@"幸运数字"); - [attribute appendAttributedString:[self createImageAttribute:[image cutImage:CGSizeMake(30, 30)]]]; + [attribute appendAttributedString:[self createImageAttribute:image size:CGSizeMake(40, 40)]]; } - - [attribute appendAttributedString:[self createTextAttribute:sendFaceInfo.nick color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; - [attribute appendAttributedString:[self createTextAttribute:@":" color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; - [attribute appendAttributedString:[self createTextAttribute:@"\n" color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; - for (int j = 0; j < sendFaceInfo.resultIndexes.count; j++) { - NSNumber *index = sendFaceInfo.resultIndexes[j]; - UIImage *face = [[XPRoomFaceTool shareFaceTool] findFaceImageById:sendFaceInfo.faceId index:[index integerValue]]; - if (face) { - UIImageView *imageView = [[UIImageView alloc]init]; - imageView.image = face; - imageView.contentMode = UIViewContentModeScaleAspectFit; - imageView.bounds = CGRectMake(0, 0, 30, 30); - NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; - [attribute appendAttributedString:[self createSapceAttribute:1]]; - [attribute appendAttributedString:attrString]; - } - } +#if DEBUG + sendFaceInfo.faceId = originalID; +#endif + } + + for (int i = 0; i< array.count; i++) { + RoomFaceSendInfoModel * sendFaceInfo = [array xpSafeObjectAtIndex:i]; + if (sendFaceInfo.resultIndexes.count == 0) { + RoomFaceInfoModel *configInfo = [[XPRoomFaceTool shareFaceTool] findFaceInfoById:sendFaceInfo.faceId]; + UIImage *face = [[XPRoomFaceTool shareFaceTool] findFaceImageById:sendFaceInfo.faceId index:configInfo.animStartPos]; + if (face) { + UIImageView *imageView = [[UIImageView alloc]init]; + imageView.image = face; + imageView.contentMode = UIViewContentModeScaleAspectFit; + imageView.bounds = CGRectMake(0, 0, 40, 40); + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; + [attribute appendAttributedString:[self createSapceAttribute:1]]; + [attribute appendAttributedString:attrString]; + } + } else { + for (int j = 0; j < sendFaceInfo.resultIndexes.count; j++) { + NSNumber *index = sendFaceInfo.resultIndexes[j]; + UIImage *face = [[XPRoomFaceTool shareFaceTool] findFaceImageById:sendFaceInfo.faceId index:[index integerValue]]; + if (face) { + UIImageView *imageView = [[UIImageView alloc]init]; + imageView.image = face; + imageView.contentMode = UIViewContentModeScaleAspectFit; + imageView.bounds = CGRectMake(0, 0, 30, 30); + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; + [attribute appendAttributedString:[self createSapceAttribute:1]]; + [attribute appendAttributedString:attrString]; + } + } + } + } } messageInfo.content = attribute; @@ -1781,6 +1806,18 @@ return attrString; } +- (NSMutableAttributedString *)createImageAttribute:(UIImage *)image size:(CGSize)size{ + UIImageView *imaveView = [[UIImageView alloc]init]; + imaveView.image = image; + CGFloat scale = (CGFloat)imaveView.image.size.width / (CGFloat)imaveView.image.size.height; + imaveView.bounds = CGRectMake(0, + 0, + size.width, + size.height); + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imaveView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imaveView.frame.size.width, imaveView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; + return attrString; +} + /// 生成一个富文本 /// @param text 富文本的文字 /// @param color 文字的颜色