// // YMRoomMessageParser.m // YUMI // // Created by YUMI on 2021/10/26. // #import "XPRoomMessageParser.h" #import #import ///Tool #import "ThemeColor+Room.h" #import "XPRoomMessageConstant.h" #import "AccountInfoStorage.h" #import "YUMIMacroUitls.h" #import "XPGiftStorage.h" #import "XPRoomFaceTool.h" #import "TTPopup.h" #import "NSArray+Safe.h" #import "ClientConfig.h" ///Model #import "XPMessageRemoteExtModel.h" #import "AttachmentModel.h" #import "GiftReceiveInfoModel.h" #import "XPKickUserModel.h" #import "MicroQueueModel.h" #import "UserInfoModel.h" #import "MicroStateModel.h" #import "RoomInfoModel.h" #import "DatingInfoModel.h" #import "RoomFaceInfoModel.h" #import "RoomFaceSendInfoModel.h" #import "GuildSuperAdminInfoModel.h" #import "RoomPKChooseUserModel.h" #import "RoomPKInfoModel.h" #import "CandyTreeResultModel.h" #import "XPGiftBigPrizeModel.h" #import "XPGiftCompoundModel.h" #import "RoomSailingPrizeModel.h" #import "XPOpenRedPacketModel.h" #import "XPMessageInfoModel.h" #import "TreasureFailryMessageModel.h" #import "NetImageView.h" #import "XPRoomTopicAlertView.h" #import "XPRoomSendTextView.h" #import "XPRoomPKResultView.h" #import "XPWebViewController.h" #import "XCCurrentVCStackManager.h" #import "XPTreasureFairyViewController.h" #import "PIGeneralPublicScreenModel.h" #import "QEmotionHelper.h" #import "BoomInfoModel.h" #import "UserRoomCardViewController.h" @implementation XPRoomMessageParser - (XPMessageInfoModel*)parseMessageAttributeForChatHall:(NIMMessage *)message{ NIMMessageType messageType = message.messageType; XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; messageInfo.isChatHall = YES; switch (messageType) { case NIMMessageTypeText: { XPMessageInfoModel *model = [self makeChatAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } case NIMMessageTypeCustom: { XPMessageInfoModel *model = [self makeCustomAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } default: return [XPMessageInfoModel new]; } } - (XPMessageInfoModel*)parseBroadcastMessageAttribute:(NIMBroadcastMessage *)message { if (message.content) { NSDictionary *msgDictionary = [message.content toJSONObject]; AttachmentModel *attachment = [AttachmentModel modelWithJSON:msgDictionary[@"body"]]; if (attachment.first == CustomMessageType_RoomBoom) { Boom632Model *model = [Boom632Model modelWithJSON:attachment.data]; XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; NSString *text = [NSString stringWithFormat:@"%@%@%@", YMLocalizedString(@"RoomMessageBoom_0"), model.nick, YMLocalizedString(@"RoomMessageBoom_1")]; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text]; [attributedString addAttribute:NSFontAttributeName value:kFontMedium(11) range:NSMakeRange(0, text.length)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, text.length)]; [attributedString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xFF3B3B) range:NSMakeRange([YMLocalizedString(@"RoomMessageBoom_0") length], model.nick.length)]; messageInfo.isBoom = YES; messageInfo.boomImageUrl = model.pic; messageInfo.rowHeight = 80; messageInfo.first = attachment.first; messageInfo.content = attributedString; return messageInfo; } } return nil; } - (XPMessageInfoModel*)parseMessageAttribute:(NIMMessage *)message { NIMMessageType messageType = message.messageType; XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; if([message.messageObject isKindOfClass:[NIMCustomObject class]] ){ NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel * attachment = (AttachmentModel *)obj.attachment; if(attachment.isBroadcast == YES){ return [self makeCustomAttribute:message messageInfo:messageInfo]; } } } switch (messageType) { case NIMMessageTypeText: { XPMessageInfoModel *model = [self makeChatAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } case NIMMessageTypeTip: { XPMessageInfoModel *model = [self makeTipsAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } case NIMMessageTypeNotification: { XPMessageInfoModel *model = [self makeNotificationAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } case NIMMessageTypeCustom: { XPMessageInfoModel *model = [self makeCustomAttribute:message messageInfo:messageInfo]; return model != nil ? model : [XPMessageInfoModel new]; break; } default: return [XPMessageInfoModel new]; } } - (NSString *)parseMessageBubble:(NIMMessage *)message { if (![message isKindOfClass:[NIMMessage class]] || ![message respondsToSelector:@selector(remoteExt)]) { return @""; } XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]]; return model.iosBubbleUrl ? model.iosBubbleUrl : @""; } /// 用户公屏聊天 - (XPMessageInfoModel *)makeCustomAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel*)messageInfo{ NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; AttachmentModel *attachment = (AttachmentModel *)obj.attachment; if (![message isKindOfClass:[NIMMessage class]] || ![message respondsToSelector:@selector(remoteExt)]) { return nil; } XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]]; messageInfo.bubbleImageUrl = [self parseMessageBubble:message]; int first = attachment.first; int second = attachment.second; if (first == CustomMessageType_Gift) {///单人送 return [self createSendGiftAttribute:attachment sendInfo:model messageInfo:messageInfo]; } else if(first == CustomMessageType_AllMicroSend) {///全麦送 多人送 return [self createBatchMicroSendGiftAttribute:attachment sendInfo:model messageInfo:messageInfo]; } else if(first == CustomMessageType_Room_Tip) {///分享/收藏房间 return [self createShareOrAttentionRoomAttribute:attachment sendInfo:model uid:message.from messageInfo:messageInfo]; } else if(first == CustomMessageType_Kick_User || first == CustomMessageType_Queue) { XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data]; return [self createKickUserAttribute:attachment info:kickModel messageInfo:messageInfo]; } else if(first == CustomMessageType_Look_Love) {//糖果树 return [self createCandyTreeHighLevelAttribute:attachment messageInfo:messageInfo]; } else if(first == CustomMessageType_Arrange_Mic) { return [self createArrangeMicAttribute:attachment messageInfo:messageInfo]; }else if(first == CustomMessageType_Update_RoomInfo) { return [self createRoomInfoUpdateAttribute:attachment messageInfo:messageInfo]; } else if(first == CustomMessageType_Collection_Room) { return [self createCollectRoomAttribute:attachment messageInfo:messageInfo]; } else if(first == CustomMessageType_RoomPlay_Dating) { return [self createRoomDatingAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_Noble_VIP) {//VIP return [self createNobleLevelAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_Face) {//表情 return [self createRoomFaceAttribute:attachment messageInfo:messageInfo remoteExtModel:model]; } else if (first == CustomMessageType_Tarot) {//塔罗 return [self createTarotAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_Anchor_FansTeam) {//粉丝团 return [self createAnchorFansTeamAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_Room_PK) {///房内PK return [self createRoomPKAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_LuckyBag) {///幸运礼物 return [self createRoomLuckyBigPrizeAttribute:attachment messageInfo:messageInfo]; } else if(first == CustomMessageType_Gift_Compound) {///礼物合成 return [self createRoomGiftCompoundAttribute:attachment messageInfo:messageInfo]; } else if(first == CustomMessageType_Room_Sailing) {///航海 return [self createRoomSailingAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_RedPacket) { if (attachment.second == Custom_Message_Sub_OpenRedPacketSuccess) { return [self createRedPacketAttribute:attachment messageInfo:messageInfo]; } else if (attachment.second == Custom_Message_Sub_LuckyPackage){ return [self createNewRedPacketAttribute:attachment messageInfo:messageInfo]; } } else if (first == CustomMessageType_Treasure_Fairy) { return [self createTreasureFairyAttribute:attachment messageInfo:messageInfo]; }else if (first == CustomMessageType_Room_Album) { NSDictionary *userInfo = attachment.data[@"user"]; NSDictionary *userLevel = attachment.data[@"userLevel"]; if(userLevel != nil){ NSString *charmUrl = userLevel[@"charmUrl"]; NSString *experUrl = userLevel[@"experUrl"]; messageInfo.charmUrl = charmUrl; messageInfo.experUrl = experUrl; } PIRoomPhotoAlbumItemModel *albumModel = [PIRoomPhotoAlbumItemModel modelWithDictionary:attachment.data[@"roomPhoto"]]; NSString * uid = [AccountInfoStorage instance].getUid; NSString * nick = @""; if(userInfo != nil){ nick = [NSString stringWithFormat:@"%@:", userInfo[@"nick"]]; } if ([message.from isEqualToString:uid]) { nick = YMLocalizedString(@"XPRoomMessageParser0"); } messageInfo.first = CustomMessageType_Room_Album; messageInfo.nameText = nick; messageInfo.albumModel = albumModel; messageInfo.content = [self makeUserNameAttribute:message messageInfo:messageInfo]; messageInfo.rowHeight = 240; return messageInfo; }else if(first == CustomMessageType_General_Public_Screen){ return [self createGeneralPublicScreenAttribute:attachment messageInfo:messageInfo]; }else if(first == CustomMessageType_Super_Gift){ return [self createGeneralPublicScreenAttribute:attachment messageInfo:messageInfo]; } else if (first == CustomMessageType_Hall_Super_Admin) { messageInfo.bubbleImageUrl = @""; NSString *content = @""; NSDictionary *dic = attachment.data; NSString *highLightContent = @""; switch (attachment.second) { case Custom_Message_Sub_Hall_Super_Admin_Lock_Mic: { NSNumber *micNum = [dic objectForKey:@"micNumber"]; if (micNum) { content = [NSString stringWithFormat:YMLocalizedString(@"1.0.34_text_8"), @(micNum.integerValue + 2)]; } } break; case Custom_Message_Sub_Hall_Super_Admin_Mute_Mic: { NSNumber *micNum = [dic objectForKey:@"micNumber"]; if (micNum) { content = [NSString stringWithFormat:YMLocalizedString(@"1.0.34_text_9"), @(micNum.integerValue + 2)]; } } break; case Custom_Message_Sub_Hall_Super_Admin_Kick_Down_Mic: { NSString *targetNick = [dic objectForKey:@"targetNick"]; if (targetNick) { content = [NSString stringWithFormat:YMLocalizedString(@"1.0.34_text_10"), targetNick]; highLightContent = targetNick; } } break; case Custom_Message_Sub_Hall_Super_Admin_Kick_Out_Room: { NSString *targetNick = [dic objectForKey:@"targetNick"]; if (targetNick) { content = [NSString stringWithFormat:YMLocalizedString(@"1.0.34_text_11"), targetNick]; highLightContent = targetNick; } } break; case Custom_Message_Sub_Hall_Super_Admin_Mark_Black: { NSString *targetNick = [dic objectForKey:@"targetNick"]; if (targetNick) { content = [NSString stringWithFormat:YMLocalizedString(@"1.0.34_text_12"), targetNick]; highLightContent = targetNick; } } break; case Custom_Message_Sub_Hall_Super_Admin_Kick_Manager_Out_Room: { XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data]; return [self createKickUserAttribute:attachment info:kickModel messageInfo:messageInfo]; } break; default: break; } if ([NSString isEmpty:content]) { return nil; } else { NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:content attributes:@{ NSFontAttributeName: kFontSemibold(14), NSForegroundColorAttributeName: [UIColor lightTextColor] }]; NSRange range = [content rangeOfString:highLightContent]; if (range.location != NSNotFound) { // 设置目标文本颜色为红色 [attribute addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor messageNickColor] range:range]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } } else if (first == CustomMessageType_User_Enter_Room) { switch (second) { case Custom_Message_Sub_User_Enter_Room: return [self createCPEnterRoomAttribute:attachment messageInfo:messageInfo]; break; case Custom_Message_Sub_Pic_Message: { PIRoomPhotoAlbumItemModel *albumModel = [PIRoomPhotoAlbumItemModel modelWithDictionary:attachment.data]; albumModel.photoUrl = albumModel.picUrl; albumModel.type = @"1"; albumModel.status = 1; messageInfo.first = CustomMessageType_Room_Album; messageInfo.nameText = albumModel.nick; messageInfo.albumModel = albumModel; messageInfo.charmUrl = albumModel.charmUrl; messageInfo.experUrl = albumModel.experUrl; messageInfo.bubbleImageUrl = albumModel.iosBubbleUrl; messageInfo.vipIcon = albumModel.vipIcon; messageInfo.content = [self makeUserNameAttribute:message messageInfo:messageInfo]; messageInfo.rowHeight = 240; return messageInfo; } break; default: break; } } // else if(first == 106){ // switch (second) { // case Custom_Message_Sub_Super_Gift_Room_Message: // return [self createGeneralPublicScreenAttribute:attachment messageInfo:messageInfo]; // break; // // default: // break; // } // } return nil; } - (NSAttributedString *)makeUserNameAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel *)messageInfo { NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSString *nick = messageInfo.albumModel.nick; if ([NSString isEmpty:nick]) { nick = messageInfo.nameText; } NSString *experUrl = messageInfo.albumModel.experUrl; if ([NSString isEmpty:experUrl]) { experUrl = messageInfo.experUrl; } NSString *charmUrl = messageInfo.albumModel.charmUrl; if ([NSString isEmpty:charmUrl]) { charmUrl = messageInfo.charmUrl; } NSString *vipIcon = messageInfo.albumModel.vipIcon; if ([NSString isEmpty:vipIcon]) { vipIcon = messageInfo.vipIcon; } NSString *inRoomNameplatePic = messageInfo.albumModel.inRoomNameplatePic; ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:messageInfo.albumModel.defUser newUser:messageInfo.albumModel.newUser fromSayHelloChannel:NO]]; if ([self isCurrentRoomSuperAdmin:message.from]) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"common_super_admin"]]; } if (![NSString isEmpty:experUrl]) { [attribute appendAttributedString:[self createUrlImageAttribute:experUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:charmUrl]) {//等级 [attribute appendAttributedString:[self createUrlImageAttribute:charmUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:vipIcon]) { [attribute appendAttributedString:[self createUrlImageAttribute:vipIcon]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:inRoomNameplatePic]) { [attribute appendAttributedString:[self createUrlImageAttribute:inRoomNameplatePic]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } [attribute appendAttributedString:[self createTextAttribute:nick color:[UIColor colorWithWhite:1 alpha:0.7] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; return attribute.copy; } /// @param message 消息的实体 - (XPMessageInfoModel*)makeChatAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel *)messageInfo{ if (![message isKindOfClass:[NIMMessage class]] || ![message respondsToSelector:@selector(remoteExt)]) { return messageInfo; } NSString * uid = [AccountInfoStorage instance].getUid; XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]]; messageInfo.bubbleImageUrl = [self parseMessageBubble:message]; NSString *getNick = ((NIMMessageChatroomExtension *)message.messageExt).roomNickname; if(getNick == nil && model.nick != nil){ getNick = model.nick; } NSString * nick = [NSString stringWithFormat:@"%@:", getNick]; if ([message.from isEqualToString:uid]) { nick = YMLocalizedString(@"XPRoomMessageParser0"); } NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:model.defUser newUser:model.newUser fromSayHelloChannel:model.fromSayHelloChannel]]; if ([self isCurrentRoomSuperAdmin:message.from]) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"common_super_admin"]]; } if (![NSString isEmpty:model.experUrl]) { messageInfo.experUrl = model.experUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:model.charmUrl]) {//等级 messageInfo.charmUrl = model.charmUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.charmUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:model.vipIcon]) { messageInfo.vipIcon = model.vipIcon; [attribute appendAttributedString:[self createUrlImageAttribute:model.vipIcon]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (model.inRoomNameplatePic.length > 0) { [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic]]; // [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic // size:CGSizeMake(72, kFontRegular(kRoomMessageDefalutFont).lineHeight)]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } [attribute appendAttributedString:[self createTextAttribute:nick color:[UIColor colorWithWhite:1 alpha:0.7] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; id nickNameNifo = message.remoteExt[@"atNames"]; if (message.text) { NSMutableAttributedString *msgStr; msgStr = [[NSMutableAttributedString alloc] initWithString:message.text]; [msgStr addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor messageTextColor] range:NSMakeRange(0, msgStr.length)]; [msgStr addAttribute:NSFontAttributeName value:kFontRegular(kRoomMessageDefalutFont) range:NSMakeRange(0, msgStr.length)]; if ([nickNameNifo isKindOfClass:[NSArray class]]) { for (NSString *nick in nickNameNifo) { NSRange range = [message.text rangeOfString:nick]; if (range.length) { [msgStr yy_setTextHighlightRange:range color:UIColorFromRGB(0xFD85C9) backgroundColor:[UIColor clearColor] userInfo:nil]; } } } [attribute appendAttributedString:msgStr]; } [self attributeAddLongPressHihtLight:attribute uid:message.from nick:((NIMMessageChatroomExtension *)message.messageExt).roomNickname]; messageInfo.cellKey = @"ChatMessage"; messageInfo.content = attribute; return messageInfo; } /// 房间tips消息 /// @param message 消息的实体 - (XPMessageInfoModel*)makeTipsAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel *)messageInfo{ messageInfo.bubbleImageUrl = [self parseMessageBubble:message]; if ([message.localExt.allKeys containsObject:@"isRoomTopic"]) { NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString: [self createTextAttribute:message.text color:[UIColor whiteColor] font:kRoomMessageDefalutFont]]; if ([[message.localExt objectForKey:@"isRoomTopic"] boolValue] == YES) { [attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; TTPopupService * config = [[TTPopupService alloc] init]; XPRoomTopicAlertView * alertView = [[XPRoomTopicAlertView alloc] init]; alertView.title = roomInfo.roomDesc; alertView.message = roomInfo.introduction; config.contentView = alertView; [TTPopup popupWithConfig:config]; }]; } messageInfo.content = attribute; } else { NSAttributedString * attribute = [self createTextAttribute:message.text color:UIColorFromRGB(0xFE5D7F) font:kRoomMessageDefalutFont]; messageInfo.content = attribute; } messageInfo.first = 10; return messageInfo; } /// 房间通知类消息 /// @param message 消息的实体 - (XPMessageInfoModel*)makeNotificationAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel *)messageInfo{ messageInfo.bubbleImageUrl = [self parseMessageBubble:message]; NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject; NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content; NIMChatroomNotificationMember *member = content.targets[0]; NIMMessageChatroomExtension * messageExt = (NIMMessageChatroomExtension *)message.messageExt; switch (content.eventType) { case NIMChatroomEventTypeEnter:///进入房间 { NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from]; XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithDictionary:dic]; NSString* nick = member.nick.length > 0 ? member.nick : @""; if ([nick.lowercaseString isEqualToString:@"Platform New User".lowercaseString] || [NSString isEmpty:nick]) { nick = extModel.nick; } ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:extModel.defUser newUser:extModel.newUser fromSayHelloChannel:extModel.fromSayHelloChannel]]; if ([self isCurrentRoomSuperAdmin:message.from]) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"common_super_admin"]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (extModel.experUrl.length > 0) {//等级 [attribute appendAttributedString:[self createUrlImageAttribute:extModel.experUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (extModel.charmUrl.length > 0) {//等级 [attribute appendAttributedString:[self createUrlImageAttribute:extModel.charmUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (extModel.vipIcon.length > 0) {//VIPicon messageInfo.vipIcon = extModel.vipIcon; [attribute appendAttributedString:[self createUrlImageAttribute:extModel.vipIcon]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (extModel.inRoomNameplatePic.length > 0) { [attribute appendAttributedString:[self createUrlImageAttribute:extModel.inRoomNameplatePic]]; // [attribute appendAttributedString:[self createUrlImageAttribute:extModel.inRoomNameplatePic // size:CGSizeMake(72, kFontRegular(kRoomMessageDefalutFont).lineHeight)]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } [attribute appendAttributedString:[self createNickAtrribute:nick uid:message.from.integerValue]]; if (extModel.carName.length > 0) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser1") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:extModel.carName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (extModel.fromType > 0) { if (extModel.fromType == UserEnterRoomFromType_Home_Recommend) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser2") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if(extModel.fromType == UserEnterRoomFromType_Follow_User || extModel.fromType == UserEnterRoomFromType_New_User_Greet) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser3") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createNickAtrribute:extModel.fromNick uid:extModel.fromUid.integerValue]]; } else if(extModel.fromType == UserEnterRoomFromType_Follow_Game_Detail) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser4") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createNickAtrribute:extModel.fromNick uid:extModel.fromUid.integerValue]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser5") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser6") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; messageInfo.content = attribute; messageInfo.first = 10; return messageInfo; } break; case NIMChatroomEventTypeInfoUpdated:{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; if (self.hostDelegate.getRoomInfo.datingState == RoomDatingStateChangeType_Open) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser8") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; messageInfo.content = attribute; messageInfo.first = 10; return messageInfo; } } break; default: return nil; } return nil; } #pragma mark - 夺宝精灵 - (XPMessageInfoModel *)createTreasureFairyAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ TreasureFailryMessageModel *info = [TreasureFailryMessageModel modelWithDictionary:attachment.data]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Gift_L1 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Gift_L2 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Gift_L3) {///初级礼物 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser115") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; NSMutableAttributedString * nickAttriibute = [self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:nickAttriibute uid:info.uid.integerValue]; [attribute appendAttributedString:nickAttriibute]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser116") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.rewardName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (info.rewardNum > 1) { [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"X%ld", info.rewardNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } else if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Gift_L4 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Gift_L5) {///高级礼物 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser117") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; NSMutableAttributedString * nickAttriibute = [self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:nickAttriibute uid:info.uid.integerValue]; [attribute appendAttributedString:nickAttriibute]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser116") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.rewardName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (info.rewardNum > 1) { [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"X%ld", info.rewardNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } else if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Ball_L1) {///初级球 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser115") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; NSMutableAttributedString * nickAttriibute = [self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:nickAttriibute uid:info.uid.integerValue]; [attribute appendAttributedString:nickAttriibute]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser116") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.rewardName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Ball_L2 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Draw_Ball_L3) {///高级球 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser117") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; NSMutableAttributedString * nickAttriibute = [self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:nickAttriibute uid:info.uid.integerValue]; [attribute appendAttributedString:nickAttriibute]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser116") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.rewardName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Convert_L1 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Convert_L2 || attachment.second == Custom_Message_Sub_Treasure_Fairy_Convert_L3) {///合成礼物 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser115") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; NSMutableAttributedString * nickAttriibute = [self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:nickAttriibute uid:info.uid.integerValue]; [attribute appendAttributedString:nickAttriibute]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser116") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; if(attachment.second == Custom_Message_Sub_Treasure_Fairy_Convert_L3) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser119") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Treasure_Fairy_Convert_L2) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser120") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser121") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser122") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%ld", info.rewardShowValue] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; if ([info.rewardType isEqualToString:@"gift"]){ [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser123") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } else { [attribute appendAttributedString:[self createTextAttribute:info.rewardUnit color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } [attribute appendAttributedString:[self createTextAttribute:info.rewardName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } if (self.hostDelegate.getUserInfo.userLevelVo.experLevelSeq >= info.userLevelLimit) { NSMutableAttributedString * nickAttriibute = [self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser124") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; @kWeakify(self); [nickAttriibute yy_setTextHighlightRange:NSMakeRange(0, nickAttriibute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); XPTreasureFairyViewController * fairyVC = [[XPTreasureFairyViewController alloc] initWithdelegate:self.hostDelegate]; fairyVC.roomUid =[NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid]; fairyVC.modalPresentationStyle = UIModalPresentationOverFullScreen; [self.hostDelegate.getCurrentNav presentViewController:fairyVC animated:YES completion:nil]; }]; [attribute appendAttributedString:nickAttriibute]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } - (XPMessageInfoModel *)createGeneralPublicScreenAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ PIGeneralPublicScreenModel *screenModel = [PIGeneralPublicScreenModel modelWithDictionary:attachment.data]; NSDictionary *textDic = screenModel.template; if(textDic.allKeys.count == 0) { return messageInfo; } NSString *key = [NSBundle uploadLanguageText]; NSString *title = textDic[key] == nil ? textDic[textDic.allKeys.firstObject] : textDic[key]; if(title.length == 0) { return messageInfo; } NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:@{ NSFontAttributeName:kFontRegular(kRoomMessageDefalutFont), NSForegroundColorAttributeName:[DJDKMIMOMColor colorWithHexString:screenModel.textColor]}]; for (PIGeneralPublicScreenItemModel *model in screenModel.contents) { if([model.type isEqualToString:@"TEXT"]){ NSDictionary *subTextDic = model.text; if(subTextDic.allKeys.count > 0){ NSString *subText = subTextDic[key] == nil ? subTextDic[subTextDic.allKeys.firstObject] : subTextDic[key]; NSAttributedString *attText = [[NSAttributedString alloc] initWithString:subText attributes:@{ NSForegroundColorAttributeName:[DJDKMIMOMColor colorWithHexString:model.textColor]}]; if ([attribute.string containsString:[NSString stringWithFormat:@"{%@}",model.key]]){ [attribute replaceCharactersInRange:[attribute.string rangeOfString:[NSString stringWithFormat:@"{%@}",model.key]] withAttributedString:attText]; } @kWeakify(self) [attribute yy_setTextHighlightRange:[attribute.string rangeOfString:subText] color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); if(model.skipType == 6){ if(model.skipContent.length == 0)return; [self showUserCard:model.skipContent.integerValue]; } }]; } }else if ([model.type isEqualToString:@"IMAGE"]){ NSMutableAttributedString *attImage = [self createUrlImageAttribute:model.image size:CGSizeMake(model.width, model.height)]; [attImage appendAttributedString:[self createSapceAttribute:2]]; if ([attribute.string containsString:[NSString stringWithFormat:@"{%@}",model.key]]){ [attribute replaceCharactersInRange:[attribute.string rangeOfString:[NSString stringWithFormat:@"{%@}",model.key]] withAttributedString:attImage]; } } } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 红包 - (XPMessageInfoModel *)createRedPacketAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ XPOpenRedPacketModel *info = [XPOpenRedPacketModel modelWithDictionary:attachment.data]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createNickAtrribute:info.openRedEnvelopeUserNick uid:info.openRedEnvelopeId.integerValue]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser9") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createNickAtrribute:info.redEnvelopeMasterNick uid:info.redEnvelopeMasterId.integerValue]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser10") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (info.amount.floatValue>0) { [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser11"), info.amount] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } - (XPMessageInfoModel *)createNewRedPacketAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSDictionary *dic = attachment.data; if (dic) { messageInfo.customInfo = dic; } messageInfo.rowHeight = 100; messageInfo.first = attachment.first; messageInfo.second = attachment.second; return messageInfo; } #pragma mark - CP 进场 - (XPMessageInfoModel *)createCPEnterRoomAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableDictionary *dic = [attachment.data mutableCopy]; [dic setObject:@(attachment.seq) forKey:@"cpIndex"]; messageInfo.customInfo = dic.copy; messageInfo.rowHeight = 81; messageInfo.first = attachment.first; messageInfo.second = attachment.second; return messageInfo; } #pragma mark - 航海 - (XPMessageInfoModel *)createRoomSailingAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ RoomSailingPrizeModel *info = [RoomSailingPrizeModel modelWithDictionary:attachment.data]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomCandyGiftView0") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser13") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.prizeName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; if (info.prizeNum>1) { [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"x%d", info.prizeNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } [self attributeAddHihtLight:attribute uid:info.uid.integerValue]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 礼物合成 - (XPMessageInfoModel *)createRoomGiftCompoundAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ XPGiftCompoundModel *info = [XPGiftCompoundModel modelWithDictionary:attachment.data]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser14") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.msg color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:info.giftName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [self attributeAddHihtLight:attribute uid:info.uid.integerValue]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 房间内幸运礼物 大价值 - (XPMessageInfoModel *)createRoomLuckyBigPrizeAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ XPGiftBigPrizeModel * info= [XPGiftBigPrizeModel modelWithDictionary:attachment.data]; NSString *text = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser15"),info.nick,info.luckyBagName,info.roomTitle,info.giftName]; if (isMSZH()){ text = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser15"),info.nick,info.roomTitle,info.luckyBagName,info.giftName]; } NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont],NSForegroundColorAttributeName:[DJDKMIMOMColor messageTextColor],NSParagraphStyleAttributeName:[self paragraphStyle]}]; [attribute addAttributes:@{NSForegroundColorAttributeName:[DJDKMIMOMColor messageNickColor]} range:[text rangeOfString:info.nick]]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 房间内PK - (XPMessageInfoModel *)createRoomPKAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; if (attachment.second == Custom_Message_Sub_Room_PK_Manager_Up_Mic) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser19") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; for (NSDictionary * selectuUser in [attachment.data allValues]) { RoomPKChooseUserModel * userInfoModel = [RoomPKChooseUserModel modelWithDictionary:selectuUser]; if (userInfoModel.groupType != GroupType_default && userInfoModel.nick.length > 0) { [attribute appendAttributedString:[self createNickAtrribute:userInfoModel.nick uid:userInfoModel.uid.integerValue]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser20") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSString * groupTypeStr; UIColor * groupColor; if (userInfoModel.groupType == GroupType_Red) { groupTypeStr= YMLocalizedString(@"XPRoomMessageParser21"); groupColor = UIColorFromRGB(0xFB3D74); }else{ groupTypeStr = YMLocalizedString(@"XPRoomMessageParser22"); groupColor = UIColorFromRGB(0x3291FC); } [attribute appendAttributedString:[self createTextAttribute:groupTypeStr color:groupColor font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:@"," color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } [attribute deleteCharactersInRange:NSMakeRange(attribute.string.length - 1, 1)]; } else { RoomPKInfoModel * model = [RoomPKInfoModel modelWithDictionary:attachment.data]; if (attachment.second == Custom_Message_Sub_Room_PK_Mode_Close) { NSString * title = YMLocalizedString(@"XPRoomMessageParser23"); [attribute appendAttributedString:[self createTextAttribute:title color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSRange range = [title rangeOfString:YMLocalizedString(@"XPRoomMessageParser24")]; [attribute addAttribute:NSForegroundColorAttributeName value:[DJDKMIMOMColor messageDefaultTextColor] range:range]; } else if(attachment.second == Custom_Message_Sub_Room_PK_Result) { NSString * victoryStr; if (model.result == RoomPKResultType_Draw) { RoomPKTeamModel * blueTeam; RoomPKTeamModel * redTeam; for (int i = 0 ; i < model.teams.count; i++) { RoomPKTeamModel * team = [model.teams xpSafeObjectAtIndex:i]; if (team.team == GroupType_Red) { redTeam = team; }else{ blueTeam = team; } } RoomPKTeamModel * team = [model.teams firstObject]; if (model.voteMode == RoomPKVoteModeType_NumberPerson) { victoryStr = YMLocalizedString(@"XPRoomMessageParser25"); NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", team.score],[NSString stringWithFormat:@"%lld", team.score]]; NSString * result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser26"),victoryStr, resultScale]; [attribute appendAttributedString:[self createTextAttribute:result color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; }else{ if (team.protecScore > 0) { NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", team.score],[NSString stringWithFormat:@"%lld", team.score]]; victoryStr = YMLocalizedString(@"XPRoomMessageParser27"); NSString * result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser28"),victoryStr, resultScale]; [attribute appendAttributedString:[self createTextAttribute:result color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; }else{ victoryStr = YMLocalizedString(@"XPRoomMessageParser29"); NSString * result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser28"),victoryStr, @"0:0"]; [attribute appendAttributedString:[self createTextAttribute:result color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } if (team.protector > 0) { [attribute appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\n"]]; NSString * teamStr = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser31"), blueTeam.protector.nick.length > 0 ? blueTeam.protector.nick : @"", [[NSNumber numberWithLongLong:blueTeam.protecScore] stringValue], redTeam.protector.nick.length > 0 ? redTeam.protector.nick : @"", [[NSNumber numberWithLongLong:redTeam.protecScore] stringValue]]; [attribute appendAttributedString:[self createTextAttribute:teamStr color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } }else{ RoomPKTeamModel * victoryTeam; RoomPKTeamModel * failTeam; for (int i = 0 ; i < model.teams.count; i++) { RoomPKTeamModel * team = [model.teams xpSafeObjectAtIndex:i]; if (team.team == (GroupType)model.result) { victoryTeam = team; }else{ failTeam = team; } } if (model.result == RoomPKResultType_Red){ victoryStr = YMLocalizedString(@"XPRoomMessageParser32"); }else if (model.result == RoomPKResultType_Blue){ victoryStr = YMLocalizedString(@"XPRoomMessageParser33"); } NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", victoryTeam.score],[NSString stringWithFormat:@"%lld", failTeam.score]]; NSString * result; if (model.voteMode == RoomPKVoteModeType_NumberPerson) { result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser34"),victoryStr, resultScale,[NSNumber numberWithLongLong:victoryTeam.score]]; }else{ if (victoryTeam.protector) { NSString * victoryProteror = victoryTeam.protector.nick.length > 0 ? victoryTeam.protector.nick : @""; result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser35"),victoryStr, resultScale,victoryStr, victoryProteror, victoryStr,[[NSNumber numberWithLongLong:victoryTeam.protecScore] stringValue]]; }else{ result = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser36"),victoryStr, resultScale,victoryStr,[[NSNumber numberWithLongLong:victoryTeam.protecScore] stringValue]]; } } [attribute appendAttributedString:[self createTextAttribute:result color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } @kWeakify(self); [attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); [self showRoomPKResult:attachment.data]; }]; } else if(attachment.second == Custom_Message_Sub_Room_PK_Mode_Open) { NSString * pkType; if (model.voteMode == RoomPKVoteModeType_GiftValue) { pkType = YMLocalizedString(@"XPRoomMessageParser37"); }else if (model.voteMode == RoomPKVoteModeType_NumberPerson){ pkType = YMLocalizedString(@"XPRoomMessageParser38"); } NSString * title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser114"), model.duration, pkType]; [attribute appendAttributedString:[self createTextAttribute:title color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; }else if (attachment.second == Custom_Message_Sub_Room_PK_Start){ NSString * title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser40"), model.duration]; [attribute appendAttributedString:[self createTextAttribute:title color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; }else if (attachment.second == Custom_Message_Sub_Room_PK_Re_Start){ NSString * pkType; if (model.voteMode == RoomPKVoteModeType_GiftValue) { pkType = YMLocalizedString(@"XPRoomMessageParser41"); }else if (model.voteMode == RoomPKVoteModeType_NumberPerson){ pkType = YMLocalizedString(@"XPRoomMessageParser42"); } NSString * title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser43"), model.duration, pkType]; [attribute appendAttributedString:[self createTextAttribute:title color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } - (void)showRoomPKResult:(NSDictionary *)dic { RoomPKInfoModel * pkInfo = [RoomPKInfoModel modelWithDictionary:dic]; if (pkInfo.pkStatus == RoomPKStatusType_End || pkInfo.pkStatus == RoomPKStatusType_ReStart) { XPRoomPKResultView * result = [[XPRoomPKResultView alloc] init]; result.roomPKResultInfoModel = pkInfo; [TTPopup popupView:result style:TTPopupStyleAlert]; } } #pragma mark - 表情显示 - (XPMessageInfoModel*)createRoomFaceAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo remoteExtModel:(XPMessageRemoteExtModel *)model { messageInfo.first = attachment.first; messageInfo.second = attachment.second; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:model.defUser newUser:model.newUser fromSayHelloChannel:model.fromSayHelloChannel]]; if ([self isCurrentRoomSuperAdmin:model.fromUid]) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"common_super_admin"]]; } if (![NSString isEmpty:model.experUrl]) { messageInfo.experUrl = model.experUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:model.charmUrl]) {//等级 messageInfo.charmUrl = model.charmUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.charmUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (![NSString isEmpty:model.vipIcon]) { messageInfo.vipIcon = model.vipIcon; [attribute appendAttributedString:[self createUrlImageAttribute:model.vipIcon]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (model.inRoomNameplatePic.length > 0) { [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if ([attachment.data[@"data"] isKindOfClass:[NSArray class]]) { NSArray * array = [RoomFaceSendInfoModel modelsWithArray:attachment.data[@"data"]]; 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 NSInteger originalID = sendFaceInfo.faceId; if (sendFaceInfo.faceId == 42) { sendFaceInfo.faceId = 1; } #endif if (sendFaceInfo.faceId == 1) { UIImage *image = kImage(@"幸运数字"); [attribute appendAttributedString:[self createImageAttribute:image size:CGSizeMake(40, 40)]]; } #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; return messageInfo; } #pragma mark - 收藏房间 - (XPMessageInfoModel*)createCollectRoomAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSDictionary *data = attachment.data[@"data"]; NSString *nick = [NSString stringWithFormat:@"%@",data[@"nick"]]; [attribute appendAttributedString:[self createTextAttribute:nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; NSString *tipString = @""; if (attachment.second == Custom_Message_Sub_Collect_Room_Tips) { tipString = YMLocalizedString(@"XPRoomMessageParser44"); } [attribute appendAttributedString:[self createTextAttribute:tipString color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 房间信息更新 - (XPMessageInfoModel*)createRoomInfoUpdateAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ if (attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) { NSDictionary * dic= attachment.data[@"roomInfo"]; if (dic.allKeys.count <=0) { dic = attachment.data; } RoomInfoModel *roomInfo = [RoomInfoModel modelWithDictionary:dic]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser45") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; if (roomInfo.isCloseScreen) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser46") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser47") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; } else if(attachment.second == Custom_Message_Sub_Update_RoomInfo_AnimateEffect) { NSDictionary * dic = attachment.data[@"roomInfo"]; if (dic.allKeys.count <=0) { dic = attachment.data; } RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser45") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; if (roomInfo.hasAnimationEffect) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser49") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser50") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createImageAttribute:[UIImage imageNamed:@"room_menu_more"]]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser51") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; } else if (attachment.second == Custom_Message_Sub_Update_RoomInfo_CleanScreen) { NSNumber *roleType = attachment.data[@"roleType"]; NSString *nick = attachment.data[@"nick"]; NSInteger uid = 0; if ([attachment.data[@"uid"] isKindOfClass:[NSNumber class]]) { uid = ((NSNumber *)attachment.data[@"uid"]).integerValue; } else if ([attachment.data[@"uid"] isKindOfClass:[NSString class]]) { uid = ((NSString *)attachment.data[@"uid"]).integerValue; } NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser45") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; if (roleType.integerValue == 1) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser53") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } else if (roleType.integerValue == 2) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser54") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser55") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [self attributeAddHihtLight:attribute uid:uid]; messageInfo.content = attribute; } messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 相亲 - (XPMessageInfoModel *)createRoomDatingAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; if(attachment.second == Custom_Message_Sub_Room_Play_Dating_Pick_Heart) { DatingInfoModel * datingModel = [DatingInfoModel modelWithDictionary:attachment.data]; NSString * targetGender = datingModel.targetGender == GenderType_Male ? YMLocalizedString(@"XPSessionFindNewFiltrateView2") : YMLocalizedString(@"XPRoomMessageParser57"); NSString * pickString = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser58"), (datingModel.targetPosition + 1), targetGender]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser59") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:pickString color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @""; [attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]]; NSString * heartContent = YMLocalizedString(@"XPRoomMessageParser60"); [attribute appendAttributedString:[self createTextAttribute:heartContent color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if(attachment.second == Custom_Message_Sub_Room_Play_Dating_Result_Mutual) {///互选 DatingInfoModel * datingModel = [DatingInfoModel modelWithDictionary:attachment.data]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser61") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSString * nick = datingModel.nickname ? datingModel.nickname : @""; [attribute appendAttributedString:[self createNickAtrribute:nick uid:datingModel.uid]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser62") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @""; [attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser63") color:[UIColor whiteColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Room_Play_Dating_Result_Not_Mutual) {///不是互选 DatingInfoModel * datingModel = [DatingInfoModel modelWithDictionary:attachment.data]; NSString * nick = datingModel.nickname ? datingModel.nickname : @""; [attribute appendAttributedString:[self createNickAtrribute:nick uid:datingModel.uid]]; if (datingModel.hasSelectUser) {//选择的有人 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser64") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @""; [attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]]; } else {///没有选择人 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser65") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } } messageInfo.content = attribute; return messageInfo; } #pragma mark - 排麦 - (XPMessageInfoModel *)createArrangeMicAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser66") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Open) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser67") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser68") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Close) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser69") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser70") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Open) { NSDictionary * dic = attachment.data; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser71") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser72"), ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser73") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Close) { NSDictionary * dic = attachment.data; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser74") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser75"), ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser76") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 糖果树公屏消息 - (XPMessageInfoModel *)createCandyTreeHighLevelAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ CandyTreeGiftInfoModel * giftInfo = [CandyTreeGiftInfoModel modelWithDictionary:attachment.data]; //action NSString *text = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser77"),giftInfo.nick,giftInfo.prizeName,[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]]; NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithAttributedString:[self createTextAttribute:text color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont],NSForegroundColorAttributeName:[DJDKMIMOMColor messageNickColor],NSParagraphStyleAttributeName:[self paragraphStyle]} range:[text rangeOfString:giftInfo.nick]]; [attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont],NSForegroundColorAttributeName:[DJDKMIMOMColor messageTextColor],NSParagraphStyleAttributeName:[self paragraphStyle]} range:[text rangeOfString:giftInfo.prizeName]]; if (giftInfo.prizeNum > 1) { [attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont],NSForegroundColorAttributeName:[DJDKMIMOMColor messageTextColor],NSParagraphStyleAttributeName:[self paragraphStyle]} range:[text rangeOfString:[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]]]; } if (attachment.second == Custom_Message_Sub_Candy_Tree_Me && giftInfo.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser79") color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } [self attributeAddHihtLight:attribute uid:giftInfo.uid.integerValue]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - VIP - (XPMessageInfoModel *)createNobleLevelAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSInteger uid = 0; if ([attachment.data[@"uid"] isKindOfClass:[NSNumber class]]) { uid = ((NSNumber *)attachment.data[@"uid"]).integerValue; } else if ([attachment.data[@"uid"] isKindOfClass:[NSString class]]) { uid = ((NSString *)attachment.data[@"uid"]).integerValue; } if (attachment.second == Custom_Message_Sub_Room_Open_Noble_VIP) {/// 开通VIP房内消息 851 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser80") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%@(%@)", attachment.data[@"nick"], attachment.data[@"erbanNo"]] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser81") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:attachment.data[@"currVipName"] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser82") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_Room_Noble_LevelUp || attachment.second == Custom_Message_Sub_AllRoom_Noble_LevelUp_Suspend) {///VIP升级 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser83") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:attachment.data[@"nick"] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser84") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:attachment.data[@"currVipName"] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:@"!" color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } [self attributeAddHihtLight:attribute uid:uid]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 塔罗 - (XPMessageInfoModel *)createTarotAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; if (attachment.second == Custom_Message_Sub_Tarot_Novice || attachment.second == Custom_Message_Sub_Tarot_Advanced || attachment.second == Custom_Message_Sub_Tarot_Intermediate) { [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser85") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:attachment.data[@"nick"] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; NSString *text = [NSString stringWithFormat:@" %@", YMLocalizedString(@"XPRoomMessageParser125")]; [attribute appendAttributedString:[self createTextAttribute:text color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; if ([attachment.data[@"drawGoldNum"] intValue] > 1) { [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d",[attachment.data[@"drawGoldNum"] intValue]] color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPNobleCenterPayView1") color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 个播粉丝团 - (XPMessageInfoModel *)createAnchorFansTeamAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSInteger uid = 0; if ([attachment.data[@"uid"] isKindOfClass:[NSNumber class]]) { uid = ((NSNumber *)attachment.data[@"uid"]).integerValue; } else if ([attachment.data[@"uid"] isKindOfClass:[NSString class]]) { uid = ((NSString *)attachment.data[@"uid"]).integerValue; } NSString *idString = [NSString stringWithFormat:@"%ld", uid]; NSString *nickName = attachment.data[@"nickname"]; if ([idString isEqualToString:[[AccountInfoStorage instance] getUid]]) { nickName = YMLocalizedString(@"XPRoomMessageParser86"); } if (attachment.second == Custom_Message_Sub_FansTeam_Open_Success) {/// 开通粉丝团成功 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser87") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:nickName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser88") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_FansTeam_Join_Success) {///加入粉丝团 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser89") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:nickName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser90") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } else if (attachment.second == Custom_Message_Sub_FansTeam_Out_Success) {//退出粉丝团 [attribute appendAttributedString:[self createTextAttribute:nickName color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser91") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } [self attributeAddHihtLight:attribute uid:uid]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 踢出房间/拉黑/下麦 - (XPMessageInfoModel *)createKickUserAttribute:(AttachmentModel *)attachment info:(XPKickUserModel *)info messageInfo:(XPMessageInfoModel *)messageInfo{ NSString * content= @""; NSString * targetName = [NSString isEmpty:info.targetNick] ? @"" : info.targetNick; NSString * handleName = [NSString isEmpty:info.handleNick] ? @"" : info.handleNick; if (attachment.second == Custom_Message_Sub_Kick_BeKicked || attachment.second == Custom_Message_Sub_Hall_Super_Admin_Kick_Manager_Out_Room) { content = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser93"),targetName,handleName]; } else if(attachment.second == Custom_Message_Sub_Kick_BlackList) { content = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser94"),targetName,handleName]; } else if(attachment.second == Custom_Message_Sub_Queue_Kick) { content = [NSString stringWithFormat:YMLocalizedString(@"XPRoomMessageParser95"),targetName,handleName]; } NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSForegroundColorAttributeName:[DJDKMIMOMColor messageDefaultTextColor],NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont]}]; if (![NSString isEmpty:targetName]) { [attribute addAttributes:@{NSForegroundColorAttributeName:[DJDKMIMOMColor messageNickColor],NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont]} range:[content rangeOfString:targetName]]; [self attributeAddHihtLight:attribute range:[content rangeOfString:targetName] uid:info.targetUid]; } if (![NSString isEmpty:handleName]) { [attribute addAttributes:@{NSForegroundColorAttributeName:[DJDKMIMOMColor messageNickColor],NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont]} range:[content rangeOfString:handleName]]; [self attributeAddHihtLight:attribute range:[content rangeOfString:handleName] uid:info.handleUid]; } messageInfo.content = attribute; return messageInfo; } #pragma mark - 分享房间 - (XPMessageInfoModel *)createShareOrAttentionRoomAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo uid:(NSString *)uid messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; NSDictionary *data = attachment.data; NSString *nick = [NSString stringWithFormat:@"%@",data[@"nick"]]; [attribute appendAttributedString:[self createTextAttribute:nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; NSString *tipString = @""; if (attachment.second == Custom_Message_Sub_Room_Tip_ShareRoom) { tipString = YMLocalizedString(@"XPRoomMessageParser96"); }else if (attachment.second == Custom_Message_Sub_Room_Tip_Attention_Owner) { tipString = YMLocalizedString(@"XPRoomMessageParser97"); } [attribute appendAttributedString:[self createTextAttribute:tipString color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [self attributeAddHihtLight:attribute uid:uid.integerValue]; messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - 送礼物的公屏 - (XPMessageInfoModel *)createBatchMicroSendGiftAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; GiftReceiveInfoModel *info = [GiftReceiveInfoModel modelWithJSON:attachment.data]; GiftInfoModel *giftInfo = info.gift == nil ? info.giftInfo : info.gift; if (giftInfo == nil) { NSString *roomUid = info.roomUid == 0 ? info.uid : @(info.roomUid).stringValue; giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:info.giftId inRoom:roomUid]; } ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:sendInfo.defUser newUser:sendInfo.newUser fromSayHelloChannel:sendInfo.fromSayHelloChannel]]; //nick [attribute appendAttributedString:[self createNickAtrribute:info.nick uid:info.uid.integerValue]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; if (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllMicroSend) {///普通礼物 if (attachment.second == Custom_Message_Sub_AllBatchSend) { //打赏 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser98") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; for (int i = 0; i < info.targetUsers.count; i++) { GiftReceiveUserInfoModel *targetInfo = [info.targetUsers xpSafeObjectAtIndex:i]; //nick [attribute appendAttributedString:[self createNickAtrribute:targetInfo.nick uid:targetInfo.uid]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; if (i < (info.targetUsers.count -1)) { //nick [attribute appendAttributedString:[self createTextAttribute:@"," color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } } } else { //打赏 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser99") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } //img if (giftInfo.giftUrl) { [attribute appendAttributedString:[self createUrlImageAttribute:giftInfo.giftUrl size:CGSizeMake(40, 40)]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } //x N [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",info.giftNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } else if(attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend) {///福袋礼物 //action NSString * sendTitle = YMLocalizedString(@"XPRoomMessageParser100"); if (attachment.second == Custom_Message_Sub_AllMicroLuckySend) { sendTitle = YMLocalizedString(@"XPRoomMessageParser101"); } //打赏 [attribute appendAttributedString:[self createTextAttribute:sendTitle color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; // 福袋名称 [attribute appendAttributedString:[self createTextAttribute:info.giftName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; // 福袋名称 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser102") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; if (info.luckyGiftList) { //target [attribute appendAttributedString:[self createNickAtrribute:info.luckyGiftList.user.nick uid:info.luckyGiftList.user.uid]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; // 福袋名称 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser103") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; [info.luckyGiftList.giftList enumerateObjectsUsingBlock:^(GiftListsInfo * _Nonnull giftListInfo, NSUInteger idx, BOOL * _Nonnull stop) { NSString *roomUid = info.roomUid == 0 ? info.uid : @(info.roomUid).stringValue; GiftInfoModel *luckGiftInfo = [[XPGiftStorage shareStorage] findGiftInfo:[NSString stringWithFormat:@"%ld", giftListInfo.giftId] inRoom:roomUid]; // 价值 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser104") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; // 礼物价格 [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%ld",(NSInteger)luckGiftInfo.goldPrice] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; // 的礼物 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser105") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; //img [attribute appendAttributedString:[self createUrlImageAttribute:luckGiftInfo.giftUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //x N [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",giftListInfo.giftNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (info.luckyGiftList.giftList.count-1 != idx) { //, [attribute appendAttributedString:[self createTextAttribute:@"," color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } }]; } } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } - (XPMessageInfoModel *)createSendGiftAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo messageInfo:(XPMessageInfoModel *)messageInfo{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; GiftReceiveInfoModel *info = [GiftReceiveInfoModel modelWithJSON:attachment.data]; GiftInfoModel *giftInfo = info.gift == nil ? info.giftInfo : info.gift; if (giftInfo == nil) { giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:info.giftId inRoom:@(info.roomUid).stringValue]; } if (giftInfo == nil) { giftInfo = [info.displayGift xpSafeObjectAtIndex:0]; } ///官方新用户 [attribute appendAttributedString:[self createOfficalAndNewuserAttribute:sendInfo.defUser newUser:sendInfo.newUser fromSayHelloChannel:sendInfo.fromSayHelloChannel]]; //nick [attribute appendAttributedString:[self createNickAtrribute:info.nick uid:info.uid.integerValue]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; if (attachment.second == Custom_Message_Sub_Gift_LuckySend) { //action [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser106") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; // 福袋名称 [attribute appendAttributedString:[self createTextAttribute:info.giftName color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser107") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; //target [attribute appendAttributedString:[self createNickAtrribute:info.luckyGiftList.user.nick uid:info.luckyGiftList.user.uid]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //lucky [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser108") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [info.luckyGiftList.giftList enumerateObjectsUsingBlock:^(GiftListsInfo * _Nonnull giftListInfo, NSUInteger idx, BOOL * _Nonnull stop) { GiftInfoModel *luckyGiftInfo = [[XPGiftStorage shareStorage] findGiftInfo:[NSString stringWithFormat:@"%ld", giftListInfo.giftId] inRoom:@(info.roomUid).stringValue]; if (luckyGiftInfo == nil) { luckyGiftInfo = giftInfo; } // 价值 [attribute appendAttributedString: [self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser109") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; // 礼物价格 [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%ld",(NSInteger)luckyGiftInfo.goldPrice] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; // 的礼物 [attribute appendAttributedString: [self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser110") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; //img [attribute appendAttributedString:[self createUrlImageAttribute:luckyGiftInfo.giftUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //x N [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",giftListInfo.giftNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; if (info.luckyGiftList.giftList.count-1 != idx) { //, [attribute appendAttributedString: [self createTextAttribute:@"," color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; } }]; } else { //打赏 [attribute appendAttributedString:[self createTextAttribute:YMLocalizedString(@"XPRoomMessageParser111") color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //target [attribute appendAttributedString: [self createNickAtrribute:info.targetNick uid:info.targetUid.integerValue]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //img [attribute appendAttributedString:[self createUrlImageAttribute:giftInfo.giftUrl size:CGSizeMake(40, 40)]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; //x N [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",info.giftNum] color:[DJDKMIMOMColor messageTextColor] font:kRoomMessageDefalutFont]]; } messageInfo.content = attribute; messageInfo.first = attachment.first; return messageInfo; } #pragma mark - Commond Mehotd ///用户是否当前房间的超管 - (BOOL)isCurrentRoomSuperAdmin:(NSString *)uid { for (GuildSuperAdminInfoModel *info in self.hostDelegate.getRoomSuperAdminList) { if ([info.uid isEqualToString:uid]) { return YES; } } return NO; } - (NSAttributedString *)createOfficalAndNewuserAttribute:(UserLevelType)levelType newUser:(BOOL)newUser fromSayHelloChannel:(BOOL)fromSayHelloChannel{ NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; //offical if (levelType == UserLevelType_Offical) { [attribute appendAttributedString: [self createLocalImageAttribute:@"app_admin_icon"]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } if (newUser) { if (fromSayHelloChannel) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"room_new_user_greet_new"]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } else { [attribute appendAttributedString: [self createLocalImageAttribute:[UIImage getLanguageText:@"common_new_user"]]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } } return attribute; } ///名字点击的 - (NSMutableAttributedString *)createNickAtrribute:(NSString *)nick uid:(NSInteger)uid { NSMutableAttributedString * attribute = [self createTextAttribute:nick color:[DJDKMIMOMColor messageNickColor] font:kRoomMessageDefalutFont]; [self attributeAddHihtLight:attribute uid:uid]; return attribute; } - (void)attributeAddHihtLight:(NSMutableAttributedString *)attribute range:(NSRange)range uid:(NSInteger)uid { @kWeakify(self); [attribute yy_setTextHighlightRange:range color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); if (uid <= 0) {return;} [self showUserCard:uid]; }]; } - (void)attributeAddHihtLight:(NSMutableAttributedString *)attribute uid:(NSInteger)uid { @kWeakify(self); [attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); if (uid <= 0) {return;} [self showUserCard:uid]; }]; } - (void)attributeAddLongPressHihtLight:(NSMutableAttributedString *)attribute uid:(NSString *)uid nick:(NSString *)nick { @kWeakify(self); [attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); if (uid <= 0) {return;} [self showUserCard:uid.integerValue]; } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); if ([uid isEqualToString:[AccountInfoStorage instance].getUid] || uid.length < 1) { return; } UIViewController *vc = self.hostDelegate.getCurrentNav.viewControllers[0]; [XPRoomSendTextView showTextView:vc.view delegate:self.hostDelegate atUid:uid atNick:nick]; }]; } - (void)showUserCard:(NSInteger)uid { RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; NSString * targetUid = [NSString stringWithFormat:@"%ld", uid]; XPUserCardInfoModel * model = [[XPUserCardInfoModel alloc] init]; __block MicroQueueModel *micModel = nil; [[self.hostDelegate.getMicroQueue allValues] enumerateObjectsUsingBlock:^(MicroQueueModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (uid == obj.userInfo.uid) { model.position = [NSString stringWithFormat:@"%d", obj.microState.position]; model.posState = obj.microState.posState; model.micState = obj.microState.micState; model.platformRole = obj.userInfo.platformRole; micModel = obj; *stop = YES; } }]; model.nick = self.hostDelegate.getUserInfo.nick; model.uid = targetUid; model.micQueue = self.hostDelegate.getMicroQueue; model.roomInfo = roomInfo; model.delegate = self.hostDelegate; model.superMangerList = self.hostDelegate.getRoomSuperAdminList; model.platformRole = micModel.userInfo.platformRole; UserRoomCardViewController *vc = [[UserRoomCardViewController alloc] initWithUser:model controlUser:self.hostDelegate.getUserInfo]; [self.hostDelegate.getCurrentNav presentViewController:vc animated:YES completion:nil]; } #pragma mark - private base methods ///铭牌 - (NSMutableAttributedString *)createNameplateAttibute:(NSString *)tagName image:(NSString *)imageName textFont:(UIFont *)textFont { NetImageConfig *config = [[NetImageConfig alloc]init]; ///先这样吧 CGSize defaultSize = CGSizeMake(60, kFontRegular(kRoomMessageDefalutFont).lineHeight); config.autoLoad = YES; NetImageView *imageView = [[NetImageView alloc] initWithUrl:imageName config:config]; imageView.bounds = CGRectMake(0, 0, defaultSize.width, defaultSize.height); // 异步加载图片 // @kWeakify(self); [imageView loadImageWithUrl:imageName completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) { // @kStrongify(self); if (image) { CGFloat scale = image.size.width / image.size.height; CGSize newSize = scale > 0 ? CGSizeMake(60 * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight) : defaultSize; dispatch_async(dispatch_get_main_queue(), ^{ imageView.bounds = CGRectMake(0, 0, newSize.width, newSize.height); }); } }]; // [imageView loadImageWithUrl:imageName completion:^(UIImage * _Nullable loadedImage) { // @kStrongify(self); // if (loadedImage) { // CGFloat scale = loadedImage.size.width / loadedImage.size.height; // CGSize newSize = scale > 0 ? CGSizeMake(18 * scale, 18) : defaultSize; // dispatch_async(dispatch_get_main_queue(), ^{ // imageView.bounds = CGRectMake(0, 0, newSize.width, newSize.height); // }); // } // }]; // UIImage* image = imageView.image; // if (image) { // CGFloat scale = image.size.width / image.size.height; // } else { // NSURL *imgUrl = [NSURL URLWithString:imageName]; // UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]]; // if (myImage) { // CGFloat scale = myImage.size.width / myImage.size.height; // if (scale == 0) { // imageView.bounds = CGRectMake(0, 0, 60, 18); // }else { // imageView.bounds = CGRectMake(0, 0, 18* scale, 18); // } // } else { // imageView.bounds = CGRectMake(0, 0, 60, 18); // } // } imageView.contentMode = UIViewContentModeScaleAspectFit; // 铭牌文字 if (![NSString isEmpty:tagName]) { UILabel *label = [[UILabel alloc] init]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont boldSystemFontOfSize:12]; label.adjustsFontSizeToFitWidth = YES; label.textColor = UIColor.whiteColor; label.text = tagName; [imageView addSubview:label]; [label mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(27); make.trailing.mas_equalTo(-8); make.centerY.mas_equalTo(0); }]; } NSMutableAttributedString *string = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.bounds.size alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return string; } /// 生成一个图片的富文本 /// @param imageUrl 网络图片的地址 - (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl { NetImageConfig *config = [[NetImageConfig alloc]init]; ///先这样吧 config.autoLoad = YES; NetImageView *imageView = [[NetImageView alloc]initWithUrl:imageUrl config:config]; UIImage* image = imageView.image; if (image) { CGFloat scale = image.size.width / image.size.height; imageView.bounds = CGRectMake(0, 0, kFontRegular(kRoomMessageDefalutFont).lineHeight * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight); } else { imageView.bounds = CGRectMake(0, 0, kFontRegular(kRoomMessageDefalutFont).lineHeight, kFontRegular(kRoomMessageDefalutFont).lineHeight); } imageView.layer.masksToBounds = YES; imageView.contentMode = UIViewContentModeScaleAspectFit; NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attrString; } /// 生成一个图片的富文本 /// @param imageUrl 网络图片的地址 - (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size { NetImageConfig *config = [[NetImageConfig alloc]init]; config.imageType = ImageTypeUserIcon; config.autoLoad = YES; NetImageView *imageView = [[NetImageView alloc] initWithUrl:imageUrl config:config]; imageView.backgroundColor = [UIColor clearColor]; imageView.bounds = CGRectMake(0, 0, size.width, size.height); imageView.layer.masksToBounds = YES; imageView.contentMode = UIViewContentModeScaleAspectFit; NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attrString; } /// 生成本地一个图片的富文本 /// @param imageName 网络图片的地址 - (NSMutableAttributedString *)createLocalImageAttribute:(NSString *)imageName { if (imageName == nil && imageName.length <= 0) { return nil; } UIImageView *imaveView = [[UIImageView alloc]init]; imaveView.image = [UIImage imageNamed:imageName]; CGFloat scale = (CGFloat)imaveView.image.size.width / (CGFloat)imaveView.image.size.height; imaveView.bounds = CGRectMake(0, 0, kFontRegular(kRoomMessageDefalutFont).lineHeight * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight); 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 imageName 网络图片的地址 - (NSMutableAttributedString *)createLanguageImageAttribute:(NSString *)imageName { if (imageName == nil && imageName.length <= 0) { return nil; } UIImageView *imaveView = [[UIImageView alloc]init]; imaveView.image = [UIImage getLanguageImage:imageName]; CGFloat scale = (CGFloat)imaveView.image.size.width / (CGFloat)imaveView.image.size.height; imaveView.bounds = CGRectMake(0, 0, kFontRegular(kRoomMessageDefalutFont).lineHeight * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight); 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 image 本地的图片 - (NSMutableAttributedString *)createImageAttribute:(UIImage *)image { 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, kFontRegular(kRoomMessageDefalutFont).lineHeight * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight); 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; } - (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 文字的颜色 /// @param font 文字的大小 - (NSMutableAttributedString *)createTextAttribute:(NSString *)text color:(UIColor *)color font:(CGFloat)font { if (text == nil || text.length <= 0) { text = @""; } NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil]; attribute.yy_font = [UIFont systemFontOfSize:font]; attribute.yy_color = color; attribute.yy_paragraphStyle = [self paragraphStyle]; return attribute; } /// 设置文本的样式 间隙 缩进 ... - (NSMutableParagraphStyle *)paragraphStyle { NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init]; paraStyle.lineSpacing = 4.0f;//行间距 // 强制排版(从左到右) paraStyle.alignment = NSTextAlignmentNatural; paraStyle.baseWritingDirection = isMSRTL() ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight; return paraStyle; } /// 占位的富文本 /// @param width 需要的间隙 - (NSMutableAttributedString *)createSapceAttribute:(CGFloat)width { UIView *spaceView = [[UIView alloc]init]; spaceView.backgroundColor = [UIColor clearColor]; spaceView.bounds = CGRectMake(0, 0, width, kFontRegular(kRoomMessageDefalutFont).lineHeight); NSMutableAttributedString * attribute = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(spaceView.frame.size.width, spaceView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attribute; } @end