2021-11-04 16:27:39 +08:00
//
// XPRoomMessageParser . m
// xplan - ios
//
// Created by 冯 硕 on 2021 / 10 / 26.
//
# import "XPRoomMessageParser.h"
# import < YYText / YYText . h >
# import < NIMSDK / NIMSDK . h >
2021-12-17 15:18:34 +08:00
# import < Masonry / Masonry . h >
2021-11-04 16:27:39 +08:00
// / Tool
# import "ThemeColor+Room.h"
# import "XPRoomMessageConstant.h"
# import "AccountInfoStorage.h"
# import "XPMacro.h"
2021-11-17 19:29:14 +08:00
# import "XPGiftStorage.h"
2022-03-10 18:49:50 +08:00
# import "XPRoomFaceTool.h"
2022-03-15 15:03:26 +08:00
# import "TTPopup.h"
2022-10-21 18:03:00 +08:00
# import "Api+WishGift.h"
2022-11-11 17:46:37 +08:00
# import "NSArray+Safe.h"
2023-03-14 10:33:35 +08:00
# import "UIView+Corner.h"
2023-03-17 17:00:45 +08:00
# import "Api+Room.h"
2023-02-13 18:15:19 +08:00
# import "XCCurrentVCStackManager.h"
2023-03-23 18:59:41 +08:00
# import "Api+UserCard.h"
2021-11-04 16:27:39 +08:00
// / Model
# import "XPMessageRemoteExtModel.h"
2022-01-08 20:15:06 +08:00
# import "AttachmentModel.h"
2021-11-17 19:29:14 +08:00
# import "GiftReceiveInfoModel.h"
2021-11-26 17:31:12 +08:00
# import "XPKickUserModel.h"
2021-11-26 21:47:00 +08:00
# import "MicroQueueModel.h"
# import "UserInfoModel.h"
# import "MicroStateModel.h"
2021-12-13 19:44:15 +08:00
# import "RoomInfoModel.h"
2022-01-05 21:48:21 +08:00
# import "DatingInfoModel.h"
2022-03-10 18:49:50 +08:00
# import "RoomFaceInfoModel.h"
# import "RoomFaceSendInfoModel.h"
2022-04-18 22:36:16 +08:00
# import "GuildSuperAdminInfoModel.h"
2022-03-29 18:29:58 +08:00
# import "RoomPKChooseUserModel.h"
# import "RoomPKInfoModel.h"
2022-06-01 10:34:36 +08:00
# import "CandyTreeResultModel.h"
2022-06-15 14:20:09 +08:00
# import "XPGiftBigPrizeModel.h"
2022-08-05 15:38:21 +08:00
# import "XPGiftCompoundModel.h"
2022-08-19 17:42:14 +08:00
# import "RoomSailingPrizeModel.h"
2022-09-16 10:51:22 +08:00
# import "XPOpenRedPacketModel.h"
2022-10-21 18:03:00 +08:00
# import "XPMessageInfoModel.h"
2023-02-13 18:15:19 +08:00
# import "XPStarredKitchenModel.h"
2021-11-04 16:27:39 +08:00
# import "NetImageView.h"
2023-03-23 18:59:41 +08:00
# import "XPRoomWelcomeModel.h"
2021-11-04 16:27:39 +08:00
2021-11-26 21:47:00 +08:00
# import "XPUserCardViewController.h"
2022-03-15 15:03:26 +08:00
# import "XPRoomTopicAlertView.h"
2022-04-24 18:58:30 +08:00
# import "XPRoomSendTextView.h"
2022-05-27 18:24:13 +08:00
# import "XPRoomPKResultView.h"
2023-02-13 18:15:19 +08:00
# import "XPWebViewController.h"
2021-11-26 21:47:00 +08:00
2021-11-04 16:27:39 +08:00
@ implementation XPRoomMessageParser
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) parseMessageAttribute : ( NIMMessage * ) message {
2021-11-04 16:27:39 +08:00
NIMMessageType messageType = message . messageType ;
2022-10-21 18:03:00 +08:00
XPMessageInfoModel * messageInfo = [ [ XPMessageInfoModel alloc ] init ] ;
2021-11-04 16:27:39 +08:00
switch ( messageType ) {
case NIMMessageTypeText :
2022-10-21 18:03:00 +08:00
return [ self makeChatAttribute : message messageInfo : messageInfo ] ;
2021-11-04 16:27:39 +08:00
case NIMMessageTypeTip :
2022-10-21 18:03:00 +08:00
return [ self makeTipsAttribute : message messageInfo : messageInfo ] ;
2021-11-04 16:27:39 +08:00
case NIMMessageTypeNotification :
2022-10-21 18:03:00 +08:00
return [ self makeNotificationAttribute : message messageInfo : messageInfo ] ;
2021-11-17 19:29:14 +08:00
case NIMMessageTypeCustom :
2022-10-21 18:03:00 +08:00
return [ self makeCustomAttribute : message messageInfo : messageInfo ] ;
2021-11-04 16:27:39 +08:00
default :
return nil ;
}
}
2022-03-21 15:52:33 +08:00
- ( NSString * ) parseMessageBubble : ( NIMMessage * ) message {
XPMessageRemoteExtModel * model = [ XPMessageRemoteExtModel modelWithJSON : message . remoteExt [ message . from ] ] ;
return model . iosBubbleUrl ? model . iosBubbleUrl : @ "" ;
}
2021-11-04 16:27:39 +08:00
// / 用 户 公 屏 聊 天
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) makeCustomAttribute : ( NIMMessage * ) message messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-17 19:29:14 +08:00
NIMCustomObject * obj = ( NIMCustomObject * ) message . messageObject ;
AttachmentModel * attachment = ( AttachmentModel * ) obj . attachment ;
XPMessageRemoteExtModel * model = [ XPMessageRemoteExtModel modelWithJSON : message . remoteExt [ message . from ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . bubbleImageUrl = [ self parseMessageBubble : message ] ;
2021-11-17 19:29:14 +08:00
int first = attachment . first ;
if ( first = = CustomMessageType_Gift ) { // / 单 人 送
2022-10-21 18:03:00 +08:00
return [ self createSendGiftAttribute : attachment sendInfo : model messageInfo : messageInfo ] ;
2021-12-06 17:00:15 +08:00
} else if ( first = = CustomMessageType_AllMicroSend ) { // / 全 麦 送 多 人 送
2022-10-21 18:03:00 +08:00
return [ self createBatchMicroSendGiftAttribute : attachment sendInfo : model messageInfo : messageInfo ] ;
2021-11-24 14:58:53 +08:00
} else if ( first = = CustomMessageType_Room _Tip ) { // / 分 享 / 收 藏 房 间
2022-10-21 18:03:00 +08:00
return [ self createShareOrAttentionRoomAttribute : attachment sendInfo : model uid : message . from messageInfo : messageInfo ] ;
2021-11-26 21:47:00 +08:00
} else if ( first = = CustomMessageType_Kick _User || first = = CustomMessageType_Queue ) {
2021-11-26 17:31:12 +08:00
XPKickUserModel * kickModel = [ XPKickUserModel modelWithJSON : attachment . data ] ;
2022-10-21 18:03:00 +08:00
return [ self createKickUserAttribute : attachment info : kickModel messageInfo : messageInfo ] ;
2022-06-16 16:12:57 +08:00
} else if ( first = = CustomMessageType_Candy _Tree ) { // 糖 果 树
2022-10-21 18:03:00 +08:00
return [ self createCandyTreeHighLevelAttribute : attachment messageInfo : messageInfo ] ;
2021-12-20 21:17:12 +08:00
} else if ( first = = CustomMessageType_Arrange _Mic ) {
2022-10-21 18:03:00 +08:00
return [ self createArrangeMicAttribute : attachment messageInfo : messageInfo ] ;
2021-12-25 16:57:50 +08:00
} else if ( first = = CustomMessageType_Update _RoomInfo ) {
2022-10-21 18:03:00 +08:00
return [ self createRoomInfoUpdateAttribute : attachment messageInfo : messageInfo ] ;
2021-12-27 16:40:14 +08:00
} else if ( first = = CustomMessageType_Collection _Room ) {
2022-10-21 18:03:00 +08:00
return [ self createCollectRoomAttribute : attachment messageInfo : messageInfo ] ;
2022-01-05 21:48:21 +08:00
} else if ( first = = CustomMessageType_RoomPlay _Dating ) {
2022-10-21 18:03:00 +08:00
return [ self createRoomDatingAttribute : attachment messageInfo : messageInfo ] ;
2022-01-10 19:59:58 +08:00
} else if ( first = = CustomMessageType_Noble _VIP ) { // 贵 族
2022-10-21 18:03:00 +08:00
return [ self createNobleLevelAttribute : attachment messageInfo : messageInfo ] ;
2022-03-10 18:49:50 +08:00
} else if ( first = = CustomMessageType_Face ) { // 贵 族
2022-10-21 18:03:00 +08:00
return [ self createRoomFaceAttribute : attachment messageInfo : messageInfo ] ;
2022-03-23 11:25:53 +08:00
} else if ( first = = CustomMessageType_Tarot ) { // 塔 罗
2022-10-21 18:03:00 +08:00
return [ self createTarotAttribute : attachment messageInfo : messageInfo ] ;
2022-04-08 15:42:25 +08:00
} else if ( first = = CustomMessageType_Anchor _FansTeam ) { // 粉 丝 团
2022-10-21 18:03:00 +08:00
return [ self createAnchorFansTeamAttribute : attachment messageInfo : messageInfo ] ;
2022-04-26 21:45:40 +08:00
} else if ( first = = CustomMessageType_Hall _Super _Admin ) { // / 超 管 踢 人 出 房 间
XPKickUserModel * kickModel = [ XPKickUserModel modelWithJSON : attachment . data ] ;
2022-10-21 18:03:00 +08:00
return [ self createKickUserAttribute : attachment info : kickModel messageInfo : messageInfo ] ;
2022-03-29 18:29:58 +08:00
} else if ( first = = CustomMessageType_Room _PK ) { // / 房 内 PK
2022-10-21 18:03:00 +08:00
return [ self createRoomPKAttribute : attachment messageInfo : messageInfo ] ;
2022-06-15 14:20:09 +08:00
} else if ( first = = CustomMessageType_LuckyBag ) { // / 幸 运 礼 物
2022-10-21 18:03:00 +08:00
return [ self createRoomLuckyBigPrizeAttribute : attachment messageInfo : messageInfo ] ;
2022-08-05 15:38:21 +08:00
} else if ( first = = CustomMessageType_Gift _Compound ) { // / 礼 物 合 成
2022-10-21 18:03:00 +08:00
return [ self createRoomGiftCompoundAttribute : attachment messageInfo : messageInfo ] ;
2022-08-19 17:42:14 +08:00
} else if ( first = = CustomMessageType_Room _Sailing ) { // / 航 海
2022-10-21 18:03:00 +08:00
return [ self createRoomSailingAttribute : attachment messageInfo : messageInfo ] ;
2022-09-16 10:51:22 +08:00
} else if ( first = = CustomMessageType_RedPacket && attachment . second = = Custom_Message _Sub _OpenRedPacketSuccess ) {
2022-10-21 18:03:00 +08:00
return [ self createRedPacketAttribute : attachment messageInfo : messageInfo ] ;
2023-02-13 18:15:19 +08:00
} else if ( first = = CustomMessageType_Wish _Gift ) {
2022-10-21 18:03:00 +08:00
return [ self createWishGiftAttribute : attachment messageInfo : messageInfo ] ;
2023-02-13 18:15:19 +08:00
} else if ( first = = CustomMessageType_Starred _Kitchen ) {
return [ self createStarredKitchenAttribute : attachment messageInfo : messageInfo ] ;
2023-03-22 17:47:32 +08:00
} else if ( first = = CustomMessageType_Room _Welcome && attachment . second = = Custom_Message _Sub _Room _Welcome ) {
2023-03-23 18:59:41 +08:00
return [ self createWelcomeAttribute : message messageInfo : messageInfo ] ;
2023-03-22 17:47:32 +08:00
}
2021-11-17 19:29:14 +08:00
return nil ;
}
2021-11-04 16:27:39 +08:00
// / @ param message 消 息 的 实 体
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) makeChatAttribute : ( NIMMessage * ) message messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-04 16:27:39 +08:00
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
2023-03-14 18:29:52 +08:00
messageInfo . isShowAvatar = YES ;
2023-03-15 18:01:28 +08:00
messageInfo . uid = message . from ;
2023-03-14 18:29:52 +08:00
NIMUser * user = [ [ NIMSDK sharedSDK ] . userManager userInfo : message . from ] ;
if ( user ) {
2023-03-16 18:04:36 +08:00
2023-03-14 18:29:52 +08:00
messageInfo . avatarUrl = user . userInfo . avatarUrl . length > 0 ? user . userInfo . avatarUrl : user . userInfo . thumbAvatarUrl ;
}
2023-03-16 18:04:36 +08:00
if ( messageInfo . avatarUrl . length <= 0 ) {
NIMMessageChatroomExtension * ext = message . messageExt ;
messageInfo . avatarUrl = ext . roomAvatar ;
}
2021-11-04 16:27:39 +08:00
XPMessageRemoteExtModel * model = [ XPMessageRemoteExtModel modelWithJSON : message . remoteExt [ message . from ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . bubbleImageUrl = [ self parseMessageBubble : message ] ;
2021-11-04 16:27:39 +08:00
NSString * nick = [ NSString stringWithFormat : @ "%@:" , ( ( NIMMessageChatroomExtension * ) message . messageExt ) . roomNickname ] ;
if ( [ message . from isEqualToString : uid ] ) {
nick = @ "我:" ;
}
2022-06-07 16:16:27 +08:00
2021-11-04 16:27:39 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2023-03-16 18:04:36 +08:00
if ( model . vipIcon ) { // 贵 族 icon
2023-07-31 11:37:19 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . vipIcon size : CGSizeMake ( 26 , 26 ) ] ] ;
2023-03-16 18:04:36 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2023-03-14 10:33:35 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "\n" color : [ UIColor clearColor ] font : kRoomMessageDefalutFont ] ] ;
2022-06-07 16:16:27 +08:00
// / 官 方 新 用 户
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : model . defUser newUser : model . newUser fromSayHelloChannel : model . fromSayHelloChannel ] ] ;
2022-04-18 22:36:16 +08:00
if ( [ self isCurrentRoomSuperAdmin : message . from ] ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_super_admin" ] ] ;
}
2023-03-14 10:33:35 +08:00
if ( model . experUrl ) {
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . experUrl ] ] ;
2023-03-14 10:33:35 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2023-03-16 18:04:36 +08:00
if ( model . charmUrl ) {
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . charmUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2022-01-13 15:47:36 +08:00
if ( model . inRoomNameplatePic . length > 0 && model . inRoomNameplateWord . length > 0 ) { // 铭 牌 有 图 片 加 文 字
2021-12-17 15:18:34 +08:00
[ attribute appendAttributedString : [ self createNameplateAttibute : model . inRoomNameplateWord image : model . inRoomNameplatePic textFont : [ UIFont systemFontOfSize : 9 ] ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
2023-03-14 10:33:35 +08:00
} else if ( model . inRoomNameplatePic . length > 0 ) { // 铭 牌 只 有 图 片
2023-07-31 11:37:19 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . inRoomNameplatePic size : CGSizeMake ( 18 , 18 ) ] ] ;
2023-03-14 10:33:35 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
[ attribute appendAttributedString : [ self createTextAttribute : @ "\n" color : [ UIColor clearColor ] font : kRoomMessageDefalutFont ] ] ;
2022-04-24 18:58:30 +08:00
id nickNameNifo = message . remoteExt [ @ "atNames" ] ;
NSMutableAttributedString * msgStr ;
if ( message . text ) {
2023-03-16 18:04:36 +08:00
msgStr = [ self createUrlImageAttribute : model . iosBubbleUrl text : message . text nickNameNifo : nickNameNifo ] ;
2023-03-14 18:29:52 +08:00
[ attribute appendAttributedString : msgStr ] ;
2022-04-24 18:58:30 +08:00
}
[ self attributeAddLongPressHihtLight : attribute uid : message . from nick : ( ( NIMMessageChatroomExtension * ) message . messageExt ) . roomNickname ] ;
2023-03-14 18:29:52 +08:00
attribute . yy_lineSpacing = 5 ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-04 16:27:39 +08:00
}
// / 房 间 tips 消 息
// / @ param message 消 息 的 实 体
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) makeTipsAttribute : ( NIMMessage * ) message messageInfo : ( XPMessageInfoModel * ) messageInfo {
messageInfo . bubbleImageUrl = [ self parseMessageBubble : message ] ;
2022-03-15 15:03:26 +08:00
if ( [ message . localExt . allKeys containsObject : @ "isRoomTopic" ] ) {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2022-10-21 18:03:00 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : message . text color : [ UIColor whiteColor ] font : kRoomMessageDefalutFont ] ] ;
2022-03-15 15:03:26 +08:00
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 ] ;
2023-03-21 19:55:24 +08:00
config . maskBackgroundAlpha = 0 ;
2022-03-15 15:03:26 +08:00
XPRoomTopicAlertView * alertView = [ [ XPRoomTopicAlertView alloc ] init ] ;
alertView . title = roomInfo . roomDesc ;
alertView . message = roomInfo . introduction ;
config . contentView = alertView ;
[ TTPopup popupWithConfig : config ] ;
} ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
2022-03-15 15:03:26 +08:00
} else {
2022-10-21 18:03:00 +08:00
NSAttributedString * attribute = [ self createTextAttribute : message . text color : UIColorFromRGB ( 0 xFE5D7F ) font : kRoomMessageDefalutFont ] ;
messageInfo . content = attribute ;
2022-03-15 15:03:26 +08:00
}
2022-10-21 18:03:00 +08:00
return messageInfo ;
2021-11-04 16:27:39 +08:00
}
// / 房 间 通 知 类 消 息
// / @ param message 消 息 的 实 体
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) makeNotificationAttribute : ( NIMMessage * ) message messageInfo : ( XPMessageInfoModel * ) messageInfo {
messageInfo . bubbleImageUrl = [ self parseMessageBubble : message ] ;
2021-11-04 16:27:39 +08:00
NIMNotificationObject * notiMsg = ( NIMNotificationObject * ) message . messageObject ;
NIMChatroomNotificationContent * content = ( NIMChatroomNotificationContent * ) notiMsg . content ;
NIMChatroomNotificationMember * member = content . targets [ 0 ] ;
2021-12-16 20:22:01 +08:00
NIMMessageChatroomExtension * messageExt = ( NIMMessageChatroomExtension * ) message . messageExt ;
2021-11-04 16:27:39 +08:00
switch ( content . eventType ) {
case NIMChatroomEventTypeEnter : // / 进 入 房 间
{
NSString * nick = member . nick . length > 0 ? member . nick : @ "" ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2021-12-16 20:22:01 +08:00
NSDictionary * dic = [ ( NSDictionary * ) messageExt . roomExt . toJSONObject objectForKey : message . from ] ;
2021-12-17 15:18:34 +08:00
XPMessageRemoteExtModel * extModel = [ XPMessageRemoteExtModel modelWithDictionary : dic ] ;
2022-06-07 16:16:27 +08:00
// / 官 方 新 用 户
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : extModel . defUser newUser : extModel . newUser fromSayHelloChannel : extModel . fromSayHelloChannel ] ] ;
2022-04-26 21:49:25 +08:00
if ( [ self isCurrentRoomSuperAdmin : message . from ] ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_super_admin" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2022-01-13 15:47:36 +08:00
if ( extModel . vipIcon . length > 0 ) { // 贵 族 icon
2023-07-31 11:37:19 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : extModel . vipIcon size : CGSizeMake ( 26 , 26 ) ] ] ;
2022-01-13 15:47:36 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
if ( extModel . experUrl . length > 0 ) { // 等 级
[ attribute appendAttributedString : [ self createUrlImageAttribute : extModel . experUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2021-12-17 15:18:34 +08:00
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 ] ] ;
}
2022-03-15 17:56:25 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : nick uid : message . from . integerValue ] ] ;
2021-12-16 20:22:01 +08:00
if ( extModel . carName . length > 0 ) {
2022-03-15 17:56:25 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 驾着 " color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-16 20:22:01 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : extModel . carName color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2022-03-15 17:56:25 +08:00
if ( extModel . fromType > 0 ) {
if ( extModel . fromType = = UserEnterRoomFromType_Home _Recommend ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "根据首页推荐" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-06-07 16:16:27 +08:00
} else if ( extModel . fromType = = UserEnterRoomFromType_Follow _User || extModel . fromType = = UserEnterRoomFromType_New _User _Greet ) {
2022-03-15 17:56:25 +08:00
[ 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 ] ] ;
2023-03-17 17:00:45 +08:00
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
NSString * toUid = member . userId ;
RoomInfoModel * roomInfo = self . hostDelegate . getRoomInfo ;
// / 如 果 是 房 主 , 并 且 不 是 自 己 进 房 消 息 , 添 加 欢 迎 TA
if ( roomInfo . uid = = [ uid integerValue ] && ! [ uid isEqualToString : toUid ] ) {
2023-03-20 19:34:34 +08:00
NSAttributedString * welcome = [ self createImageAttribute : [ UIImage imageNamed : @ "room_enter_greeting" ] height : 18 ] ;
2023-03-17 17:00:45 +08:00
[ attribute appendAttributedString : welcome ] ;
[ attribute yy_setTextHighlightRange : NSMakeRange ( attribute . length - welcome . length , welcome . length ) color : nil backgroundColor : nil tapAction : ^ ( UIView * _Nonnull containerView , NSAttributedString * _Nonnull text , NSRange range , CGRect rect ) {
// / 请 求 欢 迎 消 息 内 容
[ Api requestMsgGetone : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
if ( code = = 200 ) {
NSDictionary * dataDcit = data . data ;
NSString * msg = dataDcit [ @ "msg" ] ;
2023-03-23 18:59:41 +08:00
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 ] ] ;
2023-03-22 17:47:32 +08:00
// / 发 动 欢 迎 消 息
AttachmentModel * attachment = [ [ AttachmentModel alloc ] init ] ;
attachment . first = CustomMessageType_Room _Welcome ;
attachment . second = Custom_Message _Sub _Room _Welcome ;
2023-03-23 18:59:41 +08:00
XPRoomWelcomeModel * welcomeModel = [ [ XPRoomWelcomeModel alloc ] init ] ;
welcomeModel . targetUid = toUid ;
welcomeModel . targetNick = nick ;
welcomeModel . content = msg ? msg : @ "" ;
welcomeModel . isFans = dataDcit [ @ "isFans" ] ;
NSDictionary * dic = [ welcomeModel model2dictionary ] ;
2023-03-22 17:47:32 +08:00
attachment . data = dic ;
NIMMessage * message = [ [ NIMMessage alloc ] init ] ;
NIMCustomObject * object = [ [ NIMCustomObject alloc ] init ] ;
object . attachment = attachment ;
message . messageObject = object ;
2023-03-23 18:59:41 +08:00
message . remoteExt = ext ;
message . text = [ NSString stringWithFormat : @ "欢迎%@" , nick ] ;
2023-03-22 17:47:32 +08:00
NSString * sessionId = [ NSString stringWithFormat : @ "%ld" , roomInfo . roomId ] ;
// 构 造 会 话
NIMSession * session = [ NIMSession session : sessionId type : NIMSessionTypeChatroom ] ;
[ [ NIMSDK sharedSDK ] . chatManager sendMessage : message toSession : session completion : ^ ( NSError * _Nullable error ) {
} ] ;
2023-03-17 17:00:45 +08:00
}
} uid : uid toUid : toUid ] ;
} ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-04 16:27:39 +08:00
}
2021-12-25 16:57:50 +08:00
break ;
2022-01-05 21:48:21 +08:00
case NIMChatroomEventTypeInfoUpdated : {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2022-01-17 18:57:34 +08:00
if ( self . hostDelegate . getRoomInfo . datingState = = RoomDatingStateChangeType_Open ) {
2022-01-05 21:48:21 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "相亲玩法已开启,请点击主持人麦位选择主持人" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-01-05 21:48:21 +08:00
}
}
break ;
2021-11-04 16:27:39 +08:00
default :
return nil ;
}
2022-01-05 21:48:21 +08:00
return nil ;
2021-11-04 16:27:39 +08:00
}
2023-02-13 18:15:19 +08:00
# pragma mark - 星 级 厨 房
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createWishGiftAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
UIImageView * imaveView = [ [ UIImageView alloc ] init ] ;
imaveView . image = [ UIImage imageNamed : @ "room_wish_gift_mesage_finish" ] ;
imaveView . bounds = CGRectMake ( 0 , 0 , 170 , 34 ) ;
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 ] ;
@ kWeakify ( self ) ;
[ attrString yy_setTextHighlightRange : NSMakeRange ( 0 , attrString . length ) color : nil backgroundColor : nil tapAction : ^ ( UIView * _Nonnull containerView , NSAttributedString * _Nonnull text , NSRange range , CGRect rect ) {
@ kStrongify ( self ) ;
NSString * roomUid = [ NSString stringWithFormat : @ "%ld" , [ self . hostDelegate getRoomInfo ] . uid ] ;
[ Api wishGiftSendCelebrate : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
} roomUid : roomUid ] ;
} ] ;
messageInfo . contentLeftMargin = 0 ;
messageInfo . contentRightMargin = 0 ;
messageInfo . contentTopMargin = 0 ;
messageInfo . contentBottomMargin = 0 ;
messageInfo . isUpdateContentFrame = YES ;
messageInfo . isHiddenBubble = YES ;
messageInfo . content = attrString ;
return messageInfo ;
}
2023-02-13 18:15:19 +08:00
# pragma mark - 心 愿 礼 物
- ( XPMessageInfoModel * ) createStarredKitchenAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
XPStarredKitchenModel * giftInfo = [ XPStarredKitchenModel modelWithDictionary : attachment . data ] ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
CGFloat fontSize = 13 ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "恭喜" color : [ UIColor whiteColor ] font : fontSize ] ] ;
NSString * nick = giftInfo . nick ;
if ( nick . length > 6 ) {
nick = [ nick substringToIndex : 6 ] ;
}
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor colorWithHexString : @ "#FEF23E" ] font : fontSize ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "在深海奇缘抽中 " color : [ UIColor whiteColor ] font : fontSize ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%ld" , giftInfo . itemMultiple ] color : [ ThemeColor colorWithHexString : @ "#00EAFF" ] font : fontSize ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "倍奖励,获得" color : [ UIColor whiteColor ] font : fontSize ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " %ld" , giftInfo . diamonds ] color : [ ThemeColor colorWithHexString : @ "#00EAFF" ] font : fontSize ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "钻石" color : [ UIColor whiteColor ] font : fontSize ] ] ;
NSMutableParagraphStyle * paragraphStyle = [ NSMutableParagraphStyle new ] ;
paragraphStyle . lineBreakMode = NSLineBreakByCharWrapping ;
paragraphStyle . lineSpacing = 4.0 f ; // 行 间 距
paragraphStyle . baseWritingDirection = NSWritingDirectionLeftToRight ;
[ attribute addAttribute : NSParagraphStyleAttributeName value : paragraphStyle range : NSMakeRange ( 0 , attribute . length ) ] ;
@ 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 ( giftInfo && giftInfo . needLevel < self . hostDelegate . getUserInfo . userLevelVo . experLevelSeq && giftInfo . skipUrl . length > 0 ) {
XPWebViewController * webVC = [ [ XPWebViewController alloc ] init ] ;
webVC . url = giftInfo . skipUrl ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
}
} ] ;
messageInfo . content = attribute ;
return messageInfo ;
}
2023-03-22 17:47:32 +08:00
# pragma mark - 欢 迎 Ta
2023-03-23 18:59:41 +08:00
// - ( 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 = @ "我:" ;
}
2023-03-22 17:47:32 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2023-03-23 18:59:41 +08:00
if ( model . vipIcon ) { // 贵 族 icon
2023-07-31 11:37:19 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . vipIcon size : CGSizeMake ( 26 , 26 ) ] ] ;
2023-03-23 18:59:41 +08:00
[ 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 ) { // 铭 牌 只 有 图 片
2023-07-31 11:37:19 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . inRoomNameplatePic size : CGSizeMake ( 18 , 18 ) ] ] ;
2023-03-23 18:59:41 +08:00
[ 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 ;
2023-03-22 17:47:32 +08:00
messageInfo . content = attribute ;
return messageInfo ;
}
2022-09-16 10:51:22 +08:00
# pragma mark - 红 包
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRedPacketAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-09-16 10:51:22 +08:00
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 : @ "打开" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createNickAtrribute : info . redEnvelopeMasterNick uid : info . redEnvelopeMasterId . integerValue ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "的红包领取了" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
if ( info . amount . floatValue > 0 ) {
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%@钻石" , info . amount ] color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-09-16 10:51:22 +08:00
}
2022-08-19 17:42:14 +08:00
# pragma mark - 航 海
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomSailingAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-08-19 17:42:14 +08:00
RoomSailingPrizeModel * info = [ RoomSailingPrizeModel modelWithDictionary : attachment . data ] ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "厉害了! " color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "在航海冒险中获得" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . prizeName color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
if ( info . prizeNum > 1 ) {
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "x%d" , info . prizeNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
[ self attributeAddHihtLight : attribute uid : info . uid . integerValue ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-08-19 17:42:14 +08:00
}
2022-08-05 15:38:21 +08:00
# pragma mark - 礼 物 合 成
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomGiftCompoundAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-08-05 15:38:21 +08:00
XPGiftCompoundModel * info = [ XPGiftCompoundModel modelWithDictionary : attachment . data ] ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "恭喜" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . msg color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . giftName color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ self attributeAddHihtLight : attribute uid : info . uid . integerValue ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-08-05 15:38:21 +08:00
}
2022-06-15 14:20:09 +08:00
# pragma mark - 房 间 内 幸 运 礼 物 大 价 值
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomLuckyBigPrizeAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-06-15 14:20:09 +08:00
XPGiftBigPrizeModel * info = [ XPGiftBigPrizeModel modelWithDictionary : attachment . data ] ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "恭喜" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "在" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : info . roomTitle color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "通过%@" , info . luckyBagName ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ ",开出%@" , info . giftName ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-06-15 14:20:09 +08:00
}
2022-03-29 18:29:58 +08:00
# pragma mark - 房 间 内 PK
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomPKAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-03-29 18:29:58 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
if ( attachment . second = = Custom_Message _Sub _Room _PK _Manager _Up _Mic ) {
2022-05-25 15:40:24 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "房主/管理员邀请" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-03-29 18:29:58 +08:00
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 ;
2022-04-01 14:24:58 +08:00
if ( userInfoModel . groupType = = GroupType_Red ) {
2022-03-29 18:29:58 +08:00
groupTypeStr = @ "红队" ;
groupColor = UIColorFromRGB ( 0 xFB3D74 ) ;
} else {
groupTypeStr = @ "蓝队" ;
groupColor = UIColorFromRGB ( 0 x3291FC ) ;
}
[ 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 ) {
2022-05-27 18:24:13 +08:00
RoomPKTeamModel * blueTeam ;
RoomPKTeamModel * redTeam ;
for ( int i = 0 ; i < model . teams . count ; i + + ) {
2022-11-11 17:46:37 +08:00
RoomPKTeamModel * team = [ model . teams safeObjectAtIndex1 : i ] ;
2022-05-27 18:24:13 +08:00
if ( team . team = = GroupType_Red ) {
redTeam = team ;
} else {
blueTeam = team ;
}
}
2022-03-29 18:29:58 +08:00
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 ] ] ;
2022-05-27 18:24:13 +08:00
NSString * result = [ NSString stringWithFormat : @ "本场PK结果: %@! \nPK值:%@" , victoryStr , resultScale ] ;
2022-03-30 16:27:36 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : result color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-03-29 18:29:58 +08:00
} else {
if ( team . protecScore > 0 ) {
NSString * resultScale = [ NSString stringWithFormat : @ "%@:%@" , [ NSString stringWithFormat : @ "%lld" , team . score ] , [ NSString stringWithFormat : @ "%lld" , team . score ] ] ;
victoryStr = @ "平局" ;
2022-05-27 18:24:13 +08:00
NSString * result = [ NSString stringWithFormat : @ "本场PK结果: %@! \nPK值%@" , victoryStr , resultScale ] ;
2022-03-30 16:27:36 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : result color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-03-29 18:29:58 +08:00
} else {
victoryStr = @ "平局" ;
2022-05-27 18:24:13 +08:00
NSString * result = [ NSString stringWithFormat : @ "本场PK结果: %@! \nPK值%@" , victoryStr , @ "0:0" ] ;
2022-03-30 16:27:36 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : result color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-03-29 18:29:58 +08:00
}
}
2022-05-31 17:31:13 +08:00
if ( team . protector > 0 ) {
2022-05-27 18:24:13 +08:00
[ attribute appendAttributedString : [ [ NSMutableAttributedString alloc ] initWithString : @ "\n" ] ] ;
NSString * teamStr = [ NSString stringWithFormat : @ "蓝队守护者:%@ \n 蓝队守护值: %@ \n 红队守护者: %@ \n 红队守护值: %@" , 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 : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
2022-03-29 18:29:58 +08:00
} else {
RoomPKTeamModel * victoryTeam ;
RoomPKTeamModel * failTeam ;
for ( int i = 0 ; i < model . teams . count ; i + + ) {
2022-11-11 17:46:37 +08:00
RoomPKTeamModel * team = [ model . teams safeObjectAtIndex1 : i ] ;
2022-03-29 18:29:58 +08:00
if ( team . team = = ( GroupType ) model . result ) {
victoryTeam = team ;
} else {
failTeam = team ;
}
}
if ( model . result = = RoomPKResultType_Red ) {
2022-05-27 18:24:13 +08:00
victoryStr = @ "红队" ;
2022-03-29 18:29:58 +08:00
} else if ( model . result = = RoomPKResultType_Blue ) {
2022-05-27 18:24:13 +08:00
victoryStr = @ "蓝队" ;
2022-03-29 18:29:58 +08:00
}
NSString * resultScale = [ NSString stringWithFormat : @ "%@:%@" , [ NSString stringWithFormat : @ "%lld" , victoryTeam . score ] , [ NSString stringWithFormat : @ "%lld" , failTeam . score ] ] ;
NSString * result ;
if ( model . voteMode = = RoomPKVoteModeType_NumberPerson ) {
2022-05-27 18:24:13 +08:00
result = [ NSString stringWithFormat : @ "本场PK结果: %@胜利!\nPK值%@ \n 胜利方战斗值:%@" , victoryStr , resultScale , [ NSNumber numberWithLongLong : victoryTeam . score ] ] ;
2022-03-29 18:29:58 +08:00
} else {
if ( victoryTeam . protector ) {
2022-05-27 18:24:13 +08:00
NSString * victoryProteror = victoryTeam . protector . nick . length > 0 ? victoryTeam . protector . nick : @ "" ;
result = [ NSString stringWithFormat : @ "本场PK结果: %@胜利! \nPK值%@ \n %@守护者:%@ \n %@守护值:%@" , victoryStr , resultScale , victoryStr , victoryProteror , victoryStr , [ [ NSNumber numberWithLongLong : victoryTeam . protecScore ] stringValue ] ] ;
2022-03-29 18:29:58 +08:00
} else {
2022-05-27 18:24:13 +08:00
result = [ NSString stringWithFormat : @ "本场PK结果: %@胜利! \nPK值%@ \n %@守护值:%@" , victoryStr , resultScale , victoryStr , [ [ NSNumber numberWithLongLong : victoryTeam . protecScore ] stringValue ] ] ;
2022-03-29 18:29:58 +08:00
}
}
[ attribute appendAttributedString : [ self createTextAttribute : result color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
2022-05-27 18:24:13 +08:00
@ 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 ] ;
} ] ;
2022-03-29 18:29:58 +08:00
} 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 = @ "送礼人数多的团队获胜" ;
}
2022-05-29 13:56:06 +08:00
NSString * title = [ NSString stringWithFormat : @ "管理发起房间PK, 本次PK时间为%.0f秒,%@" , model . duration , pkType ] ;
2022-03-29 18:29:58 +08:00
[ 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 ] ] ;
}
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-03-29 18:29:58 +08:00
}
2022-05-27 18:24:13 +08:00
- ( void ) showRoomPKResult : ( NSDictionary * ) dic {
RoomPKInfoModel * pkInfo = [ RoomPKInfoModel modelWithDictionary : dic ] ;
2022-05-31 17:31:13 +08:00
if ( pkInfo . pkStatus = = RoomPKStatusType_End || pkInfo . pkStatus = = RoomPKStatusType_ReStart ) {
2022-05-27 18:24:13 +08:00
XPRoomPKResultView * result = [ [ XPRoomPKResultView alloc ] init ] ;
result . roomPKResultInfoModel = pkInfo ;
[ TTPopup popupView : result style : TTPopupStyleAlert ] ;
}
}
2022-03-10 18:49:50 +08:00
# pragma mark - 表 情 显 示
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomFaceAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-03-10 18:49:50 +08:00
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 + + ) {
2022-11-11 17:46:37 +08:00
RoomFaceSendInfoModel * sendFaceInfo = [ array safeObjectAtIndex1 : i ] ;
2022-03-10 18:49:50 +08:00
[ 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 ] ;
}
}
}
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-03-10 18:49:50 +08:00
}
2021-12-27 16:40:14 +08:00
# pragma mark - 收 藏 房 间
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createCollectRoomAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-12-27 16:40:14 +08:00
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 ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-12-27 16:40:14 +08:00
}
2021-11-17 19:29:14 +08:00
# pragma mark - 房 间 信 息 更 新
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomInfoUpdateAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-12-25 16:57:50 +08:00
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 ] ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
2021-12-27 17:10:36 +08:00
} else if ( attachment . second = = Custom_Message _Sub _Update _RoomInfo _AnimateEffect ) {
2022-04-26 18:41:17 +08:00
NSDictionary * dic = attachment . data [ @ "roomInfo" ] ;
if ( dic . allKeys . count <= 0 ) {
dic = attachment . data ;
}
RoomInfoModel * roomInfo = [ RoomInfoModel modelWithDictionary : dic ] ;
2021-12-27 17:10:36 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "消息:" color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2022-04-26 18:41:17 +08:00
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 ] ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
2022-04-25 17:45:57 +08:00
} 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 ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
2022-04-25 17:45:57 +08:00
}
2022-10-21 18:03:00 +08:00
return messageInfo ;
2021-11-04 16:27:39 +08:00
}
2022-01-05 21:48:21 +08:00
# pragma mark - 相 亲
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createRoomDatingAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-01-05 21:48:21 +08:00
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 ( 0 xF84C95 ) 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 ] ] ;
}
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-01-05 21:48:21 +08:00
}
2021-12-20 21:17:12 +08:00
# pragma mark - 排 麦
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createArrangeMicAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-12-20 21:17:12 +08:00
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 ] ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-12-20 21:17:12 +08:00
}
2021-12-10 21:20:34 +08:00
# pragma mark - 糖 果 树 公 屏 消 息
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createCandyTreeHighLevelAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-12-10 21:20:34 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
// action
[ attribute appendAttributedString : [ self createTextAttribute : @ "厉害了 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-06-01 10:34:36 +08:00
CandyTreeGiftInfoModel * giftInfo = [ CandyTreeGiftInfoModel modelWithDictionary : attachment . data ] ;
[ attribute appendAttributedString : [ self createTextAttribute : giftInfo . nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-10 21:20:34 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "摘下糖果获得" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-06-01 10:34:36 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : giftInfo . prizeName color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-06-16 16:12:57 +08:00
if ( giftInfo . prizeNum > 1 ) {
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X %d" , giftInfo . prizeNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
if ( attachment . second = = Custom_Message _Sub _Candy _Tree _Me && giftInfo . uid . integerValue = = [ AccountInfoStorage instance ] . getUid . integerValue ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "(仅自己可见)" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
2022-06-01 10:34:36 +08:00
[ self attributeAddHihtLight : attribute uid : giftInfo . uid . integerValue ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-12-10 21:20:34 +08:00
}
2022-01-10 19:59:58 +08:00
# pragma mark - 贵 族
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createNobleLevelAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-01-10 19:59:58 +08:00
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 ] ] ;
2022-02-22 17:39:31 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%@(%@)" , attachment . data [ @ "nick" ] , attachment . data [ @ "erbanNo" ] ] color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2022-01-10 19:59:58 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "开通贵族系统,获得" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-02-22 17:39:31 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : attachment . data [ @ "currVipName" ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-01-10 19:59:58 +08:00
[ 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 ] ] ;
2022-01-12 16:33:57 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : attachment . data [ @ "currVipName" ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-01-10 19:59:58 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "! " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
[ self attributeAddHihtLight : attribute uid : uid ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-01-10 19:59:58 +08:00
}
2022-03-23 11:25:53 +08:00
# pragma mark - 塔 罗
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createTarotAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-03-23 11:25:53 +08:00
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 ] ] ;
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-03-23 11:25:53 +08:00
}
2022-04-08 15:42:25 +08:00
# pragma mark - 个 播 粉 丝 团
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createAnchorFansTeamAttribute : ( AttachmentModel * ) attachment messageInfo : ( XPMessageInfoModel * ) messageInfo {
2022-04-08 15:42:25 +08:00
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 ] ;
2022-04-11 10:20:00 +08:00
NSString * nickName = attachment . data [ @ "nickname" ] ;
2022-04-08 15:42:25 +08:00
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 ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2022-04-08 15:42:25 +08:00
}
2021-11-26 17:31:12 +08:00
# pragma mark - 踢 出 房 间 / 拉 黑 / 下 麦
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createKickUserAttribute : ( AttachmentModel * ) attachment info : ( XPKickUserModel * ) info messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-26 17:31:12 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . targetNick uid : info . targetUid ] ] ;
2021-11-26 17:31:12 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "被" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . handleNick uid : info . handleUid ] ] ;
2021-11-26 17:31:12 +08:00
NSString * content = @ "" ;
2022-04-26 21:45:40 +08:00
if ( attachment . second = = Custom_Message _Sub _Kick _BeKicked || attachment . second = = Custom_Message _Sub _Hall _Super _Admin _Kick _Manager _Out _Room ) {
2021-11-26 17:31:12 +08:00
content = @ "请出房间" ;
} else if ( attachment . second = = Custom_Message _Sub _Kick _BlackList ) {
content = @ "关进小黑屋" ;
2021-11-26 21:47:00 +08:00
} else if ( attachment . second = = Custom_Message _Sub _Queue _Kick ) {
content = @ "请下麦" ;
2021-11-26 17:31:12 +08:00
}
[ attribute appendAttributedString : [ self createTextAttribute : content color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-26 17:31:12 +08:00
}
2021-12-27 16:40:14 +08:00
# pragma mark - 分 享 房 间
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createShareOrAttentionRoomAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo uid : ( NSString * ) uid messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-24 14:58:53 +08:00
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 ] ] ;
2021-11-26 21:47:00 +08:00
[ self attributeAddHihtLight : attribute uid : uid . integerValue ] ;
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-24 14:58:53 +08:00
}
2021-11-17 19:29:14 +08:00
# pragma mark - 送 礼 物 的 公 屏
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createBatchMicroSendGiftAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-17 19:29:14 +08:00
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 ] ;
}
2021-11-24 14:58:53 +08:00
// / 官 方 新 用 户
2022-06-07 16:16:27 +08:00
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : sendInfo . defUser newUser : sendInfo . newUser fromSayHelloChannel : sendInfo . fromSayHelloChannel ] ] ;
2021-11-17 19:29:14 +08:00
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . nick uid : info . uid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ 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 ) {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
for ( int i = 0 ; i < info . targetUsers . count ; i + + ) {
2022-11-11 17:46:37 +08:00
GiftReceiveUserInfoModel * targetInfo = [ info . targetUsers safeObjectAtIndex1 : i ] ;
2021-11-17 19:29:14 +08:00
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : targetInfo . nick uid : targetInfo . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
if ( i < ( info . targetUsers . count -1 ) ) {
// nick
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
}
} else {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 全麦打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
// img
if ( giftInfo . giftUrl ) {
[ attribute appendAttributedString : [ self createUrlImageAttribute : giftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , info . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
} 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 = @ " 全麦送出 " ;
}
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : sendTitle color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : info . giftName color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 给 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
if ( info . luckyGiftList ) {
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . luckyGiftList . user . nick uid : info . luckyGiftList . user . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 爆出了 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
[ info . luckyGiftList . giftList enumerateObjectsUsingBlock : ^ ( GiftListsInfo * _Nonnull giftListInfo , NSUInteger idx , BOOL * _Nonnull stop ) {
2021-12-23 15:10:11 +08:00
GiftInfoModel * luckGiftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : [ NSString stringWithFormat : @ "%ld" , giftListInfo . giftId ] ] ;
2021-11-17 19:29:14 +08:00
// 价 值
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "价值" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 礼 物 价 格
2021-12-23 15:10:11 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%ld" , ( NSInteger ) luckGiftInfo . goldPrice ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 的 礼 物
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "钻石的礼物" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : luckGiftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , giftListInfo . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
if ( info . luckyGiftList . giftList . count -1 ! = idx ) {
// ,
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
} ] ;
}
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-17 19:29:14 +08:00
}
2022-10-21 18:03:00 +08:00
- ( XPMessageInfoModel * ) createSendGiftAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo messageInfo : ( XPMessageInfoModel * ) messageInfo {
2021-11-17 19:29:14 +08:00
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 ] ;
}
2021-11-24 14:58:53 +08:00
// / 官 方 新 用 户
2022-06-07 16:16:27 +08:00
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : sendInfo . defUser newUser : sendInfo . newUser fromSayHelloChannel : sendInfo . fromSayHelloChannel ] ] ;
2021-11-17 19:29:14 +08:00
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . nick uid : info . uid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;;
if ( attachment . second = = Custom_Message _Sub _Gift _LuckySend ) {
// action
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "送出" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : info . giftName color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "给" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . luckyGiftList . user . nick uid : info . luckyGiftList . user . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// lucky
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "爆出了" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ info . luckyGiftList . giftList enumerateObjectsUsingBlock : ^ ( GiftListsInfo * _Nonnull giftListInfo , NSUInteger idx , BOOL * _Nonnull stop ) {
GiftInfoModel * luckyGiftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : [ NSString stringWithFormat : @ "%ld" , giftListInfo . giftId ] ] ;
// 价 值
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "价值" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 礼 物 价 格
2022-03-15 10:44:19 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%ld" , ( NSInteger ) luckyGiftInfo . goldPrice ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 的 礼 物
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "钻石的礼物" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : luckyGiftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , giftListInfo . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
if ( info . luckyGiftList . giftList . count -1 ! = idx ) {
// ,
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
} ] ;
} else {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . targetNick uid : info . targetUid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : giftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , info . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
2022-10-21 18:03:00 +08:00
messageInfo . content = attribute ;
return messageInfo ;
2021-11-17 19:29:14 +08:00
}
2021-11-24 14:58:53 +08:00
# pragma mark - Commond Mehotd
2022-04-18 22:36:16 +08:00
// / 用 户 是 否 当 前 房 间 的 超 管
- ( BOOL ) isCurrentRoomSuperAdmin : ( NSString * ) uid {
for ( GuildSuperAdminInfoModel * info in self . hostDelegate . getRoomSuperAdminList ) {
if ( [ info . uid isEqualToString : uid ] ) {
return YES ;
}
}
return NO ;
}
2022-06-07 16:16:27 +08:00
- ( NSAttributedString * ) createOfficalAndNewuserAttribute : ( UserLevelType ) levelType newUser : ( BOOL ) newUser fromSayHelloChannel : ( BOOL ) fromSayHelloChannel {
2021-11-24 14:58:53 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
// offical
if ( levelType = = UserLevelType_Offical ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_offical" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
if ( newUser ) {
2022-06-07 16:16:27 +08:00
if ( fromSayHelloChannel ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "room_new_user_greet_new" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
} else {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_new_user" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2021-11-24 14:58:53 +08:00
}
return attribute ;
}
2021-11-17 19:29:14 +08:00
2021-11-26 21:47:00 +08:00
// / 名 字 点 击 的
- ( 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 ] ;
} ] ;
}
2022-04-24 18:58:30 +08:00
- ( 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 ] ;
} ] ;
}
2021-11-26 21:47:00 +08:00
- ( void ) showUserCard : ( NSInteger ) uid {
2021-12-13 19:44:15 +08:00
RoomInfoModel * roomInfo = self . hostDelegate . getRoomInfo ;
2021-11-26 21:47:00 +08:00
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 ] ;
2022-01-06 15:35:49 +08:00
model . posState = obj . microState . posState ;
model . micState = obj . microState . micState ;
2021-11-26 21:47:00 +08:00
* stop = YES ;
}
} ] ;
2021-12-13 19:44:15 +08:00
model . nick = self . hostDelegate . getUserInfo . nick ;
2022-01-06 15:35:49 +08:00
model . uid = targetUid ;
model . micQueue = self . hostDelegate . getMicroQueue ;
model . roomInfo = roomInfo ;
2021-12-13 19:44:15 +08:00
model . delegate = self . hostDelegate ;
2022-04-18 22:36:16 +08:00
model . superMangerList = self . hostDelegate . getRoomSuperAdminList ;
2021-12-13 19:44:15 +08:00
XPUserCardViewController * userCardVC = [ [ XPUserCardViewController alloc ] initWithUser : model ] ;
2021-11-26 21:47:00 +08:00
[ self . hostDelegate . getCurrentNav presentViewController : userCardVC animated : YES completion : nil ] ;
}
2021-11-17 19:29:14 +08:00
# pragma mark - private base methods
2021-12-17 15:18:34 +08:00
// / 铭 牌
- ( 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 ;
2023-03-20 14:38:12 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 14 * scale , 14 ) ;
2021-12-17 15:18:34 +08:00
} else {
NSURL * imgUrl = [ NSURL URLWithString : imageName ] ;
UIImage * myImage = [ UIImage imageWithData : [ NSData dataWithContentsOfURL : imgUrl ] ] ;
2022-06-09 17:50:02 +08:00
if ( myImage ) {
CGFloat scale = myImage . size . width / myImage . size . height ;
if ( scale = = 0 ) {
2023-03-20 14:38:12 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 42 , 14 ) ;
2022-06-09 17:50:02 +08:00
} else {
2023-03-20 14:38:12 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 14 * scale , 14 ) ;
2022-06-09 17:50:02 +08:00
}
} else {
2023-03-20 14:38:12 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 42 , 14 ) ;
2021-12-17 15:18:34 +08:00
}
}
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 ;
}
2023-03-14 10:33:35 +08:00
// / 生 成 一 个 背 景 的 图 片 和 文 字
// / @ param imageUrl 网 络 图 片 的 地 址 如 果 地 址 为 空 那 就 显 示 默 认 背 景
2023-03-16 18:04:36 +08:00
- ( NSMutableAttributedString * ) createUrlImageAttribute : ( NSString * ) imageUrl text : ( NSString * ) text nickNameNifo : ( id ) nickNameNifo {
2023-03-14 10:33:35 +08:00
NetImageConfig * config = [ [ NetImageConfig alloc ] init ] ;
NetImageView * imageView = [ [ NetImageView alloc ] initWithUrl : imageUrl config : config ] ;
2023-03-16 18:04:36 +08:00
imageView . tag = 1000 ;
NSMutableAttributedString * msgStr = [ [ NSMutableAttributedString alloc ] initWithString : text ] ;
[ msgStr addAttribute : NSForegroundColorAttributeName
value : [ ThemeColor messageTextColor ]
range : NSMakeRange ( 0 , msgStr . length ) ] ;
if ( [ nickNameNifo isKindOfClass : [ NSArray class ] ] ) {
for ( NSString * nick in nickNameNifo ) {
NSRange range = [ text rangeOfString : nick ] ;
if ( range . length ) {
[ msgStr yy_setTextHighlightRange : range color : UIColorFromRGB ( 0 xFD85C9 ) backgroundColor : [ UIColor clearColor ] userInfo : nil ] ;
}
}
}
2023-03-14 10:33:35 +08:00
// 铭 牌 文 字
UILabel * label = [ [ UILabel alloc ] init ] ;
2023-03-14 18:29:52 +08:00
label . textAlignment = NSTextAlignmentLeft ;
2023-03-14 10:33:35 +08:00
label . font = [ UIFont boldSystemFontOfSize : kRoomMessageDefalutFont ] ;
label . adjustsFontSizeToFitWidth = YES ;
2023-03-14 18:29:52 +08:00
label . numberOfLines = 0 ;
2023-03-14 10:33:35 +08:00
label . textColor = UIColor . whiteColor ;
2023-03-16 18:04:36 +08:00
label . attributedText = msgStr ;
2023-03-14 10:33:35 +08:00
[ 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 ;
if ( text . length > 0 ) {
CGSize size = [ text 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 ;
} else {
imageWidth = 0 ;
imageHeight = 0 ;
}
imageView . layer . masksToBounds = YES ;
imageView . frame = CGRectMake ( 0 , 0 , imageWidth , imageHeight ) ;
if ( imageUrl . length > 0 ) {
2023-03-16 18:04:36 +08:00
imageView . imageUrl = imageUrl ;
2023-03-14 10:33:35 +08:00
} else {
2023-03-16 18:04:36 +08:00
[ imageView setCornerWithLeftTopCorner : 4 rightTopCorner : 11 bottomLeftCorner : 11 bottomRightCorner : 11 size : CGSizeMake ( imageWidth , imageHeight ) ] ;
2023-03-14 10:33:35 +08:00
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 ;
}
2023-03-23 18:59:41 +08:00
// / 生 成 一 个 背 景 的 图 片 和 文 字
// / @ 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 ;
}
2023-03-14 18:45:56 +08:00
# pragma mark - tool
- ( UIImage * ) resizableImage : ( UIImage * ) image {
// 图 片 拉 伸 区 域
CGFloat top = ( image . size . height - 1 ) / 2 ;
CGFloat left = ( image . size . width - 1 ) / 2 ;
CGFloat right = ( image . size . width - 1 ) / 2 ;
CGFloat bottom = ( image . size . height - 1 ) / 2 ;
return [ image resizableImageWithCapInsets : UIEdgeInsetsMake ( top , left , bottom , right ) resizingMode : UIImageResizingModeStretch ] ;
}
2023-07-31 11:37:19 +08:00
// / 生 成 一 个 图 片 的 富 文 本
// / @ param imageUrl 网 络 图 片 的 地 址
- ( NSMutableAttributedString * ) createUrlImageAttribute : ( NSString * ) imageUrl size : ( CGSize ) size {
NetImageConfig * config = [ [ NetImageConfig alloc ] init ] ;
if ( ! [ imageUrl hasPrefix : @ "http" ] ) {
config . placeHolder = kImage ( imageUrl ) ;
}
// / 先 这 样 吧
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 , size . width * scale , size . height ) ;
} else {
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 : [ UIFont systemFontOfSize : 15.0 ] alignment : YYTextVerticalAlignmentCenter ] ;
return attrString ;
}
2021-11-04 16:27:39 +08:00
// / 生 成 一 个 图 片 的 富 文 本
// / @ param imageUrl 网 络 图 片 的 地 址
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createUrlImageAttribute : ( NSString * ) imageUrl {
2021-11-25 17:35:31 +08:00
NetImageConfig * config = [ [ NetImageConfig alloc ] init ] ;
2023-07-31 11:37:19 +08:00
if ( ! [ imageUrl hasPrefix : @ "http" ] ) {
config . placeHolder = kImage ( imageUrl ) ;
}
2021-12-02 01:05:49 +08:00
// / 先 这 样 吧
config . autoLoad = YES ;
2021-11-25 17:35:31 +08:00
NetImageView * imageView = [ [ NetImageView alloc ] initWithUrl : imageUrl config : config ] ;
2021-11-17 19:29:14 +08:00
UIImage * image = imageView . image ;
if ( image ) {
CGFloat scale = image . size . width / image . size . height ;
2023-07-31 11:37:19 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 16 * scale , 16 ) ;
2021-11-17 19:29:14 +08:00
} else {
2023-07-31 11:37:19 +08:00
imageView . bounds = CGRectMake ( 0 , 0 , 16 , 16 ) ;
2021-11-17 19:29:14 +08:00
}
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 ;
2021-11-04 16:27:39 +08:00
}
2021-11-17 19:29:14 +08:00
2023-03-20 19:34:34 +08:00
- ( NSMutableAttributedString * ) createImageAttribute : ( UIImage * ) image {
2023-07-31 11:37:19 +08:00
return [ self createImageAttribute : image height : 16 ] ;
2023-03-20 19:34:34 +08:00
}
2021-11-04 16:27:39 +08:00
// / 生 成 本 地 一 个 图 片 的 富 文 本
// / @ param imageName 网 络 图 片 的 地 址
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createLocalImageAttribute : ( NSString * ) imageName {
2021-11-17 19:29:14 +08:00
if ( imageName = = nil && imageName . length <= 0 ) {
return nil ;
}
2021-11-04 16:27:39 +08:00
return [ self createImageAttribute : [ UIImage imageNamed : imageName ] ] ;
}
// / 生 成 本 地 一 个 图 片 的 富 文 本
// / @ param image 本 地 的 图 片
2023-03-20 19:34:34 +08:00
// / @ param height 图 片 高 度 ( 宽 度 自 动 按 比 例 )
- ( NSMutableAttributedString * ) createImageAttribute : ( UIImage * ) image height : ( CGFloat ) height {
2021-11-04 16:27:39 +08:00
UIImageView * imaveView = [ [ UIImageView alloc ] init ] ;
imaveView . image = image ;
CGFloat scale = ( CGFloat ) imaveView . image . size . width / ( CGFloat ) imaveView . image . size . height ;
2023-03-20 19:34:34 +08:00
imaveView . bounds = CGRectMake ( 0 , 0 , height * scale , height ) ;
2021-11-04 16:27:39 +08:00
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 文 字 的 大 小
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createTextAttribute : ( NSString * ) text color : ( UIColor * ) color font : ( CGFloat ) font {
2021-11-17 19:29:14 +08:00
if ( text = = nil || text . length <= 0 ) {
text = @ "" ;
}
2021-11-04 16:27:39 +08:00
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 ;
}
// / 设 置 文 本 的 样 式 间 隙 缩 进 . . .
2021-11-26 21:47:00 +08:00
- ( NSMutableParagraphStyle * ) paragraphStyle {
2021-11-04 16:27:39 +08:00
NSMutableParagraphStyle * paraStyle = [ [ NSMutableParagraphStyle alloc ] init ] ;
paraStyle . lineSpacing = 4.0 f ; // 行 间 距
// 强 制 排 版 ( 从 左 到 右 )
paraStyle . alignment = NSTextAlignmentLeft ;
paraStyle . baseWritingDirection = NSWritingDirectionLeftToRight ;
return paraStyle ;
}
// / 占 位 的 富 文 本
// / @ param width 需 要 的 间 隙
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createSapceAttribute : ( CGFloat ) width {
2021-11-04 16:27:39 +08:00
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