跨房pk 邀请以及邀请之后的结果

This commit is contained in:
fengshuo
2022-01-11 14:38:55 +08:00
committed by chenguilong
parent 8b7e8f5aa5
commit e9c53b6e6a
24 changed files with 854 additions and 146 deletions

View File

@@ -34,6 +34,8 @@
#import "AnchorGiftValueView.h"
#import "XPRoomTopicViewController.h"
#import "XPRoomTopicAlertView.h"
#import "XPAcrossRoomPKInviteView.h"
#import "XPAcrossRoomPKInviteResultView.h"
@interface XPRoomFunctionContainerView ()
///host
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
@@ -57,9 +59,9 @@
@implementation XPRoomFunctionContainerView
- (void)dealloc {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
}
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
@@ -75,7 +77,7 @@
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.contributionButton];
[self addSubview:self.anchorGiftValueView];
[self addSubview:self.anchorGiftValueView];
[self addSubview:self.topicStackView];
[self.topicStackView addArrangedSubview:self.topicLabel];
[self.topicStackView addArrangedSubview:self.editButton];
@@ -88,11 +90,11 @@
make.width.mas_equalTo(90);
make.height.mas_equalTo(26);
}];
[self.anchorGiftValueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contributionButton.mas_right).mas_offset(8);
make.centerY.mas_equalTo(self.contributionButton);
make.height.mas_equalTo(26);
}];
[self.anchorGiftValueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contributionButton.mas_right).mas_offset(8);
make.centerY.mas_equalTo(self.contributionButton);
make.height.mas_equalTo(26);
}];
[self.topicStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
@@ -136,61 +138,139 @@
[self.datingProgresButton removeFromSuperview];
}
}
if (roomInfo.type == RoomType_Anchor) {
[self.contributionButton setTitle:@"主播榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = !roomInfo.showGiftValue;
if (!roomInfo.showGiftValue) {
self.anchorGiftValueView.giftValue = 0;
}
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+49);
}];
} else {
[self.contributionButton setTitle:@"房间榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = YES;
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+57);
}];
}
if (roomInfo.type == RoomType_Anchor) {
[self.contributionButton setTitle:@"主播榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = !roomInfo.showGiftValue;
if (!roomInfo.showGiftValue) {
self.anchorGiftValueView.giftValue = 0;
}
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+49);
}];
} else {
[self.contributionButton setTitle:@"房间榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = YES;
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+57);
}];
}
[self updateRoomTopic];
}
- (void)onRoomEntered {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSString * roomUid = [NSString stringWithFormat:@"%ld", roomInfo.uid];
if (roomInfo.type == RoomType_Anchor) {//
if (![[AccountInfoStorage instance].getUid isEqualToString:roomUid]) {//
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {//
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) {
[self setFollowAnchorTimer];
}
} uid:uid isLikeUid:roomUid];
}
}
if (roomInfo.type == RoomType_Anchor) {//
if (![[AccountInfoStorage instance].getUid isEqualToString:roomUid]) {//
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {//
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) {
[self setFollowAnchorTimer];
}
} uid:uid isLikeUid:roomUid];
}
}
[self updateRoomTopic];
}
- (void)onMicroGiftValueUpdate:(NSDictionary *)data {
[self handleAnchorGiftValue:data];
[self handleAnchorGiftValue:data];
}
- (void)handleNIMCustomMessage:(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_AnchorRoom_AudienceUpMic) {
[self showAskForUpMic:attachment.data];
} else if(attachment.first == CustomMessageType_Room_GiftValue && attachment.second == Custom_Message_Sub_Room_GiftValue_Sync) {
[self handleAnchorGiftValue:attachment.data];
} else if(attachment.first == CustomMessageType_Gift && (attachment.second == Custom_Message_Sub_Gift_Send || attachment.second == Custom_Message_Sub_Gift_LuckySend || attachment.second == Custom_Message_Sub_Gift_ChannelNotify)) {
[self handleAnchorGiftValue:attachment.data];
}else if(attachment.first == CustomMessageType_AllMicroSend && (attachment.second == Custom_Message_Sub_AllMicroSend || attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend)) {
[self handleAnchorGiftValue:attachment.data];
}
if (attachment.first == CustomMessageType_AnchorRoom_AudienceUpMic) {
[self showAskForUpMic:attachment.data];
} else if(attachment.first == CustomMessageType_Room_GiftValue && attachment.second == Custom_Message_Sub_Room_GiftValue_Sync) {
[self handleAnchorGiftValue:attachment.data];
} else if(attachment.first == CustomMessageType_Gift && (attachment.second == Custom_Message_Sub_Gift_Send || attachment.second == Custom_Message_Sub_Gift_LuckySend || attachment.second == Custom_Message_Sub_Gift_ChannelNotify)) {
[self handleAnchorGiftValue:attachment.data];
}else if(attachment.first == CustomMessageType_AllMicroSend && (attachment.second == Custom_Message_Sub_AllMicroSend || attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend)) {
[self handleAnchorGiftValue:attachment.data];
} else if (attachment.first == CustomMessageType_Across_Room_PK) {
switch (attachment.second) {
case Custom_Message_Sub_AcrossRoomPK_Invite:
{
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMTeamMemberTypeOwner) {
XPAcrossRoomPKInviteView * inviteView = [[XPAcrossRoomPKInviteView alloc] init];
inviteView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
inviteView.dataDic = attachment.data;
[self addSubview:inviteView];
[inviteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
}];
}
}
}];
}
break;
case Custom_Message_Sub_AcrossRoomPK_Accept:
{
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMTeamMemberTypeOwner) {
XPAcrossRoomPKInviteResultView * inviteResutView = [[XPAcrossRoomPKInviteResultView alloc] init];
inviteResutView.isAccept = YES;
[self addSubview:inviteResutView];
[inviteResutView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(114 + kSafeAreaTopHeight);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(281, 42));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[inviteResutView removeFromSuperview];
});
}
}
}];
}
break;
case Custom_Message_Sub_AcrossRoomPK_Reject:
{
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMTeamMemberTypeOwner) {
XPAcrossRoomPKInviteResultView * inviteResutView = [[XPAcrossRoomPKInviteResultView alloc] init];
inviteResutView.isAccept = NO;
[self addSubview:inviteResutView];
[inviteResutView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(114 + kSafeAreaTopHeight);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(281, 42));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[inviteResutView removeFromSuperview];
});
}
}
}];
}
break;
default:
break;
}
}
}
}
- (void)handleNIMNotificationMessage:(NIMMessage *)message {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
@@ -235,11 +315,11 @@
if (roomInfo.blindDateState == RoomPlayDateingType_Talk) {
message = @"进入心动选人环节?";
} else if(roomInfo.blindDateState == RoomPlayDateingType_Pick) {
message = @"进入心动公布环节?";
message = @"进入心动公布环节?";
} else if(roomInfo.blindDateState == RoomPlayDateingType_Result) {
message = @"结束本轮,同时清空魅力值?";
message = @"结束本轮,同时清空魅力值?";
} else if (roomInfo.blindDateState == RoomPlayDateingType_Finish) {
message = @"进入嘉宾交流环节?";
message = @"进入嘉宾交流环节?";
}
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.message = message;
@@ -258,13 +338,13 @@
}];}
- (void)tapGiftValueRecognizer {
if (self.anchorGiftValueView.hidden) return;
if (self.delegate.getUserInfo && self.delegate.getUserInfo.uid > 0) {
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
webView.url = [NSString stringWithFormat:@"%@?uid=%ld", URLWithType(kRoomCharmRankURL), self.delegate.getRoomInfo.uid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
}
if (self.anchorGiftValueView.hidden) return;
if (self.delegate.getUserInfo && self.delegate.getUserInfo.uid > 0) {
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
webView.url = [NSString stringWithFormat:@"%@?uid=%ld", URLWithType(kRoomCharmRankURL), self.delegate.getRoomInfo.uid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
}
}
#pragma mark -
@@ -277,7 +357,7 @@
offsetY += (120 + 5 + 6 + 20 +60 + 3);
} else {
offsetY += (58 + 5 + 6 + 12 + 3 );
}
}
[self.topicStackView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(offsetY);
@@ -329,84 +409,84 @@
#pragma mark -
- (void)setFollowAnchorTimer {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
#ifdef DEBUG
NSInteger totalTime = 5;
NSInteger totalTime = 5;
#else
NSInteger totalTime = 420;
NSInteger totalTime = 420;
#endif
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.followAnchorTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.followAnchorTimer,dispatch_walltime(NULL, totalTime*NSEC_PER_SEC), totalTime*NSEC_PER_SEC, 0); //
@weakify(self);
dispatch_source_set_event_handler(self.followAnchorTimer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
self.followAnchorTimer = nil;
}
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) { //
if (self.window) {
[self showFollowAnchorView];
}
}
} uid:uid isLikeUid:roomUid];
});
});
dispatch_resume(self.followAnchorTimer);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.followAnchorTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.followAnchorTimer,dispatch_walltime(NULL, totalTime*NSEC_PER_SEC), totalTime*NSEC_PER_SEC, 0); //
@weakify(self);
dispatch_source_set_event_handler(self.followAnchorTimer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
self.followAnchorTimer = nil;
}
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) { //
if (self.window) {
[self showFollowAnchorView];
}
}
} uid:uid isLikeUid:roomUid];
});
});
dispatch_resume(self.followAnchorTimer);
}
//
- (void)showFollowAnchorView {
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
UserInfoModel *userInfo = [UserInfoModel modelWithDictionary:data.data];
XPRoomAnchorInfoCardView *view = [[XPRoomAnchorInfoCardView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 300)];
view.userInfo = self.delegate.getUserInfo;
view.targetUserInfo = userInfo;
view.roomId =roomInfo.roomId;
[TTPopup popupView:view style:TTPopupStyleActionSheet];
} uid:roomUid];
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
UserInfoModel *userInfo = [UserInfoModel modelWithDictionary:data.data];
XPRoomAnchorInfoCardView *view = [[XPRoomAnchorInfoCardView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 300)];
view.userInfo = self.delegate.getUserInfo;
view.targetUserInfo = userInfo;
view.roomId =roomInfo.roomId;
[TTPopup popupView:view style:TTPopupStyleActionSheet];
} uid:roomUid];
}
///
- (void)showAskForUpMic:(NSDictionary *)dict {
NSString *roomUid = [NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid];
if (![roomUid isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
UserInfoModel *model = [UserInfoModel modelWithJSON:dict];
XPAnchorAudienceUpMicView *upMicView = [[XPAnchorAudienceUpMicView alloc] initWithFrame:CGRectMake(0, 0, 300, 226) delegate:self.delegate];
upMicView.info = model;
TTPopupConfig *config = [[TTPopupConfig alloc] init];
config.filterIdentifier = @"audienceRequestUpMic";
config.shouldFilterPopup = YES;
config.contentView = upMicView;
config.style = TTPopupStyleAlert;
[TTPopup popupWithConfig:config];
NSString *roomUid = [NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid];
if (![roomUid isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
UserInfoModel *model = [UserInfoModel modelWithJSON:dict];
XPAnchorAudienceUpMicView *upMicView = [[XPAnchorAudienceUpMicView alloc] initWithFrame:CGRectMake(0, 0, 300, 226) delegate:self.delegate];
upMicView.info = model;
TTPopupConfig *config = [[TTPopupConfig alloc] init];
config.filterIdentifier = @"audienceRequestUpMic";
config.shouldFilterPopup = YES;
config.contentView = upMicView;
config.style = TTPopupStyleAlert;
[TTPopup popupWithConfig:config];
}
- (void)handleAnchorGiftValue:(NSDictionary *)dict {
if (self.delegate.getRoomInfo.type != RoomType_Anchor) {//
return;
}
GiftValueInfoModel * model = [GiftValueInfoModel modelWithDictionary:dict];
for (int i = 0; i < model.giftValueVos.count; i++) {
GiftValueDetailModel * giftValueModel = [model.giftValueVos objectAtIndex:i];
if (![giftValueModel.uid isEqualToString:[NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid]]) {
continue;
}
self.anchorGiftValueView.giftValue = giftValueModel.giftValue;
}
if (self.delegate.getRoomInfo.type != RoomType_Anchor) {//
return;
}
GiftValueInfoModel * model = [GiftValueInfoModel modelWithDictionary:dict];
for (int i = 0; i < model.giftValueVos.count; i++) {
GiftValueDetailModel * giftValueModel = [model.giftValueVos objectAtIndex:i];
if (![giftValueModel.uid isEqualToString:[NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid]]) {
continue;
}
self.anchorGiftValueView.giftValue = giftValueModel.giftValue;
}
}
#pragma mark - Getters And Setters
@@ -442,15 +522,15 @@
}
- (AnchorGiftValueView *)anchorGiftValueView {
if (!_anchorGiftValueView) {
_anchorGiftValueView = [[AnchorGiftValueView alloc] init];
_anchorGiftValueView.hidden = YES;
_anchorGiftValueView.layer.cornerRadius = 13;
_anchorGiftValueView.layer.masksToBounds = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGiftValueRecognizer)];
[_anchorGiftValueView addGestureRecognizer:tap];
}
return _anchorGiftValueView;
if (!_anchorGiftValueView) {
_anchorGiftValueView = [[AnchorGiftValueView alloc] init];
_anchorGiftValueView.hidden = YES;
_anchorGiftValueView.layer.cornerRadius = 13;
_anchorGiftValueView.layer.masksToBounds = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGiftValueRecognizer)];
[_anchorGiftValueView addGestureRecognizer:tap];
}
return _anchorGiftValueView;
}
- (UIStackView *)topicStackView {