From e45176485da9de16e8f1715710009dce94af34e8 Mon Sep 17 00:00:00 2001 From: eggmanQQQ <3671373519@qq.com> Date: Thu, 5 Sep 2024 19:43:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9E=84=E5=BB=BA=E9=80=81=E7=A4=BC?= =?UTF-8?q?=E8=BF=9E=E5=87=BB=20manager=EF=BC=8C=20=20=E4=BB=8E=20send=20g?= =?UTF-8?q?ift=20view=20=E4=B8=AD=E6=8A=BD=E7=A6=BB=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=A4=BC=E7=89=A9-=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YuMi.xcodeproj/project.pbxproj | 12 + .../MsRoomMessageMainView.m | 82 +----- .../View/SendGiftView/GiftComboManager.h | 43 +++ .../View/SendGiftView/GiftComboManager.m | 278 ++++++++++++++++++ .../View/SendGiftView/Model/GiftInfoModel.h | 2 +- .../View/SendGiftView/View/GiftComboView.h | 16 + .../View/SendGiftView/View/GiftComboView.m | 19 ++ .../View/SendGiftView/View/XPSendGiftView.m | 36 ++- .../YMRoom/View/XPRoomViewController.m | 25 ++ 9 files changed, 435 insertions(+), 78 deletions(-) create mode 100644 YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h create mode 100644 YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m create mode 100644 YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.h create mode 100644 YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.m diff --git a/YuMi.xcodeproj/project.pbxproj b/YuMi.xcodeproj/project.pbxproj index 5598aa1f..5b7d0736 100644 --- a/YuMi.xcodeproj/project.pbxproj +++ b/YuMi.xcodeproj/project.pbxproj @@ -498,6 +498,8 @@ 23FF42762AA6E1480055733C /* XPHomeRecommendOtherRoomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FF42752AA6E1480055733C /* XPHomeRecommendOtherRoomView.m */; }; 23FF42792AA6E19C0055733C /* HomeMenuSourceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FF42782AA6E19C0055733C /* HomeMenuSourceModel.m */; }; 23FF428E2AAB2D3A0055733C /* XPCandyTreeBuyView.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FF428D2AAB2D3A0055733C /* XPCandyTreeBuyView.m */; }; + 540EC1D02C89925F00F3BF0D /* GiftComboView.m in Sources */ = {isa = PBXBuildFile; fileRef = 540EC1CF2C89925F00F3BF0D /* GiftComboView.m */; }; + 540EC1D32C89998500F3BF0D /* GiftComboManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 540EC1D22C89998500F3BF0D /* GiftComboManager.m */; }; 5412E0F42C4E460300FDD668 /* XPMineCenterAgencyView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5412E0F32C4E460300FDD668 /* XPMineCenterAgencyView.m */; }; 5412E0FD2C52512100FDD668 /* RoomBottomEntranceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5412E0FC2C52512100FDD668 /* RoomBottomEntranceModel.m */; }; 541DD9552C1EDEFB00B616C4 /* XPHomePagingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 541DD9542C1EDEFB00B616C4 /* XPHomePagingViewController.m */; }; @@ -2524,6 +2526,10 @@ 23FF42782AA6E19C0055733C /* HomeMenuSourceModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeMenuSourceModel.m; sourceTree = ""; }; 23FF428C2AAB2D3A0055733C /* XPCandyTreeBuyView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPCandyTreeBuyView.h; sourceTree = ""; }; 23FF428D2AAB2D3A0055733C /* XPCandyTreeBuyView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPCandyTreeBuyView.m; sourceTree = ""; }; + 540EC1CE2C89925F00F3BF0D /* GiftComboView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiftComboView.h; sourceTree = ""; }; + 540EC1CF2C89925F00F3BF0D /* GiftComboView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiftComboView.m; sourceTree = ""; }; + 540EC1D12C89998500F3BF0D /* GiftComboManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiftComboManager.h; sourceTree = ""; }; + 540EC1D22C89998500F3BF0D /* GiftComboManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiftComboManager.m; sourceTree = ""; }; 5412E0F22C4E460300FDD668 /* XPMineCenterAgencyView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineCenterAgencyView.h; sourceTree = ""; }; 5412E0F32C4E460300FDD668 /* XPMineCenterAgencyView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineCenterAgencyView.m; sourceTree = ""; }; 5412E0FB2C52512100FDD668 /* RoomBottomEntranceModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoomBottomEntranceModel.h; sourceTree = ""; }; @@ -9199,6 +9205,8 @@ E8788939273A544000BF1D57 /* Protocol */, E878894E273A699900BF1D57 /* ThemeColor+SendGift.h */, E878894F273A699900BF1D57 /* ThemeColor+SendGift.m */, + 540EC1D12C89998500F3BF0D /* GiftComboManager.h */, + 540EC1D22C89998500F3BF0D /* GiftComboManager.m */, ); path = SendGiftView; sourceTree = ""; @@ -9267,6 +9275,8 @@ 23630BA52BAC3888003AD25D /* PIGiftSuperGiftBroadcastView.m */, E8D4DE422940462C00EC788D /* XPGiftTwelveStarBroadcastView.h */, E8D4DE432940462C00EC788D /* XPGiftTwelveStarBroadcastView.m */, + 540EC1CE2C89925F00F3BF0D /* GiftComboView.h */, + 540EC1CF2C89925F00F3BF0D /* GiftComboView.m */, ); path = View; sourceTree = ""; @@ -12404,6 +12414,7 @@ 238B37B02AC55A2C00BFC9D5 /* XPTreasureFairyStoreResultCell.m in Sources */, E88B5CC126FB407B00DA9178 /* XPMineUserInfoViewController.m in Sources */, 2331C1AC2A60F32D00E1D940 /* CandyTreeRecordModel.m in Sources */, + 540EC1D32C89998500F3BF0D /* GiftComboManager.m in Sources */, E81E09CF290F750800A1F410 /* AdvertiseModel.m in Sources */, 2305F3472AD94E9D00AD403C /* XPMaskManagerCell.m in Sources */, E852D74428633A08001465ED /* MonentsCommentModel.m in Sources */, @@ -12588,6 +12599,7 @@ E89DCF5728FFF076001647EC /* XPWishGiftEmptyTableViewCell.m in Sources */, 237700D32BC7CC7C00D661F1 /* NSObject+MJExtension.m in Sources */, E8D4DE442940462C00EC788D /* XPGiftTwelveStarBroadcastView.m in Sources */, + 540EC1D02C89925F00F3BF0D /* GiftComboView.m in Sources */, E81060DF29876D3A00B772F0 /* MessageTimeModel.m in Sources */, E81A65422835120200F55894 /* XPMonentsInteractivePresenter.m in Sources */, 238B37A82AC55A2C00BFC9D5 /* TreasureFairyTrialsRecordModel.m in Sources */, diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessageMainView.m b/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessageMainView.m index 6725d2e6..ac7d6813 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessageMainView.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessageMainView.m @@ -4,9 +4,6 @@ // // Created by duoban on 2024/5/10. // -#import -#import -#import #import "MsRoomMessageMainView.h" #import "XPRoomMessageContainerView.h" #import "ClientConfig.h" @@ -15,13 +12,8 @@ #import "Api+Message.h" #import "AttachmentModel.h" #import "RoomInfoModel.h" -@interface MsRoomMessageMainView() -///分页标题 -@property (nonatomic, strong) NSArray *titles; -///分页控件 -@property (nonatomic, strong) JXCategoryTitleView *titleView; -///分页lineView -@property (nonatomic, strong) JXCategoryListContainerView *pi_containerView; +@interface MsRoomMessageMainView() + @property(nonatomic,strong) XPRoomMessageContainerView *roomView; ///房间的代理 @@ -32,43 +24,29 @@ @implementation MsRoomMessageMainView - - (instancetype)initWithDelegate:(id)delegate { self = [super init]; if (self) { self.hostDelegate = delegate; + +// TODO: 处理连击飘屏 + [self installUI]; [self installConstraints]; } return self; } -(void)installUI{ - [self addSubview:self.titleView]; - [self addSubview:self.pi_containerView]; + [self addSubview:self.roomView]; } -(void)installConstraints{ - [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.leading.mas_equalTo(kGetScaleWidth(0)); - make.width.mas_equalTo(150); - make.height.mas_equalTo(kGetScaleWidth(30)); - }]; - - [self.pi_containerView mas_makeConstraints:^(MASConstraintMaker *make) { - make.leading.trailing.bottom.mas_equalTo(self); - make.top.mas_equalTo(self.titleView.mas_bottom).offset(8); + [self.roomView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.mas_equalTo(self); }]; } - (void)showUserCard:(NSInteger)uid{ [self.roomView showUserCard:uid]; } -#pragma mark - JXCategoryViewDelegate -- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView { - return self.titles.count; -} - -- (id)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index { - return self.roomView; -} #pragma mark - RoomGuestDelegate - (void)handleNIMCustomMessage:(NIMMessage *)message { @@ -126,51 +104,9 @@ #pragma mark - 懒加载 - (NSInteger)type{ - return self.titleView.selectedIndex; -} -- (JXCategoryTitleView *)titleView { - if (!_titleView) { - _titleView = [[JXCategoryTitleView alloc] init]; - _titleView.delegate = self; - _titleView.titles = self.titles; - _titleView.backgroundColor = [UIColor clearColor]; - _titleView.titleColor = [UIColor colorWithWhite:1 alpha:0.6]; - _titleView.titleSelectedColor = UIColorFromRGB(0xFFFFFF); - _titleView.titleFont = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; - _titleView.titleSelectedFont = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; - _titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter; - _titleView.contentScrollViewClickTransitionAnimationEnabled = NO; - _titleView.defaultSelectedIndex = 0; - _titleView.cellSpacing = 20; - _titleView.cellWidthIncrement = 5; - _titleView.cellWidth = 30; - _titleView.listContainer = self.pi_containerView; - - JXCategoryIndicatorImageView *lineView = [[JXCategoryIndicatorImageView alloc] init]; - lineView.indicatorImageViewSize = CGSizeMake(8, 1.5); - lineView.verticalMargin = 0; - lineView.indicatorImageView.image = [UIImage imageWithColor:UIColorFromRGB(0x10ECD6) size:CGSizeMake(8, 1.5)]; - lineView.indicatorImageView.layer.masksToBounds = YES; - lineView.indicatorImageView.layer.cornerRadius = 1.5/2; - _titleView.indicators = @[lineView]; - } - return _titleView; + return 0; } -- (NSArray *)titles{ - if(!_titles){ - _titles = @[YMLocalizedString(@"XPMineMainGuildListVC1")]; - } - return _titles; -} -- (JXCategoryListContainerView *)pi_containerView { - if (!_pi_containerView) { - _pi_containerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self]; - _pi_containerView.defaultSelectedIndex = 0; - _pi_containerView.scrollView.tag = 1009; - } - return _pi_containerView; -} - (XPRoomMessageContainerView *)roomView{ if(!_roomView){ _roomView = [[XPRoomMessageContainerView alloc] initWithDelegate:self.hostDelegate]; diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h new file mode 100644 index 00000000..41dbe52b --- /dev/null +++ b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h @@ -0,0 +1,43 @@ +// +// GiftComboManager.h +// YuMi +// +// Created by P on 2024/9/5. +// + +#import + +#import "GiftInfoModel.h" + +@class GiftReceiveInfoModel, UserInfoModel; + +typedef enum : NSUInteger { + ComboAction_ShowPanel, + ComboAction_RemovePanel +} ComboActionType; + + +NS_ASSUME_NONNULL_BEGIN + +@interface GiftComboManager : NSObject + +// 单例方法 ++ (instancetype)sharedManager; + +- (void)registerActions:(void(^ _Nullable)(ComboActionType type))action; + + +- (void)saveSendGiftTo:(NSArray *)UIDs; +- (void)saveGiftSourceType:(GiftSourceType)type; +- (void)saveSendGiftInfo:(GiftInfoModel *)model; +- (void)saveSendGiftType:(RoomSendGiftType)type; +- (void)saveRoomUID:(NSString *)roomUID; +- (void)saveSendGiftNum:(NSString *)numString; +- (void)saveUserInfo:(UserInfoModel *)userInfo; +- (void)saveSessionID:(NSString *)sessionID; + +- (void)resetCombo; + +@end + +NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m new file mode 100644 index 00000000..db4fa64a --- /dev/null +++ b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m @@ -0,0 +1,278 @@ +// +// GiftComboManager.m +// YuMi +// +// Created by P on 2024/9/5. +// +// 处理连击面板逻辑 + +#import "GiftComboManager.h" + +#import "UserInfoModel.h" +#import "AttachmentModel.h" +#import "GiftReceiveInfoModel.h" +#import "XPMessageRemoteExtModel.h" + +#import "Api+Gift.h" + +@interface GiftComboManager () + +// 用来存储 GiftReceiveInfoModel 和 NSDictionary 的元数据队列 +@property (nonatomic, strong) NSMutableArray *giftComboQueue; + +// 定时器,处理请求的调度器 +@property (nonatomic, strong) dispatch_source_t timer; + +@property (nonatomic, copy) NSArray *sendGiftToUIDs; +@property (nonatomic, assign) GiftSourceType giftSourceType; +@property (nonatomic, strong) GiftInfoModel *giftInfo; +@property (nonatomic, assign) RoomSendGiftType roomSendGiftType; +@property (nonatomic, copy) NSString *roomUID; +@property (nonatomic, copy) NSString *giftNumPerTimes; +@property (nonatomic, strong) UserInfoModel *sendGiftUserInfo; +@property (nonatomic, copy) NSString *sessionID; + +@property (nonatomic, assign) NSInteger combo; + +@end + +@implementation GiftComboManager + +#pragma mark - 单例方法 + ++ (instancetype)sharedManager { + static GiftComboManager *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + sharedInstance.giftComboQueue = [NSMutableArray array]; + }); + return sharedInstance; +} + +// 添加 GiftReceiveInfoModel 和 metadata 到队列 +- (void)addGiftComboWithInfo:(GiftReceiveInfoModel *)info andMetadata:(NSDictionary *)metadata { + if (info && metadata) { + // 将元数据打包成字典并添加到队列 + @synchronized (self) { + NSDictionary *comboData = @{@"info": info, @"metadata": metadata}; + [self.giftComboQueue addObject:comboData]; + } + // 启动定时器 + [self startProcessingQueue]; + } +} + +- (void)addComboFromNIMAttachment:(AttachmentModel *)attachment { + if (attachment) { + // 将元数据打包成字典并添加到队列 + @synchronized (self) { + [self.giftComboQueue addObject:attachment]; + } + // 启动定时器 + [self startProcessingQueue]; + } +} + +// 开始连击,重置 +- (void)resetCombo { + _combo = 1; +} + +// MARK: Logic is 连击面板出现后,每点击一次,就触发一次面板最后的请求,请求成功后,构造云信消息体,消息体进入队列并按 0.2s 一次的频率发送消息 + +#pragma mark - 管理队列 + +// 开始处理队列 +- (void)startProcessingQueue { + if (self.timer) { + return; // 如果定时器已经在运行,直接返回 + } + + // 创建 GCD 定时器 + self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue()); + + // 设置定时器时间间隔:每 0.2 秒执行一次 + dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC, 0.01 * NSEC_PER_SEC); + + // 定时器触发的事件处理 + dispatch_source_set_event_handler(self.timer, ^{ + [self processGiftComboQueue]; + }); + + // 启动定时器 + dispatch_resume(self.timer); +} + +// 停止处理队列 +- (void)stopProcessingQueue { + if (self.timer) { + dispatch_source_cancel(self.timer); + self.timer = nil; + } +} + +// 处理队列中的第一个请求 +- (void)processGiftComboQueue { + @synchronized (self) { + if (self.giftComboQueue.count > 0) { + // 获取并移除队列中的第一个元数据 + AttachmentModel *attachment = [self.giftComboQueue firstObject]; + [self.giftComboQueue removeObjectAtIndex:0]; + + // 处理逻辑 + [self processGiftComboWith:attachment]; + } else { + // 如果队列为空,停止定时器 + [self stopProcessingQueue]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSLog(@"礼物处理完成"); + }); + } + } +} + +// 处理元数据的实际逻辑 +- (void)processGiftComboWith:(AttachmentModel *)info { + [self sendCustomMessage:info]; +} + +#pragma mark - Gift meta data +- (void)saveSendGiftTo:(NSArray *)UIDs +{ + _sendGiftToUIDs = UIDs; +} + +- (void)saveGiftSourceType:(GiftSourceType)type +{ + _giftSourceType = type; +} + +- (void)saveSendGiftInfo:(GiftInfoModel *)model +{ + _giftInfo = model; +} + +- (void)saveSendGiftType:(RoomSendGiftType)type +{ + _roomSendGiftType = type; +} + +- (void)saveRoomUID:(NSString *)roomUID { + _roomUID = roomUID; +} + +- (void)saveSendGiftNum:(NSString *)numString +{ + _giftNumPerTimes = numString; +} + +- (void)saveUserInfo:(UserInfoModel *)userInfo { + _sendGiftUserInfo = userInfo; +} + +- (void)saveSessionID:(NSString *)sessionID { + _sessionID = sessionID; +} + +#pragma mark - XPGiftPresenter + +- (void)sendGift { + NSString *allUIDs = @""; + for (NSString *item in self.sendGiftToUIDs) { + if (allUIDs.length > 0) { + allUIDs = [allUIDs stringByAppendingString:@","]; + } + allUIDs = [allUIDs stringByAppendingString:item]; + } + @kWeakify(self); + [Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + @kStrongify(self); + if (code == 200) { + GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data]; + receive.sourceType = self.giftSourceType; + receive.roomSendGiftType = self.roomSendGiftType; + [self handleSendGiftSuccess:data]; + } else { +// TODO: 发送失败处理 + } + } + targetUids:allUIDs + giftNum:self.giftNumPerTimes + sendType:[NSString stringWithFormat:@"%ld", GiftSendType_OnMic] + giftId:[NSString stringWithFormat:@"%ld", self.giftInfo.giftId] + giftSource:[NSString stringWithFormat:@"%ld", self.giftSourceType] + giftType:[NSString stringWithFormat:@"%ld", self.giftInfo.giftType] + roomUid:self.roomUID + msg:@"" + uid:[AccountInfoStorage instance].getUid]; +} + +- (void)handleSendGiftSuccess:(BaseModel *)response { + GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:response.data]; + if (!receive) { + return; + } + + NSDictionary *tempDic = response.data; + NSMutableDictionary *data = [NSMutableDictionary dictionary]; + [data addEntriesFromDictionary:tempDic]; + + AttachmentModel *attachment = [[AttachmentModel alloc] init]; + switch (receive.roomSendGiftType) { + case RoomSendGiftType_AllMic: { + attachment.first = CustomMessageType_AllMicroSend; + attachment.second = Custom_Message_Sub_AllMicroSend; + [data setObject:[tempDic valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"]; + attachment.data = data; + } + break; + case RoomSendGiftType_MutableOnMic: { + attachment.first = CustomMessageType_AllMicroSend; + attachment.second = Custom_Message_Sub_AllBatchSend; + attachment.data = data; + } + break; + case RoomSendGiftType_ToOne: { + attachment.first = CustomMessageType_Gift; + attachment.second = Custom_Message_Sub_Gift_Send; + NSDictionary *targetUsers = ((NSArray *)[data objectForKey:@"targetUsers"]).firstObject; + [data setObject:[targetUsers valueForKeyPath:@"uid"] forKey:@"targetUid"]; + [data setObject:[targetUsers valueForKeyPath:@"nick"] forKey:@"targetNick"]; + [data setObject:[targetUsers valueForKeyPath:@"avatar"] forKey:@"targetAvatar"]; + attachment.data = data; + } + break; + default: + attachment = nil; + break; + } + + if (attachment) { + + // TODO: 添加到队列 + [self sendCustomMessage:attachment]; + } +} + +- (void)sendCustomMessage:(AttachmentModel *)attachment { + NIMMessage *message = [[NIMMessage alloc]init]; + NIMCustomObject *object = [[NIMCustomObject alloc] init]; + object.attachment = attachment; + message.messageObject = object; + + UserInfoModel *userInfo = self.sendGiftUserInfo; + 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; + + //构造会话 + NIMSession *session = [NIMSession session:self.sessionID type:NIMSessionTypeChatroom]; + [[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil]; +} + + +@end diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/Model/GiftInfoModel.h b/YuMi/Modules/YMRoom/View/SendGiftView/Model/GiftInfoModel.h index 5a33dfe8..ce0744ac 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/Model/GiftInfoModel.h +++ b/YuMi/Modules/YMRoom/View/SendGiftView/Model/GiftInfoModel.h @@ -51,7 +51,7 @@ typedef NS_ENUM(NSUInteger, GiftOtherViewType) { typedef NS_ENUM(NSUInteger, GiftSendType) { GiftSendType_Room = 1,///zho GiftSendType_Chat = 2, - GiftSendType_OnMic = 3, +GiftSendType_OnMic = 3, }; /** diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.h b/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.h new file mode 100644 index 00000000..d0c66897 --- /dev/null +++ b/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.h @@ -0,0 +1,16 @@ +// +// GiftComboView.h +// YuMi +// +// Created by P on 2024/9/5. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GiftComboView : UIView + +@end + +NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.m b/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.m new file mode 100644 index 00000000..43efb174 --- /dev/null +++ b/YuMi/Modules/YMRoom/View/SendGiftView/View/GiftComboView.m @@ -0,0 +1,19 @@ +// +// GiftComboView.m +// YuMi +// +// Created by P on 2024/9/5. +// + +#import "GiftComboView.h" + +@implementation GiftComboView + +- (instancetype)init { + if (self = [super init]) { + + } + return self; +} + +@end diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m index 69178574..9e23bb90 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m +++ b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m @@ -47,6 +47,9 @@ #import "XPIAPRechargeViewController.h" #import "XPWebViewController.h" #import "PIGiftSuperGiftBroadcastView.h" + +#import "GiftComboManager.h" + UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification; UIKIT_EXTERN NSString * kShowFirstRechargeView; @@ -98,6 +101,8 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; @property (nonatomic, assign) bool didLoadPackGiftList; +@property (nonatomic, strong) NSMutableArray *sendGiftMessageArray; + @end @implementation XPSendGiftView @@ -109,6 +114,7 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; -(void)dealloc{ [[NSNotificationCenter defaultCenter]removeObserver:self]; } + - (instancetype)initWithType:(SendGiftType)type uid:(NSString * __nullable)uid{ if (self = [super init]) { self.modalPresentationStyle = UIModalPresentationOverFullScreen; @@ -404,6 +410,26 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; } } +/// 初始化/重置 连击礼物功能状态 +- (void)readyForCombo:(XPGiftCountModel *)giftCount { + if (self.segmentType == GiftSegmentType_Pack || + self.segmentType == GiftSegmentType_Lucky) { + return; + } + + NSString *sessionID = self.usingplaceType == SendGiftType_User ? [NSString stringWithFormat:@"%ld", self.userArray.firstObject.uid] : [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].roomId]; + + GiftInfoModel *giftInfo = self.giftInfoView.lastSelectGift; + [[GiftComboManager sharedManager] saveSendGiftTo:[self.userView getSelectUserList]]; + [[GiftComboManager sharedManager] saveGiftSourceType:giftInfo.sourceType]; + [[GiftComboManager sharedManager] saveSendGiftInfo:giftInfo]; + [[GiftComboManager sharedManager] saveSendGiftType:[self dealRoomSendGiftType:giftInfo giftCount:giftCount]]; + [[GiftComboManager sharedManager] saveSendGiftNum:[self dealSendGiftCount:giftCount gift:giftInfo]]; + [[GiftComboManager sharedManager] saveRoomUID:self.roomUid]; + [[GiftComboManager sharedManager] saveUserInfo:self.delegate.getUserInfo]; + [[GiftComboManager sharedManager] saveSessionID:sessionID]; +} + #pragma mark - XPGiftBarViewDelegate - (void)xPGiftBarView:(XPGiftBarView *)view didClickSendGift:(XPGiftCountModel *)giftCount { ///总礼物 三要素 送礼物的人 送的什么礼物 送多少个礼物 @@ -458,9 +484,9 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; ///充值 - (void)xPGiftBarViewDidClickRecharge:(XPGiftBarView *)view { - @kWeakify(self); +// @kWeakify(self); [self dismissViewControllerAnimated:NO completion:^{ - @kStrongify(self); +// @kStrongify(self); XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init]; rechargeVC.type = @"4"; [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES]; @@ -556,7 +582,7 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; self.giftBarView.drawGiftCount = 10; [self.superGiftView removeFromSuperview]; [self.luckyBroadcastView removeFromSuperview]; - [self.constellationBanner removeFromSuperview]; + [self.constellationBanner removeFromSuperview]; switch (type) { case GiftSegmentType_Lucky: { @@ -782,12 +808,14 @@ UIKIT_EXTERN NSString * kShowFirstRechargeView; } else { self.giftBarView.walletInfoModel = receiveInfo.userPurse; } + @kWeakify(self); - dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)); + dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)); dispatch_after(delayTime, dispatch_get_main_queue(), ^{ @kStrongify(self); if (self) { [self sendCustomMessage:receiveInfo oringinDic:originDic]; + [[GiftComboManager sharedManager] resetCombo]; } }); diff --git a/YuMi/Modules/YMRoom/View/XPRoomViewController.m b/YuMi/Modules/YMRoom/View/XPRoomViewController.m index 369bf189..38087935 100644 --- a/YuMi/Modules/YMRoom/View/XPRoomViewController.m +++ b/YuMi/Modules/YMRoom/View/XPRoomViewController.m @@ -83,6 +83,8 @@ #import "XPIAPRechargeViewController.h" #import "XPCandyTreeInsufficientBalanceView.h" +#import "GiftComboManager.h" + UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; UIKIT_EXTERN NSString * const kRoomMiniNotificationKey; UIKIT_EXTERN NSString * kNewUserRechargeKey; @@ -281,6 +283,8 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出 [[NIMSDK sharedSDK].conversationManager removeDelegate:self]; [[NIMSDK sharedSDK].broadcastManager removeDelegate:self]; [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [self removeComboManager]; } - (XPRoomPresenter *)createPresenter { @@ -356,6 +360,27 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出 [[NIMSDK sharedSDK].broadcastManager addDelegate:self]; } +- (void)setupComboManager { + // TODO: 测试发送礼物后唤起 test view/ 处理连击倒计时 & 消息发送 + [[GiftComboManager sharedManager] registerActions:^(ComboActionType type) { + switch (type) { + case ComboAction_ShowPanel: + + break; + case ComboAction_RemovePanel: + + break; + + default: + break; + } + }]; +} + +- (void)removeComboManager { + [[GiftComboManager sharedManager] registerActions:nil]; +} + /// 禮物面板緩存-2: 進房後,用當前的 roomUid 加載最新數據,並緩存 - (void)preLoadGifts { [self.presenter getNormalGiftList:self.roomUid];