|
|
|
@@ -22,6 +22,7 @@
|
|
|
|
|
#import "UIView+Corner.h"
|
|
|
|
|
#import "Api+Room.h"
|
|
|
|
|
#import "XCCurrentVCStackManager.h"
|
|
|
|
|
#import "Api+UserCard.h"
|
|
|
|
|
///Model
|
|
|
|
|
#import "XPMessageRemoteExtModel.h"
|
|
|
|
|
#import "AttachmentModel.h"
|
|
|
|
@@ -45,6 +46,7 @@
|
|
|
|
|
#import "XPMessageInfoModel.h"
|
|
|
|
|
#import "XPStarredKitchenModel.h"
|
|
|
|
|
#import "NetImageView.h"
|
|
|
|
|
#import "XPRoomWelcomeModel.h"
|
|
|
|
|
|
|
|
|
|
#import "XPUserCardViewController.h"
|
|
|
|
|
#import "XPRoomTopicAlertView.h"
|
|
|
|
@@ -131,7 +133,7 @@
|
|
|
|
|
} else if (first == CustomMessageType_Starred_Kitchen) {
|
|
|
|
|
return [self createStarredKitchenAttribute:attachment messageInfo:messageInfo];
|
|
|
|
|
} else if (first == CustomMessageType_Room_Welcome && attachment.second == Custom_Message_Sub_Room_Welcome) {
|
|
|
|
|
return [self createWelcomeAttribute:attachment messageInfo:messageInfo];
|
|
|
|
|
return [self createWelcomeAttribute:message messageInfo:messageInfo];
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
@@ -296,22 +298,53 @@
|
|
|
|
|
if (code == 200) {
|
|
|
|
|
NSDictionary *dataDcit = data.data;
|
|
|
|
|
NSString *msg = dataDcit[@"msg"];
|
|
|
|
|
|
|
|
|
|
UserInfoModel *userInfo = [self.hostDelegate getUserInfo];
|
|
|
|
|
//设置ext
|
|
|
|
|
XPMessageRemoteExtModel * extModel = [[XPMessageRemoteExtModel alloc] init];
|
|
|
|
|
extModel.defUser = userInfo.defUser;
|
|
|
|
|
extModel.erbanNo = userInfo.erbanNo;
|
|
|
|
|
extModel.carName = userInfo.carName;
|
|
|
|
|
extModel.inRoomNameplatePic = userInfo.nameplatePic;
|
|
|
|
|
extModel.inRoomNameplateWord = userInfo.nameplateWord;
|
|
|
|
|
extModel.charmUrl = userInfo.userLevelVo.charmUrl;
|
|
|
|
|
extModel.experLevelSeq = userInfo.userLevelVo.experLevelSeq;
|
|
|
|
|
extModel.experUrl = userInfo.userLevelVo.experUrl;
|
|
|
|
|
extModel.newUser = userInfo.newUser;
|
|
|
|
|
extModel.vipIcon = userInfo.userVipInfoVO.vipIcon;
|
|
|
|
|
extModel.fromUid = userInfo.fromUid;
|
|
|
|
|
extModel.fromType = userInfo.fromType;
|
|
|
|
|
extModel.fromNick = userInfo.fromNick;
|
|
|
|
|
extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
|
|
|
|
|
extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
|
|
|
|
|
extModel.enterHide = userInfo.userVipInfoVO.enterHide;
|
|
|
|
|
extModel.preventKick = userInfo.userVipInfoVO.preventKick;
|
|
|
|
|
extModel.enterRoomEffects = userInfo.userVipInfoVO.enterRoomEffects;
|
|
|
|
|
extModel.gender = userInfo.gender;
|
|
|
|
|
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
|
|
|
|
|
extModel.platformRole = userInfo.platformRole;
|
|
|
|
|
|
|
|
|
|
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
|
|
|
|
|
|
|
|
|
|
/// 发动欢迎消息
|
|
|
|
|
AttachmentModel * attachment = [[AttachmentModel alloc] init];
|
|
|
|
|
attachment.first = CustomMessageType_Room_Welcome;
|
|
|
|
|
attachment.second = Custom_Message_Sub_Room_Welcome;
|
|
|
|
|
NSDictionary * dic = @{@"targetUid": toUid,
|
|
|
|
|
@"targetNick": nick,
|
|
|
|
|
@"content":msg ? msg : @"",
|
|
|
|
|
@"isFans":dataDcit[@"isFans"]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
XPRoomWelcomeModel *welcomeModel = [[XPRoomWelcomeModel alloc] init];
|
|
|
|
|
welcomeModel.targetUid = toUid;
|
|
|
|
|
welcomeModel.targetNick = nick;
|
|
|
|
|
welcomeModel.content = msg ? msg : @"";
|
|
|
|
|
welcomeModel.isFans = dataDcit[@"isFans"];
|
|
|
|
|
NSDictionary *dic = [welcomeModel model2dictionary];
|
|
|
|
|
attachment.data = dic;
|
|
|
|
|
|
|
|
|
|
NIMMessage *message = [[NIMMessage alloc]init];
|
|
|
|
|
NIMCustomObject *object = [[NIMCustomObject alloc] init];
|
|
|
|
|
object.attachment = attachment;
|
|
|
|
|
message.messageObject = object;
|
|
|
|
|
message.text = msg;
|
|
|
|
|
message.remoteExt = ext;
|
|
|
|
|
message.text = [NSString stringWithFormat:@"欢迎%@",nick];
|
|
|
|
|
|
|
|
|
|
NSString *sessionId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
|
|
|
|
|
//构造会话
|
|
|
|
@@ -400,12 +433,78 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - 欢迎Ta
|
|
|
|
|
- (XPMessageInfoModel *)createWelcomeAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{
|
|
|
|
|
NSString *nickName = attachment.data[@"targetNick"];
|
|
|
|
|
NSString *uid = attachment.data[@"targetUid"];
|
|
|
|
|
//- (XPMessageInfoModel *)createWelcomeAttribute:(AttachmentModel *)attachment messageInfo:(XPMessageInfoModel *)messageInfo{
|
|
|
|
|
// NSString *nickName = attachment.data[@"targetNick"];
|
|
|
|
|
// NSString *uid = attachment.data[@"targetUid"];
|
|
|
|
|
// NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
// [attribute appendAttributedString:[self createTextAttribute:@"欢迎" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
// [attribute appendAttributedString:[self createNickAtrribute:nickName ? nickName : @"" uid:uid.integerValue]];
|
|
|
|
|
// messageInfo.content = attribute;
|
|
|
|
|
// return messageInfo;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
- (XPMessageInfoModel *)createWelcomeAttribute:(NIMMessage *)message messageInfo:(XPMessageInfoModel *)messageInfo{
|
|
|
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
|
|
|
messageInfo.isShowAvatar = YES;
|
|
|
|
|
messageInfo.uid = message.from;
|
|
|
|
|
NIMUser * user = [[NIMSDK sharedSDK].userManager userInfo:message.from];
|
|
|
|
|
if (user) {
|
|
|
|
|
|
|
|
|
|
messageInfo.avatarUrl = user.userInfo.avatarUrl.length > 0 ? user.userInfo.avatarUrl : user.userInfo.thumbAvatarUrl;
|
|
|
|
|
}
|
|
|
|
|
if (messageInfo.avatarUrl.length <= 0) {
|
|
|
|
|
NIMMessageChatroomExtension * ext = message.messageExt;
|
|
|
|
|
messageInfo.avatarUrl = ext.roomAvatar;
|
|
|
|
|
}
|
|
|
|
|
XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
|
|
|
|
|
messageInfo.bubbleImageUrl = [self parseMessageBubble:message];
|
|
|
|
|
NSString * nick = [NSString stringWithFormat:@"%@:", ((NIMMessageChatroomExtension *)message.messageExt).roomNickname];
|
|
|
|
|
if ([message.from isEqualToString:uid]) {
|
|
|
|
|
nick = @"我:";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
[attribute appendAttributedString:[self createTextAttribute:@"欢迎" color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
[attribute appendAttributedString:[self createNickAtrribute:nickName ? nickName : @"" uid:uid.integerValue]];
|
|
|
|
|
if (model.vipIcon) {//贵族icon
|
|
|
|
|
[attribute appendAttributedString:[self createUrlImageAttribute:model.vipIcon]];
|
|
|
|
|
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
|
|
|
|
}
|
|
|
|
|
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
[attribute appendAttributedString:[self createTextAttribute:@"\n" color:[UIColor clearColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
|
|
|
|
|
///官方新用户
|
|
|
|
|
[attribute appendAttributedString:[self createOfficalAndNewuserAttribute:model.defUser newUser:model.newUser fromSayHelloChannel:model.fromSayHelloChannel]];
|
|
|
|
|
if ([self isCurrentRoomSuperAdmin:message.from]) {
|
|
|
|
|
[attribute appendAttributedString:[self createLocalImageAttribute:@"common_super_admin"]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.experUrl) {
|
|
|
|
|
[attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]];
|
|
|
|
|
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.charmUrl) {
|
|
|
|
|
[attribute appendAttributedString:[self createUrlImageAttribute:model.charmUrl]];
|
|
|
|
|
[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:@"\n" color:[UIColor clearColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
|
|
|
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
|
|
|
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
|
|
|
|
|
XPRoomWelcomeModel *welcomeModel = [XPRoomWelcomeModel modelWithDictionary:attachment.data];
|
|
|
|
|
|
|
|
|
|
NSMutableAttributedString *msgStr = [self createWelcomeUrlImageAttribute:model.iosBubbleUrl toNick:welcomeModel.targetNick toUid:welcomeModel.targetUid.integerValue isFans:welcomeModel.isFans];
|
|
|
|
|
[attribute appendAttributedString:msgStr];
|
|
|
|
|
|
|
|
|
|
[self attributeAddLongPressHihtLight:attribute uid:message.from nick:((NIMMessageChatroomExtension *)message.messageExt).roomNickname];
|
|
|
|
|
attribute.yy_lineSpacing = 5;
|
|
|
|
|
messageInfo.content = attribute;
|
|
|
|
|
return messageInfo;
|
|
|
|
|
}
|
|
|
|
@@ -1244,6 +1343,67 @@
|
|
|
|
|
return attrString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 生成一个背景的图片 和文字
|
|
|
|
|
/// @param imageUrl 网络图片的地址 如果地址为空 那就显示默认背景
|
|
|
|
|
- (NSMutableAttributedString *)createWelcomeUrlImageAttribute:(NSString *)imageUrl toNick:(NSString *)toNick toUid:(NSInteger)toUid isFans:(BOOL)isFans {
|
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
|
|
|
NetImageView *imageView = [[NetImageView alloc]initWithUrl:imageUrl config:config];
|
|
|
|
|
imageView.tag = 1000;
|
|
|
|
|
NSString *welcomeText = @"欢迎";
|
|
|
|
|
NSString * fullText = [NSString stringWithFormat:@"%@%@",welcomeText,toNick];
|
|
|
|
|
NSMutableAttributedString * msgStr = [[NSMutableAttributedString alloc] init];
|
|
|
|
|
[msgStr appendAttributedString:[self createTextAttribute:welcomeText color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
|
|
|
|
[msgStr appendAttributedString:[self createNickAtrribute:toNick uid:toUid]];
|
|
|
|
|
|
|
|
|
|
NSString *uid = [AccountInfoStorage instance].getUid;
|
|
|
|
|
if (toUid == uid.integerValue && isFans == NO) {
|
|
|
|
|
// NSAttributedString *attention = [self createImageAttribute:[UIImage imageNamed:@"room_enter_greeting"] height:18];
|
|
|
|
|
// [msgStr appendAttributedString:attention];
|
|
|
|
|
// /// 关注事件
|
|
|
|
|
// [msgStr yy_setTextHighlightRange:NSMakeRange(msgStr.length-attention.length, attention.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
|
|
|
// NSString * uid = [[AccountInfoStorage instance] getUid];
|
|
|
|
|
// NSString * ticket = [[AccountInfoStorage instance] getTicket];
|
|
|
|
|
// NSString * type = @"1";
|
|
|
|
|
// [Api attentionCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
|
// if (code == 200) {
|
|
|
|
|
// //TODO: 关注成功更新消息内容
|
|
|
|
|
// }
|
|
|
|
|
// } uid:uid likedUid:[NSString stringWithFormat:@"%ld",toUid] ticket:ticket type:type];
|
|
|
|
|
//
|
|
|
|
|
// }];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 铭牌文字
|
|
|
|
|
UILabel *label = [[UILabel alloc] init];
|
|
|
|
|
label.textAlignment = NSTextAlignmentLeft;
|
|
|
|
|
label.font = [UIFont boldSystemFontOfSize:kRoomMessageDefalutFont];
|
|
|
|
|
label.adjustsFontSizeToFitWidth = YES;
|
|
|
|
|
label.numberOfLines = 0;
|
|
|
|
|
label.textColor = UIColor.whiteColor;
|
|
|
|
|
label.attributedText = msgStr;
|
|
|
|
|
[imageView addSubview:label];
|
|
|
|
|
[label mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.left.mas_equalTo(10);
|
|
|
|
|
make.right.mas_equalTo(-19);
|
|
|
|
|
make.top.mas_equalTo(10);
|
|
|
|
|
}];
|
|
|
|
|
CGFloat imageWidth;
|
|
|
|
|
CGFloat imageHeight;
|
|
|
|
|
CGSize size = [fullText boundingRectWithSize:CGSizeMake(kRoomMessageMaxWidth - 10 - 19 - 15 - 34 - 7, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont]} context:nil].size;
|
|
|
|
|
imageWidth = size.width + 10 + 19 + 5;
|
|
|
|
|
imageHeight = size.height + 20;
|
|
|
|
|
imageView.layer.masksToBounds = YES;
|
|
|
|
|
imageView.frame = CGRectMake(0, 0, imageWidth, imageHeight);
|
|
|
|
|
if (imageUrl.length > 0) {
|
|
|
|
|
imageView.imageUrl = imageUrl;
|
|
|
|
|
}else {
|
|
|
|
|
[imageView setCornerWithLeftTopCorner:4 rightTopCorner:11 bottomLeftCorner:11 bottomRightCorner:11 size:CGSizeMake(imageWidth, imageHeight)];
|
|
|
|
|
imageView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - tool
|
|
|
|
|
- (UIImage*)resizableImage:(UIImage *)image {
|
|
|
|
|
//图片拉伸区域
|
|
|
|
|