1003 lines
59 KiB
Objective-C
1003 lines
59 KiB
Objective-C
//
|
||
// XPRoomMessageParser.m
|
||
// xplan-ios
|
||
//
|
||
// Created by 冯硕 on 2021/10/26.
|
||
//
|
||
|
||
#import "XPRoomMessageParser.h"
|
||
#import <YYText/YYText.h>
|
||
#import <NIMSDK/NIMSDK.h>
|
||
#import <Masonry/Masonry.h>
|
||
///Tool
|
||
#import "ThemeColor+Room.h"
|
||
#import "XPRoomMessageConstant.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "XPMacro.h"
|
||
#import "XPGiftStorage.h"
|
||
#import "XPRoomFaceTool.h"
|
||
#import "TTPopup.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 "NetImageView.h"
|
||
|
||
#import "XPUserCardViewController.h"
|
||
#import "XPRoomTopicAlertView.h"
|
||
#import "XPRoomSendTextView.h"
|
||
|
||
@implementation XPRoomMessageParser
|
||
|
||
- (NSAttributedString*)parseMessageAttribute:(NIMMessage *)message {
|
||
NIMMessageType messageType = message.messageType;
|
||
switch (messageType) {
|
||
case NIMMessageTypeText:
|
||
return [self makeChatAttribute:message];
|
||
|
||
case NIMMessageTypeTip:
|
||
return [self makeTipsAttribute:message];
|
||
|
||
case NIMMessageTypeNotification:
|
||
return [self makeNotificationAttribute:message];
|
||
|
||
case NIMMessageTypeCustom:
|
||
return [self makeCustomAttribute:message];
|
||
default:
|
||
return nil;
|
||
}
|
||
}
|
||
|
||
- (NSString *)parseMessageBubble:(NIMMessage *)message {
|
||
XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
|
||
return model.iosBubbleUrl ? model.iosBubbleUrl : @"";
|
||
}
|
||
|
||
/// 用户公屏聊天
|
||
- (NSAttributedString *)makeCustomAttribute:(NIMMessage *)message {
|
||
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
||
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
|
||
XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
|
||
int first = attachment.first;
|
||
if (first == CustomMessageType_Gift) {///单人送
|
||
return [self createSendGiftAttribute:attachment sendInfo:model];
|
||
} else if(first == CustomMessageType_AllMicroSend) {///全麦送 多人送
|
||
return [self createBatchMicroSendGiftAttribute:attachment sendInfo:model];
|
||
} else if(first == CustomMessageType_Room_Tip) {///分享/收藏房间
|
||
return [self createShareOrAttentionRoomAttribute:attachment sendInfo:model uid:message.from];
|
||
} else if(first == CustomMessageType_Kick_User || first == CustomMessageType_Queue) {
|
||
XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data];
|
||
return [self createKickUserAttribute:attachment info:kickModel];
|
||
} else if(first == CustomMessageType_Candy_Tree ) {//糖果树
|
||
return [self createCandyTreeHighLevelAttribute:attachment];
|
||
} else if(first == CustomMessageType_Arrange_Mic) {
|
||
return [self createArrangeMicAttribute:attachment];
|
||
}else if(first == CustomMessageType_Update_RoomInfo) {
|
||
return [self createRoomInfoUpdateAttribute:attachment];
|
||
} else if(first == CustomMessageType_Collection_Room) {
|
||
return [self createCollectRoomAttribute:attachment];
|
||
} else if(first == CustomMessageType_RoomPlay_Dating) {
|
||
return [self createRoomDatingAttribute:attachment];
|
||
} else if (first == CustomMessageType_Noble_VIP) {//贵族
|
||
return [self createNobleLevelAttribute:attachment];
|
||
} else if (first == CustomMessageType_Face) {//贵族
|
||
return [self createRoomFaceAttribute:attachment];
|
||
} else if (first == CustomMessageType_Tarot) {//塔罗
|
||
return [self createTarotAttribute:attachment];
|
||
} else if (first == CustomMessageType_Anchor_FansTeam) {//粉丝团
|
||
return [self createAnchorFansTeamAttribute:attachment];
|
||
} else if(first == CustomMessageType_Hall_Super_Admin) {///超管踢人出房间
|
||
XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data];
|
||
return [self createKickUserAttribute:attachment info:kickModel];
|
||
} else if (first == CustomMessageType_Room_PK) {///房内PK
|
||
return [self createRoomPKAttribute:attachment];
|
||
}
|
||
return nil;
|
||
}
|
||
|
||
/// @param message 消息的实体
|
||
- (NSAttributedString*)makeChatAttribute:(NIMMessage *)message{
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
|
||
|
||
NSString * nick = [NSString stringWithFormat:@"%@:", ((NIMMessageChatroomExtension *)message.messageExt).roomNickname];
|
||
if ([message.from isEqualToString:uid]) {
|
||
nick = @"我:";
|
||
}
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
if ([self isCurrentRoomSuperAdmin:message.from]) {
|
||
[attribute appendAttributedString:[self createLocalImageAttribute:@"common_super_admin"]];
|
||
}
|
||
///官方新用户
|
||
[attribute appendAttributedString:[self createOfficalAndNewuserAttribute:model.defUser newUser:model.newUser]];
|
||
if (model.vipIcon) {//贵族icon
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:model.vipIcon]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
if (model.experUrl) {
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
if (model.inRoomNameplatePic.length > 0 && model.inRoomNameplateWord.length > 0) { //铭牌有图片加文字
|
||
[attribute appendAttributedString:[self createNameplateAttibute:model.inRoomNameplateWord image:model.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
} else if (model.inRoomNameplatePic.length > 0) {//铭牌只有图片
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
|
||
id nickNameNifo = message.remoteExt[@"atNames"];
|
||
NSMutableAttributedString *msgStr;
|
||
if (message.text) {
|
||
msgStr = [[NSMutableAttributedString alloc] initWithString:message.text];
|
||
[msgStr addAttribute:NSForegroundColorAttributeName
|
||
value:[ThemeColor messageTextColor]
|
||
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];
|
||
return attribute;
|
||
}
|
||
|
||
/// 房间tips消息
|
||
/// @param message 消息的实体
|
||
- (NSAttributedString*)makeTipsAttribute:(NIMMessage *)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];
|
||
}];
|
||
}
|
||
return attribute;
|
||
} else {
|
||
return [self createTextAttribute:message.text color:UIColorFromRGB(0xFE5D7F) font:kRoomMessageDefalutFont];
|
||
}
|
||
}
|
||
|
||
/// 房间通知类消息
|
||
/// @param message 消息的实体
|
||
- (NSAttributedString*)makeNotificationAttribute:(NIMMessage *)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:///进入房间
|
||
{
|
||
NSString* nick = member.nick.length > 0 ? member.nick : @"";
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from];
|
||
XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithDictionary:dic];
|
||
if ([self isCurrentRoomSuperAdmin:message.from]) {
|
||
[attribute appendAttributedString:[self createLocalImageAttribute:@"common_super_admin"]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
if (extModel.vipIcon.length > 0) {//贵族icon
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:extModel.vipIcon]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
if (extModel.experUrl.length > 0) {//等级
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:extModel.experUrl]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
if (extModel.inRoomNameplatePic.length > 0 && extModel.inRoomNameplateWord.length > 0) {
|
||
[attribute appendAttributedString:[self createNameplateAttibute:extModel.inRoomNameplateWord image:extModel.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
[attribute appendAttributedString:[self createNickAtrribute:nick uid:message.from.integerValue]];
|
||
if (extModel.carName.length > 0) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@" 驾着 " color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:extModel.carName color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
if (extModel.fromType > 0) {
|
||
if (extModel.fromType == UserEnterRoomFromType_Home_Recommend) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"根据首页推荐" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if(extModel.fromType == UserEnterRoomFromType_Follow_User) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"跟随" color:[ThemeColor 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:@"接受" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createNickAtrribute:extModel.fromNick uid:extModel.fromUid.integerValue]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"的邀请" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:@"进入了房间" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
return attribute;
|
||
}
|
||
break;
|
||
case NIMChatroomEventTypeInfoUpdated:{
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
if (self.hostDelegate.getRoomInfo.datingState == RoomDatingStateChangeType_Open) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"相亲玩法已开启,请点击主持人麦位选择主持人" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
return attribute;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
return nil;
|
||
}
|
||
return nil;
|
||
}
|
||
|
||
#pragma mark - 房间内PK
|
||
- (NSAttributedString *)createRoomPKAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
if (attachment.second == Custom_Message_Sub_Room_PK_Manager_Up_Mic) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"房主/管理员邀请" color:[ThemeColor 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:@"进入" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSString * groupTypeStr;
|
||
UIColor * groupColor;
|
||
if (userInfoModel.groupType == GroupType_Red) {
|
||
groupTypeStr= @"红队";
|
||
groupColor = UIColorFromRGB(0xFB3D74);
|
||
}else{
|
||
groupTypeStr = @"蓝队";
|
||
groupColor = UIColorFromRGB(0x3291FC);
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:groupTypeStr color:groupColor font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"," color:[ThemeColor 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 = @"管理员关闭了PK模式";
|
||
[attribute appendAttributedString:[self createTextAttribute:title color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSRange range = [title rangeOfString:@"关闭了"];
|
||
[attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor messageDefaultTextColor] range:range];
|
||
} else if(attachment.second == Custom_Message_Sub_Room_PK_Result) {
|
||
NSString * victoryStr;
|
||
if (model.result == RoomPKResultType_Draw) {
|
||
RoomPKTeamModel * team = [model.teams firstObject];
|
||
if (model.voteMode == RoomPKVoteModeType_NumberPerson) {
|
||
victoryStr = @"平局";
|
||
NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", team.score],[NSString stringWithFormat:@"%lld", team.score]];
|
||
NSString * result = [NSString stringWithFormat:@"本场PK结果:%@!\n PK值%@",victoryStr, resultScale];
|
||
[attribute appendAttributedString:[self createTextAttribute:result color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}else{
|
||
if (team.protecScore > 0) {
|
||
NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", team.score],[NSString stringWithFormat:@"%lld", team.score]];
|
||
victoryStr = @"平局";
|
||
NSString * result = [NSString stringWithFormat:@"本场PK结果:%@!\n PK值%@",victoryStr, resultScale];
|
||
[attribute appendAttributedString:[self createTextAttribute:result color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}else{
|
||
victoryStr = @"平局";
|
||
NSString * result = [NSString stringWithFormat:@"本场PK结果:%@!\n PK值%@",victoryStr, @"0:0"];
|
||
[attribute appendAttributedString:[self createTextAttribute:result color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}
|
||
}else{
|
||
RoomPKTeamModel * victoryTeam;
|
||
RoomPKTeamModel * failTeam;
|
||
for (int i = 0 ; i < model.teams.count; i++) {
|
||
RoomPKTeamModel * team = [model.teams objectAtIndex:i];
|
||
if (team.team == (GroupType)model.result) {
|
||
victoryTeam = team;
|
||
}else{
|
||
failTeam = team;
|
||
}
|
||
}
|
||
|
||
if (model.result == RoomPKResultType_Red){
|
||
victoryStr = @"红队胜利";
|
||
}else if (model.result == RoomPKResultType_Blue){
|
||
victoryStr = @"蓝队胜利";
|
||
}
|
||
|
||
NSString * resultScale = [NSString stringWithFormat:@"%@:%@",[NSString stringWithFormat:@"%lld", victoryTeam.score],[NSString stringWithFormat:@"%lld", failTeam.score]];
|
||
NSString * result;
|
||
if (model.voteMode == RoomPKVoteModeType_NumberPerson) {
|
||
result = [NSString stringWithFormat:@"本场PK结果:%@!\n PK值%@ \n 胜利方战斗值:%@",victoryStr, resultScale,[NSNumber numberWithLongLong:victoryTeam.score]];
|
||
}else{
|
||
if (victoryTeam.protector) {
|
||
result = [NSString stringWithFormat:@"本场PK结果:%@ \n PK值%@ \n 胜利方战斗值:%@ \n 守护者:%@ \n 守护值:%@",victoryStr, resultScale,[[NSNumber numberWithLongLong:victoryTeam.score] stringValue],victoryTeam.protector.nick.length > 0 ?victoryTeam.protector.nick : @"", [[NSNumber numberWithLongLong:victoryTeam.protecScore] stringValue]];
|
||
}else{
|
||
result = [NSString stringWithFormat:@"本场PK结果:%@ \n PK值%@ \n 胜利方战斗值:%@ \n 守护值:%@",victoryStr, resultScale,[[NSNumber numberWithLongLong:victoryTeam.score] stringValue], [[NSNumber numberWithLongLong:victoryTeam.protecScore] stringValue]];
|
||
}
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:result color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
} else if(attachment.second == Custom_Message_Sub_Room_PK_Mode_Open) {
|
||
NSString * pkType;
|
||
if (model.voteMode == RoomPKVoteModeType_GiftValue) {
|
||
pkType = @"获得礼物多的团队获胜";
|
||
}else if (model.voteMode == RoomPKVoteModeType_NumberPerson){
|
||
pkType = @"送礼人数多的团队获胜";
|
||
}
|
||
NSString * title = [NSString stringWithFormat:@"管理员创建房间PK,本次PK时间为%.0f秒,%@", model.duration, pkType];
|
||
[attribute appendAttributedString:[self createTextAttribute:title color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}else if (attachment.second == Custom_Message_Sub_Room_PK_Start){
|
||
NSString * title = [NSString stringWithFormat:@"PK开始了,本次PK时间为%.0f秒,快给喜欢的选手投票吧", model.duration];
|
||
[attribute appendAttributedString:[self createTextAttribute:title color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}else if (attachment.second == Custom_Message_Sub_Room_PK_Re_Start){
|
||
NSString * pkType;
|
||
if (model.voteMode == RoomPKVoteModeType_GiftValue) {
|
||
pkType = @"获得礼物多的团队获胜";
|
||
}else if (model.voteMode == RoomPKVoteModeType_NumberPerson){
|
||
pkType = @"送礼人数多的团队获胜";
|
||
}
|
||
NSString * title = [NSString stringWithFormat:@"管理员重新开始PK,本次PK时间为%.0f秒,%@", model.duration, pkType];
|
||
[attribute appendAttributedString:[self createTextAttribute:title color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 表情显示
|
||
- (NSAttributedString*)createRoomFaceAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
if ([attachment.data[@"data"] isKindOfClass:[NSArray class]]) {
|
||
NSArray * array = [RoomFaceSendInfoModel modelsWithArray:attachment.data[@"data"]];
|
||
for (int i = 0; i< array.count; i++) {
|
||
RoomFaceSendInfoModel * sendFaceInfo = [array objectAtIndex:i];
|
||
[attribute appendAttributedString:[self createTextAttribute:sendFaceInfo.nick color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@":" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"\n" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
for (int j = 0; j < sendFaceInfo.resultIndexes.count; j++) {
|
||
NSNumber *index = sendFaceInfo.resultIndexes[j];
|
||
UIImage *face = [[XPRoomFaceTool shareFaceTool] findFaceImageById:sendFaceInfo.faceId index:[index integerValue]];
|
||
if (face) {
|
||
UIImageView *imageView = [[UIImageView alloc]init];
|
||
imageView.image = face;
|
||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||
imageView.bounds = CGRectMake(0, 0, 30, 30);
|
||
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||
[attribute appendAttributedString:[self createSapceAttribute:1]];
|
||
[attribute appendAttributedString:attrString];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 收藏房间
|
||
- (NSAttributedString*)createCollectRoomAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
NSDictionary *data = attachment.data[@"data"];
|
||
NSString *nick = [NSString stringWithFormat:@"%@",data[@"nick"]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
NSString *tipString = @"";
|
||
if (attachment.second == Custom_Message_Sub_Collect_Room_Tips) {
|
||
tipString = @"收藏了房间";
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:tipString color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 房间信息更新
|
||
- (NSAttributedString*)createRoomInfoUpdateAttribute:(AttachmentModel *)attachment {
|
||
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:@"消息:" color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
if (roomInfo.isCloseScreen) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员已关闭聊天公屏" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
} else {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员已开启聊天公屏" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
return 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:@"消息:" color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
if (roomInfo.hasAnimationEffect) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员已开启房间内礼物特效" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
} else {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员已关闭房间内礼物特效,点击底部" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createImageAttribute:[UIImage imageNamed:@"room_menu_more"]]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"图标即可开启" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
return 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:@"消息:" color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
if (roleType.integerValue == 1) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"房主" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
} else if (roleType.integerValue == 2) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:@"已清空房间公屏消息" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[self attributeAddHihtLight:attribute uid:uid];
|
||
return attribute;
|
||
}
|
||
return nil;
|
||
}
|
||
|
||
#pragma mark - 相亲
|
||
- (NSAttributedString *)createRoomDatingAttribute:(AttachmentModel *)attachment {
|
||
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 ? @"男" : @"女";
|
||
NSString * pickString = [NSString stringWithFormat:@"%d号%@嘉宾:", (datingModel.targetPosition + 1), targetGender];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"本轮你选择了" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:pickString color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @"";
|
||
[attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]];
|
||
NSString * heartContent = @"作为你的心动对象";
|
||
[attribute appendAttributedString:[self createTextAttribute:heartContent color:[ThemeColor 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:@"恭喜" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSString * nick = datingModel.nickname ? datingModel.nickname : @"";
|
||
[attribute appendAttributedString:[self createNickAtrribute:nick uid:datingModel.uid]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"和" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @"";
|
||
[attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"牵手成功,让我们见证他们幸福的开端" color:UIColorFromRGB(0xF84C95) 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:@"的心动对象是" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
NSString * targetNick = datingModel.targetNickname ? datingModel.targetNickname : @"";
|
||
[attribute appendAttributedString:[self createNickAtrribute:targetNick uid:datingModel.targetUid]];
|
||
} else {///没有选择人
|
||
[attribute appendAttributedString:[self createTextAttribute:@"未选择心动对象" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 排麦
|
||
- (NSAttributedString *)createArrangeMicAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"管理员" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Open) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"开启了" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"排麦模式" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Mode_Close) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"关闭了" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"排麦模式" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Open) {
|
||
NSDictionary * dic = attachment.data;
|
||
[attribute appendAttributedString:[self createTextAttribute:@"设置" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d麦", ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"为自由麦" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_Arrange_Mic_Free_Mic_Close) {
|
||
NSDictionary * dic = attachment.data;
|
||
[attribute appendAttributedString:[self createTextAttribute:@"关闭了" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d麦", ((NSNumber *)dic[@"micPos"]).intValue + 1 ] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"自由麦" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 糖果树公屏消息
|
||
- (NSAttributedString *)createCandyTreeHighLevelAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
//action
|
||
[attribute appendAttributedString:[self createTextAttribute:@"厉害了 " color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
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;
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"nick"] color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"摘下糖果获得" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"prizeName"] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" x %@", attachment.data[@"prizeNum"]] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[self attributeAddHihtLight:attribute uid:uid];
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 贵族
|
||
- (NSAttributedString *)createNobleLevelAttribute:(AttachmentModel *)attachment {
|
||
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) {/// 开通贵族房内消息 851
|
||
[attribute appendAttributedString:[self createTextAttribute:@"贵族降临!恭喜" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%@(%@)", attachment.data[@"nick"], attachment.data[@"erbanNo"]] color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"开通贵族系统,获得" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"currVipName"] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"贵族身份!" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_Room_Noble_LevelUp || attachment.second == Custom_Message_Sub_AllRoom_Noble_LevelUp_Suspend) {///贵族升级
|
||
[attribute appendAttributedString:[self createTextAttribute:@"全场欢呼!!恭喜" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"nick"] color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"的贵族身份成功升级为" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"currVipName"] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"!" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
[self attributeAddHihtLight:attribute uid:uid];
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 塔罗
|
||
- (NSAttributedString *)createTarotAttribute:(AttachmentModel *)attachment {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
if (attachment.second == Custom_Message_Sub_Tarot) {
|
||
[attribute appendAttributedString:[self createTextAttribute:@"恭喜" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:attachment.data[@"nick"] color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
NSString *text = [NSString stringWithFormat:@" %@", attachment.data[@"drawMsgText"]];
|
||
[attribute appendAttributedString:[self createTextAttribute:text color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
if ([attachment.data[@"drawGoldNum"] intValue] > 1) {
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%d",[attachment.data[@"drawGoldNum"] intValue]] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%@ ", attachment.data[@"chargeProdName"]] color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 个播粉丝团
|
||
- (NSAttributedString *)createAnchorFansTeamAttribute:(AttachmentModel *)attachment {
|
||
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 = @"您";
|
||
}
|
||
if (attachment.second == Custom_Message_Sub_FansTeam_Open_Success) {/// 开通粉丝团成功
|
||
[attribute appendAttributedString:[self createTextAttribute:@"恭喜" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nickName color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"开通粉丝团成功" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_FansTeam_Join_Success) {///加入粉丝团
|
||
[attribute appendAttributedString:[self createTextAttribute:@"恭喜" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nickName color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"加入粉丝团" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if (attachment.second == Custom_Message_Sub_FansTeam_Out_Success) {//退出粉丝团
|
||
[attribute appendAttributedString:[self createTextAttribute:nickName color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"已退出粉丝团" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
[self attributeAddHihtLight:attribute uid:uid];
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 踢出房间/拉黑/下麦
|
||
- (NSAttributedString *)createKickUserAttribute:(AttachmentModel *)attachment info:(XPKickUserModel *)info {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
[attribute appendAttributedString:[self createNickAtrribute:info.targetNick uid:info.targetUid]];
|
||
[attribute appendAttributedString:[self createTextAttribute:@"被" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createNickAtrribute:info.handleNick uid:info.handleUid]];
|
||
NSString * content= @"";
|
||
if (attachment.second == Custom_Message_Sub_Kick_BeKicked || attachment.second == Custom_Message_Sub_Hall_Super_Admin_Kick_Manager_Out_Room) {
|
||
content = @"请出房间";
|
||
} else if(attachment.second == Custom_Message_Sub_Kick_BlackList) {
|
||
content = @"关进小黑屋";
|
||
} else if(attachment.second == Custom_Message_Sub_Queue_Kick) {
|
||
content = @"请下麦";
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:content color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
return attribute;
|
||
}
|
||
|
||
|
||
#pragma mark - 分享房间
|
||
- (NSAttributedString *)createShareOrAttentionRoomAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo uid:(NSString *)uid {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
NSDictionary *data = attachment.data[@"data"];
|
||
NSString *nick = [NSString stringWithFormat:@"%@",data[@"nick"]];
|
||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
NSString *tipString = @"";
|
||
if (attachment.second == Custom_Message_Sub_Room_Tip_ShareRoom) {
|
||
tipString = @"分享了房间";
|
||
}else if (attachment.second == Custom_Message_Sub_Room_Tip_Attention_Owner) {
|
||
tipString = @"关注了房主";
|
||
}
|
||
[attribute appendAttributedString:[self createTextAttribute:tipString color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[self attributeAddHihtLight:attribute uid:uid.integerValue];
|
||
return attribute;
|
||
}
|
||
|
||
#pragma mark - 送礼物的公屏
|
||
- (NSAttributedString *)createBatchMicroSendGiftAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo {
|
||
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];
|
||
}
|
||
///官方新用户
|
||
[attribute appendAttributedString:[self createOfficalAndNewuserAttribute:sendInfo.defUser newUser:sendInfo.newUser]];
|
||
//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:@" 打赏 " color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
for (int i = 0; i < info.targetUsers.count; i++) {
|
||
GiftReceiveUserInfoModel *targetInfo = [info.targetUsers objectAtIndex: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:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
}
|
||
} else {
|
||
//打赏
|
||
[attribute appendAttributedString:[self createTextAttribute:@" 全麦打赏 " color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
//img
|
||
if (giftInfo.giftUrl) {
|
||
[attribute appendAttributedString:[self createUrlImageAttribute:giftInfo.giftUrl]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
|
||
//x N
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",info.giftNum] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
} else if(attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend) {///福袋礼物
|
||
//action
|
||
NSString * sendTitle = @" 送出 ";
|
||
if (attachment.second == Custom_Message_Sub_AllMicroLuckySend) {
|
||
sendTitle = @" 全麦送出 ";
|
||
}
|
||
//打赏
|
||
[attribute appendAttributedString:[self createTextAttribute:sendTitle color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
|
||
// 福袋名称
|
||
[attribute appendAttributedString:[self createTextAttribute:info.giftName color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
|
||
// 福袋名称
|
||
[attribute appendAttributedString:[self createTextAttribute:@" 给 " color:[ThemeColor 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:@" 爆出了 " color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
|
||
[info.luckyGiftList.giftList enumerateObjectsUsingBlock:^(GiftListsInfo * _Nonnull giftListInfo, NSUInteger idx, BOOL * _Nonnull stop) {
|
||
GiftInfoModel *luckGiftInfo = [[XPGiftStorage shareStorage] findGiftInfo:[NSString stringWithFormat:@"%ld", giftListInfo.giftId]];
|
||
// 价值
|
||
[attribute appendAttributedString:[self createTextAttribute:@"价值" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
// 礼物价格
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%ld",(NSInteger)luckGiftInfo.goldPrice] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
// 的礼物
|
||
[attribute appendAttributedString:[self createTextAttribute:@"钻石的礼物" color:[ThemeColor 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:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
if (info.luckyGiftList.giftList.count-1 != idx) {
|
||
//,
|
||
[attribute appendAttributedString:[self createTextAttribute:@"," color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}];
|
||
}
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
- (NSAttributedString *)createSendGiftAttribute:(AttachmentModel *)attachment sendInfo:(XPMessageRemoteExtModel *)sendInfo {
|
||
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];
|
||
}
|
||
///官方新用户
|
||
[attribute appendAttributedString:[self createOfficalAndNewuserAttribute:sendInfo.defUser newUser:sendInfo.newUser]];
|
||
//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:@"送出" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
// 福袋名称
|
||
[attribute appendAttributedString:[self createTextAttribute:info.giftName color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
|
||
[attribute appendAttributedString:[self createTextAttribute:@"给" color:[ThemeColor 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:@"爆出了" color:[ThemeColor 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]];
|
||
// 价值
|
||
[attribute appendAttributedString: [self createTextAttribute:@"价值" color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
// 礼物价格
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%ld",(NSInteger)luckyGiftInfo.goldPrice] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
// 的礼物
|
||
[attribute appendAttributedString: [self createTextAttribute:@"钻石的礼物" color:[ThemeColor 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:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
if (info.luckyGiftList.giftList.count-1 != idx) {
|
||
//,
|
||
[attribute appendAttributedString: [self createTextAttribute:@"," color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
}];
|
||
} else {
|
||
//打赏
|
||
[attribute appendAttributedString:[self createTextAttribute:@" 打赏 " color:[ThemeColor 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]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
//x N
|
||
[attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@" X%ld",info.giftNum] color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
#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 {
|
||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||
//offical
|
||
if (levelType == UserLevelType_Offical) {
|
||
[attribute appendAttributedString: [self createLocalImageAttribute:@"common_offical"]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
if (newUser) {
|
||
[attribute appendAttributedString: [self createLocalImageAttribute:@"common_new_user"]];
|
||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||
}
|
||
return attribute;
|
||
}
|
||
|
||
///名字点击的
|
||
- (NSMutableAttributedString *)createNickAtrribute:(NSString *)nick uid:(NSInteger)uid {
|
||
NSMutableAttributedString * attribute = [self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont];
|
||
[self attributeAddHihtLight:attribute uid:uid];
|
||
return attribute;
|
||
}
|
||
|
||
- (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];
|
||
[[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;
|
||
*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;
|
||
XPUserCardViewController * userCardVC = [[XPUserCardViewController alloc] initWithUser:model];
|
||
[self.hostDelegate.getCurrentNav presentViewController:userCardVC animated:YES completion:nil];
|
||
}
|
||
|
||
#pragma mark - private base methods
|
||
///铭牌
|
||
- (NSMutableAttributedString *)createNameplateAttibute:(NSString *)tagName image:(NSString *)imageName textFont:(UIFont *)textFont {
|
||
NetImageConfig *config = [[NetImageConfig alloc]init];
|
||
///先这样吧
|
||
config.autoLoad = YES;
|
||
NetImageView *imageView = [[NetImageView alloc]initWithUrl:imageName config:config];
|
||
UIImage* image = imageView.image;
|
||
if (image) {
|
||
CGFloat scale = image.size.width / image.size.height;
|
||
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
|
||
} else {
|
||
NSURL *imgUrl = [NSURL URLWithString:imageName];
|
||
UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]];
|
||
CGFloat scale = myImage.size.width / myImage.size.height;
|
||
if (scale == 0) {
|
||
imageView.bounds = CGRectMake(0, 0, 60, 20);
|
||
}else {
|
||
imageView.bounds = CGRectMake(0, 0, 20* scale, 20);
|
||
}
|
||
}
|
||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||
// 铭牌文字
|
||
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.left.mas_equalTo(27);
|
||
make.right.mas_equalTo(-8);
|
||
make.centerY.mas_equalTo(0);
|
||
}];
|
||
NSMutableAttributedString *string = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.bounds.size alignToFont:[UIFont boldSystemFontOfSize:12] 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, 20 * scale, 20);
|
||
} else {
|
||
imageView.bounds = CGRectMake(0, 0, 20, 20);
|
||
}
|
||
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:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||
return attrString;
|
||
}
|
||
|
||
|
||
/// 生成本地一个图片的富文本
|
||
/// @param imageName 网络图片的地址
|
||
- (NSMutableAttributedString *)createLocalImageAttribute:(NSString *)imageName {
|
||
if (imageName == nil && imageName.length <= 0) {
|
||
return nil;
|
||
}
|
||
return [self createImageAttribute:[UIImage imageNamed:imageName]];
|
||
}
|
||
|
||
/// 生成本地一个图片的富文本
|
||
/// @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, 20 * scale, 20);
|
||
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imaveView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imaveView.frame.size.width, imaveView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] 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 = NSTextAlignmentLeft;
|
||
paraStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
||
return paraStyle;
|
||
}
|
||
|
||
/// 占位的富文本
|
||
/// @param width 需要的间隙
|
||
- (NSMutableAttributedString *)createSapceAttribute:(CGFloat)width {
|
||
UIView *spaceView = [[UIView alloc]init];
|
||
spaceView.backgroundColor = [UIColor clearColor];
|
||
spaceView.bounds = CGRectMake(0, 0, width, 10);
|
||
NSMutableAttributedString * attribute = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(spaceView.frame.size.width, spaceView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||
return attribute;
|
||
}
|
||
|
||
@end
|