新增 versionType 属性以支持新旧版本兼容,更新 XPRoomPresenter 和 XPMessageRemoteExtModel,优化 micButton 处理逻辑,增强消息发送功能的稳定性和可维护性。

This commit is contained in:
edwinQQQ
2025-08-20 19:06:49 +08:00
parent 0b89480a77
commit 267650759c
3 changed files with 96 additions and 32 deletions

View File

@@ -99,6 +99,7 @@
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
extModel.platformRole = userInfo.platformRole;
extModel.nick = userInfo.nick;
extModel.versionType = 1;
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
request.roomExt = [ext toJSONString];

View File

@@ -70,6 +70,10 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic,assign) BOOL isCustomWord;
@property(nonatomic,copy) NSString * headWearUrl;
@property(nonatomic,assign) NSInteger headWearType;
// 用于新旧版本兼容时的判断
@property (nonatomic, assign) NSInteger versionType;
@end
NS_ASSUME_NONNULL_END

View File

@@ -327,8 +327,66 @@
- (void)handleUpMicAction:(NIMChatroomMember *)member {
// TODO 31
// TODO:
NSError *error = nil;
NSData *data = [member.roomExt dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSDictionary *value = nil;
if (!error) {
NSLog(@"解析成功:%@", dict);
NSString *firstKey = dict.allKeys.firstObject;
if (![NSString isEmpty:firstKey]) {
value = dict[firstKey];
}
}
if (value &&
[value objectForKey:@"versionType"] &&
![member.userId isEqualToString:[AccountInfoStorage instance].getUid]) {
AttachmentModel *attachment = [[AttachmentModel alloc] init];
attachment.first = ClientMessage_Type;
attachment.second = ClientMessage_UpMic_Ask;
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
[data setObject:[AccountInfoStorage instance].getUid
forKey:@"uid"];
[data setObject:member.userId forKey:@"targetUid"];
[data setObject:self.position forKey:@"position"];
[data setObject:@(self.roomType) forKey:@"roomType"];
[data setObject:@([[NSDate date] timeIntervalSince1970])
forKey:@"sendTime"];
attachment.data = data;
NSString *sessionID = self.roomId;
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
// UserInfoModel *userInfo = [self.delegate getUserInfo];
// XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
// extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
// extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
// extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
// extModel.platformRole = userInfo.platformRole;
// NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
// message.remoteExt = member.;
NIMSessionType sessionType = NIMSessionTypeChatroom;
//
NIMSession *session = [NIMSession session:sessionID type:sessionType];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) {
BOOL onMain = [NSThread isMainThread];
if (error) {
NSLog(@"[Combo effect][Send] ❌ 发送失败 | sessionId=%@ | code=%ld | desc=%@ | main=%@ | ts=%.3f",
sessionID, (long)error.code, error.localizedDescription, onMain ? @"YES" : @"NO", [[NSDate date] timeIntervalSince1970]);
} else {
NSLog(@"[Combo effect][Send] ✅ 发送成功 | sessionId=%@ | main=%@ | ts=%.3f",
sessionID, onMain ? @"YES" : @"NO", [[NSDate date] timeIntervalSince1970]);
}
}];
} else {
if ([AccountInfoStorage instance].getUid.integerValue == member.userId.integerValue) {
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
@@ -366,6 +424,7 @@
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
[self.navigationController popViewControllerAnimated:YES];
}
}
}
#pragma mark - Event Response