新增 versionType 属性以支持新旧版本兼容,更新 XPRoomPresenter 和 XPMessageRemoteExtModel,优化 micButton 处理逻辑,增强消息发送功能的稳定性和可维护性。
This commit is contained in:
@@ -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
|
||||
|
@@ -327,44 +327,103 @@
|
||||
|
||||
- (void)handleUpMicAction:(NIMChatroomMember *)member {
|
||||
|
||||
// TODO : 发送类似 31 的消息
|
||||
// TODO: 处理接收逻辑
|
||||
|
||||
if ([AccountInfoStorage instance].getUid.integerValue == member.userId.integerValue) {
|
||||
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
if (code == 200) {
|
||||
UserInfoModel * userInfo = [UserInfoModel modelWithJSON:data.data];
|
||||
NIMChatroomQueueUpdateRequest *request = [[NIMChatroomQueueUpdateRequest alloc]init];
|
||||
request.key = self.position;
|
||||
request.value = [[self userInfoToQueueExt:userInfo] toJSONString];
|
||||
request.roomId = self.roomId;
|
||||
request.transient = YES;
|
||||
[[NIMSDK sharedSDK].chatroomManager updateChatroomQueueObject:request completion:^(NSError * _Nullable error) {
|
||||
if (error == nil) {
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
} else {
|
||||
[self showErrorToast:error.description];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
} uid:member.userId];
|
||||
} else {
|
||||
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
||||
[dic setValue:@(self.position.integerValue) forKey:@"micPosition"];
|
||||
[dic setValue:@(member.userId.integerValue) forKey:@"uid"];
|
||||
AttachmentModel *attachement = [[AttachmentModel alloc]init];
|
||||
attachement.first = CustomMessageType_Queue;
|
||||
attachement.second = Custom_Message_Sub_Queue_Invite;
|
||||
attachement.data = dic;
|
||||
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 = attachement;
|
||||
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:self.roomId type:NIMSessionTypeChatroom];
|
||||
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
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) {
|
||||
UserInfoModel * userInfo = [UserInfoModel modelWithJSON:data.data];
|
||||
NIMChatroomQueueUpdateRequest *request = [[NIMChatroomQueueUpdateRequest alloc]init];
|
||||
request.key = self.position;
|
||||
request.value = [[self userInfoToQueueExt:userInfo] toJSONString];
|
||||
request.roomId = self.roomId;
|
||||
request.transient = YES;
|
||||
[[NIMSDK sharedSDK].chatroomManager updateChatroomQueueObject:request completion:^(NSError * _Nullable error) {
|
||||
if (error == nil) {
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
} else {
|
||||
[self showErrorToast:error.description];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
} uid:member.userId];
|
||||
} else {
|
||||
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
||||
[dic setValue:@(self.position.integerValue) forKey:@"micPosition"];
|
||||
[dic setValue:@(member.userId.integerValue) forKey:@"uid"];
|
||||
AttachmentModel *attachement = [[AttachmentModel alloc]init];
|
||||
attachement.first = CustomMessageType_Queue;
|
||||
attachement.second = Custom_Message_Sub_Queue_Invite;
|
||||
attachement.data = dic;
|
||||
|
||||
NIMMessage *message = [[NIMMessage alloc]init];
|
||||
NIMCustomObject *object = [[NIMCustomObject alloc] init];
|
||||
object.attachment = attachement;
|
||||
message.messageObject = object;
|
||||
//构造会话
|
||||
NIMSession *session = [NIMSession session:self.roomId type:NIMSessionTypeChatroom];
|
||||
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user