// // MsRoomMessagChatHallView.m // YuMi // // Created by duoban on 2024/5/10. // #import "MsRoomMessagChatHallView.h" ///Third #import #import ///Tool #import "DJDKMIMOMColor.h" #import "YUMIMacroUitls.h" #import "XPRoomMessageConstant.h" #import "XPRoomMessageParser.h" #import "AccountInfoStorage.h" #import "XPRoomMiniManager.h" #import "PLTimeUtil.h" #import "ClientConfig.h" #import #import "ThemeColor+Room.h" #import "NSArray+Safe.h" #import "Api+Room.h" #import "Api+Message.h" #import "XPMessageRemoteExtModel.h" ///Model #import "RoomInfoModel.h" #import "AttachmentModel.h" #import "RoomFaceSendInfoModel.h" #import "XPMessageRemoteExtModel.h" #import "RoomPKChooseUserModel.h" #import "CandyTreeResultModel.h" #import "RoomSailingPrizeModel.h" #import "UserInfoModel.h" #import "XPMessageInfoModel.h" #import "GiftReceiveInfoModel.h" #import "XPGiftStorage.h" ///View #import "XPRoomMessageTableViewCell.h" #import "XPRoomMessageHeaderView.h" #import "View/XPRoomMessageHeaderView.h" #import "PIRoomMessagePhotoAlbumCell.h" #import "PIRoomMessageUnlockPhotoAlbumView.h" #import "PIRoomPhotoAlbumItemModel.h" #import "SDPhotoBrowser.h" #import "XPSkillCardPlayerManager.h" #import "MsRoomMessagChatHallCell.h" #import "MSSessionPublicChatHallTopModel.h" @interface MsRoomMessagChatHallView () ///房间的代理 @property (nonatomic,weak) id hostDelegate; ///列表 @property (nonatomic,strong) UITableView *messageTableView; ///头部 @property (nonatomic,strong) UIView *headerView; @property(nonatomic,strong) UILabel *titleView; ///messageView 持有这个工具类 进行数据的分发操作 TODO: 有需要在改 @property (nonatomic,strong) XPRoomMessageParser *messageParser; ///是否是最小化进房的 @property (nonatomic,assign) BOOL isMiniEnter; ///数据源 @property (nonatomic,strong) NSMutableArray *datasource; @property(nonatomic,strong) PIRoomPhotoAlbumItemModel *lookUpModel; ///是否是大的 只有在小游戏的时候有用 @property (nonatomic,assign) BOOL isLarge; @property(nonatomic,assign) BOOL isLoadHistoryMessage; @end @implementation MsRoomMessagChatHallView - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (instancetype)initWithDelegate:(id)delegate { self = [super init]; if (self) { self.isLoadHistoryMessage = YES; self.hostDelegate = delegate; [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView { return self; } - (void)showUserCard:(NSInteger)uid{ [self.messageParser showUserCard:uid]; } #pragma mark - Response #pragma mark - Private Method - (void)initSubViews { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCustomMessage:) name:@"message" object:nil]; [self addSubview:self.headerView]; [self.headerView addSubview:self.titleView]; [self addSubview:self.messageTableView]; [Api getPublicChatHallTopText:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if(code == 200){ MSSessionPublicChatHallTopModel *model = [MSSessionPublicChatHallTopModel modelWithDictionary:data.data]; if(model != nil){ self.titleView.text = model.content; [self.headerView mas_remakeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_greaterThanOrEqualTo(0); }]; }else{ [self.headerView mas_remakeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_equalTo(0); }]; } } }]; } - (void)initSubViewConstraints { [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_greaterThanOrEqualTo(0); }]; [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.top.bottom.equalTo(self.headerView).inset(10); }]; [self.messageTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.bottom.trailing.mas_equalTo(self); make.top.equalTo(self.headerView.mas_bottom).mas_offset(10); }]; } #pragma mark - 添加数据并且做自动滚动 ///执行插入动画并滚动 - (void)scrollToBottom:(BOOL)animated { if(self.datasource.count > 0){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSIndexPath *ip = [NSIndexPath indexPathForRow:self.datasource.count-1 inSection:0]; //取最后一行数据 [self.messageTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:animated]; //滚动到最后一行 }); } } ///自定义消息 是否可以加到 公屏 需要自己维护 - (BOOL)isCanDisplayMessage:(NIMMessage *)message { NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel *attachment = (AttachmentModel *)obj.attachment; if(attachment.first == CustomMessageType_Chat_Hall_Headlinesn && attachment.second == Custom_Message_Sub_Chat_Hall_Headlinesn){ MSSessionPublicChatHallTopModel *topModel = [MSSessionPublicChatHallTopModel modelWithDictionary:attachment.data]; if(topModel.recordStatus == 1){ self.titleView.text = topModel.content; [self.headerView mas_remakeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_equalTo(0); }]; }else{ self.titleView.text = topModel.content; [self.headerView mas_remakeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_greaterThanOrEqualTo(0); }]; } if(topModel.recordStatus == 1){ return NO; } } return [[[self supportMessageDic] objectForKey:@(attachment.first)] containsObject:@(attachment.second)]; } return NO; } - (NSDictionary *)supportMessageDic { return @{ @(CustomMessageType_Chat_Hall_Headlinesn): [NSSet setWithObjects: @(Custom_Message_Sub_Chat_Hall_Headlinesn), nil] }; } -(void)addRoomMessage:(NIMMessage *)msg{ if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;} [self.datasource addObject:[self.messageParser parseMessageAttributeForChatHall:msg]]; [self.messageTableView reloadData]; [self scrollToBottom:YES]; } - (void)addCustomMessage:(NSNotification *)notification { self.isMiniEnter = NO; if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;} NIMMessage * message = notification.object; [self addRoomMessage:message]; } #pragma mark - RoomGuestDelegate - (void)handleNIMCustomAttachment:(AttachmentModel *)attachment{ } - (void)handleNIMCustomMessage:(NIMMessage *)message { self.isMiniEnter = NO; if ([self isCanDisplayMessage:message]) { NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; [self addRoomMessage:message]; } } - (void)handleNIMImageMessage:(NIMMessage *)message { self.isMiniEnter = NO; if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;} PIRoomPhotoAlbumItemModel*model = [PIRoomPhotoAlbumItemModel new]; model.type = @"1"; model.status = 1; NIMImageObject * imageObject = (NIMImageObject*)message.messageObject; model.photoUrl = imageObject.url; XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; messageInfo.albumModel = model; messageInfo.first = CustomMessageType_Room_Album; XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]]; messageInfo.charmUrl = extModel.charmUrl; messageInfo.experUrl = extModel.experUrl; messageInfo.bubbleImageUrl = extModel.iosBubbleUrl; messageInfo.nameText = extModel.nick; [self.datasource addObject:messageInfo]; [self.messageTableView reloadData]; [self scrollToBottom:YES]; } - (void)handleNIMNotificationMessage:(NIMMessage *)message { self.isMiniEnter = NO; NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject; NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content; RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; if (content.eventType == NIMChatroomEventTypeEnter) { if (roomInfo.isCloseScreen) { self.isLoadHistoryMessage = NO; AttachmentModel *attachement = [[AttachmentModel alloc]init]; attachement.first = CustomMessageType_Update_RoomInfo; attachement.second = Custom_Message_Sub_Update_RoomInfo_MessageState; attachement.data = @{@"roomInfo":self.hostDelegate.getRoomInfo.model2dictionary}; NIMMessage *message = [[NIMMessage alloc]init]; NIMCustomObject *object = [[NIMCustomObject alloc] init]; object.attachment = attachement; message.messageObject = object; [self addRoomMessage:message]; return; } else { NIMChatroomNotificationMember *member = content.targets[0]; if (member.userId.integerValue == [AccountInfoStorage instance].getUid.integerValue) { ///自己进房成功后拉取历史消息 if(self.datasource.count > 0) { self.isLoadHistoryMessage = NO; return; } [self handleFetchHistoryMessage]; } else { self.isLoadHistoryMessage = NO; } } } } - (void)handleFetchHistoryMessage{ UserInfoModel *infoModel = self.hostDelegate.getUserInfo; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[infoModel.partitionId]]; NSString *roomId = publicChatRoomId; NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init]; option.limit = 100; option.startTime = 0; option.order = NIMMessageSearchOrderAsc; option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeImage)]; [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId option:option result:^(NSError * _Nullable error, NSArray * _Nullable messages) { if(error != nil){ self.isLoadHistoryMessage = NO; } //如果拉取的数量等于请求的数量,说明这个时间点以后的消息数量大于等于需要拉取的数量,直接拉取最新的50条 if (messages.count == 100) { NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init]; option.limit = 100; option.order = NIMMessageSearchOrderDesc; option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeImage)]; [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId option:option result:^(NSError * _Nullable error, NSArray * _Nullable messages) { if(error != nil){ self.isLoadHistoryMessage = NO; } dispatch_async(dispatch_get_main_queue(), ^{///回到主线程 if (self.datasource.count > kRoomMessageMaxLength) { NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; [self.datasource removeObjectsInArray:needRemoveMsgArray]; } // 执行插入 for (NIMMessage *item in messages.reverseObjectEnumerator) { [self dealWithHistoryDataWithMessage:item]; } [self.messageTableView reloadData]; //执行插入动画并滚动 [self scrollToBottom:YES]; self.isLoadHistoryMessage = NO; }); }]; return; } dispatch_async(dispatch_get_main_queue(), ^{///回到主线程 if (self.datasource.count > kRoomMessageMaxLength) { NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; [self.datasource removeObjectsInArray:needRemoveMsgArray]; } // 执行插入 for (NIMMessage *item in messages) { [self dealWithHistoryDataWithMessage:item]; } [self.messageTableView reloadData]; //执行插入动画并滚动 [self scrollToBottom:YES]; self.isLoadHistoryMessage = NO; }); }]; } -(void)dealWithHistoryDataWithMessage:(NIMMessage *)item{ BOOL isHaveSave = NO; if(item.messageType == NIMMessageTypeText){ isHaveSave = YES; }else if(item.messageType == NIMMessageTypeImage){ isHaveSave = YES; }else if(item.messageType == NIMMessageTypeCustom){ NIMCustomObject *obj = (NIMCustomObject *)item.messageObject; if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel *attachment = (AttachmentModel *)obj.attachment; if (attachment.first == CustomMessageType_Chat_Hall_Headlinesn && attachment.second == Custom_Message_Sub_Chat_Hall_Headlinesn) { isHaveSave = YES; } } } if(isHaveSave == NO)return; if (item.messageType == NIMMessageTypeImage){ PIRoomPhotoAlbumItemModel*model = [PIRoomPhotoAlbumItemModel new]; model.type = @"1"; model.status = 1; NIMImageObject * imageObject = (NIMImageObject*)item.messageObject; model.photoUrl = imageObject.url; XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; messageInfo.albumModel = model; messageInfo.first = CustomMessageType_Room_Album; XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithJSON:item.remoteExt[item.from]]; messageInfo.charmUrl = extModel.charmUrl; messageInfo.experUrl = extModel.experUrl; messageInfo.bubbleImageUrl = extModel.iosBubbleUrl; messageInfo.nameText = extModel.nick; [self.datasource addObject:messageInfo]; return; } [self.datasource addObject:[self.messageParser parseMessageAttributeForChatHall:item]]; } - (void)handleNIMTextMessage:(NIMMessage *)message { self.isMiniEnter = NO; if (self.hostDelegate.getRoomInfo.isCloseScreen) {return;} [self addRoomMessage:message]; } - (void)onRoomMiniEntered { self.isMiniEnter = YES; UserInfoModel *userInfo = self.hostDelegate.getUserInfo; 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.isCustomWord = userInfo.isCustomWord; 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; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[userInfo.partitionId]]; NIMChatroomEnterRequest *publicChatRoomRequest = [[NIMChatroomEnterRequest alloc] init]; publicChatRoomRequest.roomId = publicChatRoomId; NSMutableDictionary *publicChatRoomExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:publicChatRoomId]; publicChatRoomRequest.roomExt = [publicChatRoomExt toJSONString]; [[NIMSDK sharedSDK].chatroomManager enterChatroom:publicChatRoomRequest completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) { if(error == nil){ [self handleFetchHistoryMessage]; } }]; self.headerView.backgroundColor = UIColorRGBAlpha(0xADF4FF, 0.2); } - (void)onRoomEntered { self.headerView.backgroundColor = UIColorRGBAlpha(0xADF4FF, 0.2); } - (void)onRoomUpdate { ///改变公屏的背景样式 if (self.hostDelegate.getRoomInfo.hadChangeRoomType) { self.headerView.backgroundColor = UIColorRGBAlpha(0xADF4FF, 0.2); [self.messageTableView reloadData]; } } #pragma mark - UITableViewDelegate And UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.datasource.count; } //- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // XPMessageInfoModel* messageInfo = [self.datasource safeObjectAtIndex1:indexPath.row]; // // if(messageInfo.first == CustomMessageType_Room_Album){ // return 186; // }else if(messageInfo.first == CustomMessageType_Chat_Hall_Headlinesn){ // return 40; // } // // return messageInfo.rowHeight; //} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { XPMessageInfoModel* attr = [self.datasource safeObjectAtIndex1:indexPath.row]; if(attr.first == CustomMessageType_Room_Album){ PIRoomMessagePhotoAlbumCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])]; cell.delegate = self; cell.messageInfo = attr; cell.roomType = self.hostDelegate.getRoomInfo.type; return cell; }else if (attr.first == CustomMessageType_Chat_Hall_Headlinesn){ MsRoomMessagChatHallCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MsRoomMessagChatHallCell class]) forIndexPath:indexPath]; cell.model = attr; return cell; } XPRoomMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPRoomMessageTableViewCell class])]; cell.delegate = self; cell.messageInfo = attr; cell.roomType = self.hostDelegate.getRoomInfo.type; return cell; } #pragma mark - XPRoomMessageTableViewCellDelegate - (void)xPRoomMessageTableViewCellDidTapEmpty:(XPRoomMessageTableViewCell *)view { if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) { self.isLarge = !self.isLarge; CGFloat height = self.isLarge ? 200 : 80; [self mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(height); }]; } } #pragma mark - PIRoomMessagePhotoAlbumCell - (void)pIRoomMessagePhotoAlbumCellDelegateDidTapEmpty:(PIRoomMessagePhotoAlbumCell *)view{ if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) { self.isLarge = !self.isLarge; CGFloat height = self.isLarge ? 200 : 80; [self mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(height); }]; } } -(void)unlockAlbumHandleWithInfo:(PIRoomPhotoAlbumItemModel *_Nonnull)info{ PIRoomMessageUnlockPhotoAlbumView *albumView = [[PIRoomMessageUnlockPhotoAlbumView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; albumView.albumModel = info; albumView.delegate = self; [TTPopup popupView:albumView style:TTPopupStyleAlert]; } -(void)pIRoomMessagePhotoAlbumCell:(PIRoomMessagePhotoAlbumCell *_Nonnull)cell lookUpAlbumPhotoWithAlbumModel:(PIRoomPhotoAlbumItemModel *_Nonnull)albumModel;{ SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init]; browser.sourceImagesContainerView = cell; browser.delegate = self; browser.imageCount = 1; browser.currentImageIndex = 0; browser.isMe = NO; self.lookUpModel = albumModel; [browser show]; } - (void)pIRoomMessagePhotoAlbumCell:(PIRoomMessagePhotoAlbumCell *)cell lookUpUserCardModel:(PIRoomPhotoAlbumItemModel *)albumModel{ } #pragma mark - PIRoomMessageUnlockPhotoAlbumViewDelegate - (void)unlockRoomAlbumImageWithAlbumModel:(PIRoomPhotoAlbumItemModel *)albumModel{ [XNDJTDDLoadingTool showLoading]; [Api unlockRoomAlbumPhoto:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { [XNDJTDDLoadingTool hideHUD]; if(code == 200){ NSMutableDictionary *getData = [NSMutableDictionary dictionary]; [getData addEntriesFromDictionary:data.data]; AttachmentModel *attachment = [[AttachmentModel alloc] init]; attachment.first = CustomMessageType_Gift; attachment.second = Custom_Message_Sub_Gift_Send; NSDictionary *targetUsers = ((NSArray *)[getData objectForKey:@"targetUsers"]).firstObject; [getData setObject:[targetUsers valueForKeyPath:@"uid"] forKey:@"targetUid"]; [getData setObject:[targetUsers valueForKeyPath:@"nick"] forKey:@"targetNick"]; [getData setObject:[targetUsers valueForKeyPath:@"avatar"] forKey:@"targetAvatar"]; [getData setObject:@(YES) forKey:@"isRoomAlbum"]; attachment.data = getData; [self sendCustomMessage:attachment]; if(albumModel.ID != nil){ if(![[XPSkillCardPlayerManager shareInstance].photoIdList containsObject:albumModel.ID]){ if([XPSkillCardPlayerManager shareInstance].photoIdList == nil){ [XPSkillCardPlayerManager shareInstance].photoIdList = [NSMutableArray arrayWithArray:@[albumModel.ID]]; }else{ [[XPSkillCardPlayerManager shareInstance].photoIdList addObject:albumModel.ID]; } } [[NSNotificationCenter defaultCenter]postNotificationName:@"kGetgetUnlockRoomAlbumPhotoListNot" object:nil]; } return; } [XNDJTDDLoadingTool showErrorWithMessage:msg]; } id:albumModel.ID roomUid:@(self.hostDelegate.getRoomInfo.uid).stringValue]; } - (void)sendCustomMessage:(AttachmentModel *)attachment { NSString *sessionID = [NSString stringWithFormat:@"%ld", [self.hostDelegate getRoomInfo].roomId]; NIMMessage *message = [[NIMMessage alloc]init]; NIMCustomObject *object = [[NIMCustomObject alloc] init]; object.attachment = attachment; message.messageObject = object; UserInfoModel *userInfo = [self.hostDelegate getUserInfo]; XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init]; extModel.androidBubbleUrl = userInfo.androidBubbleUrl; extModel.iosBubbleUrl = userInfo.iosBubbleUrl; extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel; NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]]; message.remoteExt = remoteExt; NIMSessionType sessionType = NIMSessionTypeChatroom; //构造会话 NIMSession *session = [NIMSession session:sessionID type:sessionType]; [[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil]; } #pragma mark - SDPhotoBrowserDelegate - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index{ if(self.lookUpModel != nil){ return [[NSURL alloc]initWithString:self.lookUpModel.photoUrl]; } return nil; } - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { return [UIImageConstant defalutBannerPlaceholder]; } #pragma mark - Getters And Setters - (UITableView *)messageTableView { if (!_messageTableView) { _messageTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _messageTableView.delegate = self; _messageTableView.dataSource = self; _messageTableView.tableFooterView = [UIView new]; _messageTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _messageTableView.backgroundColor = [UIColor clearColor]; _messageTableView.showsVerticalScrollIndicator = NO; _messageTableView.tag = 666; if (@available(iOS 11.0, *)) { _messageTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } [_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomMessageTableViewCell class])]; [_messageTableView registerClass:[PIRoomMessagePhotoAlbumCell class] forCellReuseIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])]; [_messageTableView registerClass:[MsRoomMessagChatHallCell class] forCellReuseIdentifier:NSStringFromClass([MsRoomMessagChatHallCell class])]; } return _messageTableView; } - (UIView *)headerView { if (!_headerView) { _headerView = [[UIView alloc] init]; _headerView.layer.cornerRadius = 7; _headerView.layer.masksToBounds = YES; } return _headerView; } - (NSMutableArray *)datasource { if (!_datasource) { _datasource = [NSMutableArray array]; } return _datasource; } - (XPRoomMessageParser *)messageParser { if (!_messageParser) { _messageParser = [[XPRoomMessageParser alloc] init]; _messageParser.hostDelegate = self.hostDelegate; } return _messageParser; } - (UILabel *)titleView{ if(!_titleView){ _titleView = [UILabel labelInitWithText:@"" font:[UIFont systemFontOfSize:13 weight:UIFontWeightMedium] textColor:UIColorFromRGB(0x05FFE3)]; _titleView.textAlignment = NSTextAlignmentCenter; _titleView.numberOfLines = 0; } return _titleView; } @end