// // MsRoomMessageMainView.m // YuMi // // Created by duoban on 2024/5/10. // #import "MsRoomMessageMainView.h" #import "XPRoomMessageContainerView.h" #import "ClientConfig.h" #import "UserInfoModel.h" #import #import "Api+Message.h" #import "AttachmentModel.h" #import "RoomInfoModel.h" #import "BoomInfoModel.h" #import "XPSkillCardPlayerManager.h" @interface MsRoomMessageMainView() @property(nonatomic,strong) XPRoomMessageContainerView *messageListView; ///房间的代理 @property (nonatomic,weak) id hostDelegate; ///是否是大的 只有在小游戏的时候有用 @property (nonatomic,assign) BOOL isLarge; @property (nonatomic, strong) UIButton *buttonRoom; @property (nonatomic, strong) UIButton *buttonChat; @property (nonatomic, strong) UIButton *buttonGift; @property (nonatomic, strong) UIImageView *selectedMark; @end @implementation MsRoomMessageMainView - (instancetype)initWithDelegate:(id)delegate { self = [super init]; if (self) { self.hostDelegate = delegate; self.hidden = YES; [self installUI]; [self installConstraints]; [[NIMSDK sharedSDK].broadcastManager addDelegate:self]; } return self; } - (void)dealloc { [[NIMSDK sharedSDK].broadcastManager removeDelegate:self]; } -(void)installUI{ [self addSubview:self.buttonRoom]; [self addSubview:self.buttonChat]; [self addSubview:self.buttonGift]; [self addSubview:self.selectedMark]; [self addSubview:self.messageListView]; } -(void)installConstraints{ [self.buttonRoom mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self); make.leading.mas_equalTo(self).offset(15); make.height.mas_equalTo(20); }]; [self.buttonChat mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self); make.leading.mas_equalTo(self.buttonRoom.mas_trailing).offset(20); make.height.mas_equalTo(20); }]; [self.buttonGift mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self); make.leading.mas_equalTo(self.buttonChat.mas_trailing).offset(20); make.height.mas_equalTo(20); }]; [self.selectedMark mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self).offset(19); make.centerX.mas_equalTo(self.buttonRoom); make.size.mas_equalTo(CGSizeMake(9, 3)); }]; [self.messageListView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.buttonRoom.mas_bottom).offset(16); make.leading.bottom.trailing.mas_equalTo(self); }]; } - (void)showUserCard:(NSInteger)uid{ [self.messageListView showUserCard:uid]; } - (void)didTapButton:(UIButton *)sender { [self.messageListView changeType:sender.tag - 100]; [UIView animateWithDuration:0.2 animations:^{ [self.selectedMark mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self).offset(19); if (sender.tag == 101) { make.centerX.mas_equalTo(self.buttonRoom); } else if (sender.tag == 102) { make.centerX.mas_equalTo(self.buttonChat); } else { make.centerX.mas_equalTo(self.buttonGift); } make.size.mas_equalTo(CGSizeMake(10, 3)); }]; [self layoutIfNeeded]; }]; } #pragma mark - RoomGuestDelegate - (void)handleNIMCustomMessage:(NIMMessage *)message { UserInfoModel *infoModel = self.hostDelegate.getUserInfo; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[infoModel.partitionId]]; if(![message.session.sessionId isEqualToString:publicChatRoomId]){ [self.messageListView handleNIMCustomMessage:message]; return; } } - (void)handleNIMNotificationMessage:(NIMMessage *)message { UserInfoModel *infoModel = self.hostDelegate.getUserInfo; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[infoModel.partitionId]]; if(![message.session.sessionId isEqualToString:publicChatRoomId]){ [self.messageListView handleNIMNotificationMessage:message]; return; } } - (void)handleNIMTextMessage:(NIMMessage *)message { UserInfoModel *infoModel = self.hostDelegate.getUserInfo; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[infoModel.partitionId]]; if(![message.session.sessionId isEqualToString:publicChatRoomId]){ [self.messageListView handleNIMTextMessage:message]; return; } } - (void)handleNIMImageMessage:(NIMMessage *)message { } - (void)onRoomMiniEntered { self.hidden = NO; [self.messageListView onRoomMiniEntered]; } - (void)onRoomEntered { self.hidden = NO; [self.messageListView onRoomEntered]; } - (void)onRoomUpdate { [self.messageListView onRoomUpdate]; } #pragma mark - XPRoomMessageContainerViewDelegate - (void)xPRoomMessageContainerViewlDidTapEmpty:(XPRoomMessageContainerView *)view{ if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) { self.isLarge = !self.isLarge; CGFloat height = self.isLarge ? 200 : (iPhoneXSeries ? 100 : 80); [self mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(height); }]; } } #pragma mark - - (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage { if ([AccountInfoStorage instance].getUid.length == 0) { return; } if (broadcastMessage.content) { NSDictionary *msgDictionary = [broadcastMessage.content toJSONObject]; AttachmentModel *attachment = [AttachmentModel modelWithJSON:msgDictionary[@"body"]]; Boom632Model *m = [Boom632Model modelWithJSON:[attachment data]]; if (m.roomUid != [XPSkillCardPlayerManager shareInstance].roomUid.integerValue) { return; } } [self.messageListView handleBroadcastMessage:broadcastMessage]; } #pragma mark - 懒加载 - (NSInteger)type{ return 0; } - (XPRoomMessageContainerView *)messageListView{ if(!_messageListView){ _messageListView = [[XPRoomMessageContainerView alloc] initWithDelegate:self.hostDelegate]; _messageListView.delegate = self; } return _messageListView; } - (UIButton *)buttonRoom { if (!_buttonRoom) { _buttonRoom = [UIButton buttonWithType:UIButtonTypeCustom]; _buttonRoom.tag = 101; [_buttonRoom.titleLabel setFont:kFontMedium(14)]; [_buttonRoom setTitle:YMLocalizedString(@"RoomMessageTitle_0") forState:UIControlStateNormal]; [_buttonRoom addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; } return _buttonRoom; } - (UIButton *)buttonChat { if (!_buttonChat) { _buttonChat = [UIButton buttonWithType:UIButtonTypeCustom]; _buttonChat.tag = 102; [_buttonChat.titleLabel setFont:kFontMedium(14)]; [_buttonChat setTitle:YMLocalizedString(@"RoomMessageTitle_1") forState:UIControlStateNormal]; [_buttonChat addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; } return _buttonChat; } - (UIButton *)buttonGift { if (!_buttonGift) { _buttonGift = [UIButton buttonWithType:UIButtonTypeCustom]; _buttonGift.tag = 103; [_buttonGift.titleLabel setFont:kFontMedium(14)]; [_buttonGift setTitle:YMLocalizedString(@"RoomMessageTitle_2") forState:UIControlStateNormal]; [_buttonGift addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; } return _buttonGift; } - (UIImageView *)selectedMark { if (!_selectedMark) { _selectedMark = [[UIImageView alloc] init]; _selectedMark.backgroundColor = UIColorFromRGB(0x04D5C6); _selectedMark.layer.cornerRadius = 1; _selectedMark.layer.masksToBounds = YES; } return _selectedMark; } @end