新增公共房间消息转发通知常量,并在相关管理器和视图控制器中实现消息转发逻辑,优化公共房间消息处理流程,提升代码可读性和功能性。

This commit is contained in:
edwinQQQ
2025-08-12 18:50:43 +08:00
parent 505472b073
commit 2867c7ddb5
6 changed files with 150 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ UIKIT_EXTERN NSString * const kRedPacketHistory;
UIKIT_EXTERN NSString * const kTuWenMessageHistory;///图文消息已读记录
UIKIT_EXTERN NSString * const kRoomQuickMessageCloseCount;
UIKIT_EXTERN NSString * const kLoginMethod;
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
typedef NS_ENUM(NSUInteger, Pi_KeyType) {
KeyType_PasswordEncode,///密码 des 加密的
KeyType_TRTC,///TRTC key

View File

@@ -43,6 +43,7 @@ NSString * const kRoomRoomLittleGameMiniStageNotificationKey = @"kRoomRoomLittle
NSString * const kFreeGiftCountdownNotification = @"kFreeGiftCountdownNotification";///
NSString * const kMessageFromPublicRoomWithAttachmentNotification = @"MessageFromPublicRoomWithAttachmentNotification";///
///
NSString * const KeyWithType(Pi_KeyType type) {

View File

@@ -10,6 +10,8 @@
#import "ClientConfig.h"
#import "AccountInfoStorage.h"
#import "XPMessageRemoteExtModel.h"
#import "AttachmentModel.h"
#import "YUMIConstant.h"
@interface PublicRoomManager () <NIMChatManagerDelegate>
@@ -336,7 +338,33 @@
if (message.session.sessionType == NIMSessionTypeChatroom) {
NSString *sessionId = message.session.sessionId;
if ([sessionId isEqualToString:self.currentPublicRoomId]) {
NSLog(@"PublicRoomManager: 收到公共房间消息: %@", message.rawAttachContent);
NIMMessageChatroomExtension *messageExt = (NIMMessageChatroomExtension *)message.messageExt;
// NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from];
// XPMessageRemoteExtModel *extModel = [XPMessageRemoteExtModel modelWithJSON:dic];
NSString * messageText = message.text;
AttachmentModel *attachment;
if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *) message.messageObject;
attachment = (AttachmentModel *) obj.attachment;
if (attachment.first == CustomMessageType_Car_Notify) {
if (attachment.second == Custom_Message_Sub_Car_OutDate) {
messageText = attachment.data[@"msg"];
}
}
// (attachment.first == 106)
if (attachment && attachment.first == 106) {
//
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageFromPublicRoomWithAttachmentNotification"
object:message];
NSLog(@"PublicRoomManager: 转发106类型消息到房间");
}
}
NSLog(@"PublicRoomManager: 收到公共房间消息: %@\n%@",
message.rawAttachContent,
messageExt.roomExt);
//
// TODO: 广
}

View File

@@ -7,6 +7,10 @@
#import "MvpViewController.h"
#import "XPMessageRemoteExtModel.h"
// 公共房间消息转发通知名称
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
NS_ASSUME_NONNULL_BEGIN
@interface XPRoomViewController : MvpViewController

View File

@@ -98,6 +98,7 @@
UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
UIKIT_EXTERN NSString * kNewUserRechargeKey;
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
NSString * const kHadShowAnchorRoomTipKey = @"kHadShowAnchorRoomTipKey";//
NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//退
@@ -421,6 +422,12 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openRedPacketNotification:) name:@"kOpenRedPacketNotification" object:nil];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePublicRoomMessageForward:)
name:@"MessageFromPublicRoomWithAttachmentNotification"
object:nil];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
@@ -3121,4 +3128,26 @@ XPCandyTreeInsufficientBalanceViewDelegate>
}
return _redPacketView;
}
#pragma mark -
- (void)handlePublicRoomMessageForward:(NSNotification *)notification {
NIMMessage *message = notification.object;
if (![message isKindOfClass:[NIMMessage class]]) {
NSLog(@"XPRoomViewController: 收到无效的公共房间转发消息");
return;
}
//
if (!self.roomInfo || !self.messageContainerView) {
NSLog(@"XPRoomViewController: 房间未就绪,忽略公共房间转发消息");
return;
}
// 使
[self.messageContainerView handleNIMCustomMessage:message];
NSLog(@"XPRoomViewController: 处理公共房间转发的106类型消息");
}
@end