From a61127622cd952def6ae3e79d92cca3db76d593b Mon Sep 17 00:00:00 2001 From: James Magahern Date: Wed, 1 Apr 2026 17:22:28 -0700 Subject: [PATCH] SendMessage: some backwards compatibility --- .../Operations/MBIMSendMessageOperation.m | 125 ++++++++++++++++-- 1 file changed, 116 insertions(+), 9 deletions(-) diff --git a/server/kordophone/Bridge/Operations/MBIMSendMessageOperation.m b/server/kordophone/Bridge/Operations/MBIMSendMessageOperation.m index 10db1d4..5252dd7 100644 --- a/server/kordophone/Bridge/Operations/MBIMSendMessageOperation.m +++ b/server/kordophone/Bridge/Operations/MBIMSendMessageOperation.m @@ -21,6 +21,118 @@ return @"sendMessage"; } +- (nullable IMChat *)_existingSingleChatForHandle:(IMHandle *)handle registry:(IMChatRegistry *)registry +{ + if ([registry respondsToSelector:@selector(existingChatWithHandle:allowAlternativeService:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatWithHandle:allowAlternativeService:"); + return [registry existingChatWithHandle:handle allowAlternativeService:NO]; + } + + if ([registry respondsToSelector:@selector(existingChatWithHandle:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatWithHandle:"); + return [registry existingChatWithHandle:handle]; + } + + if ([registry respondsToSelector:@selector(existingChatForIMHandle:allowRetargeting:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatForIMHandle:allowRetargeting:"); + return [registry existingChatForIMHandle:handle allowRetargeting:NO]; + } + + if ([registry respondsToSelector:@selector(existingChatForIMHandle:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatForIMHandle:"); + return [registry existingChatForIMHandle:handle]; + } + + MBIMLogError(@"IMChatRegistry does not support any known single-handle existing chat lookup selector."); + return nil; +} + +- (nullable IMChat *)_createSingleChatForHandle:(IMHandle *)handle registry:(IMChatRegistry *)registry +{ + if ([registry respondsToSelector:@selector(chatWithHandle:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatWithHandle:"); + return [registry chatWithHandle:handle]; + } + + if ([registry respondsToSelector:@selector(chatForIMHandle:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatForIMHandle:"); + return [registry chatForIMHandle:handle]; + } + + MBIMLogError(@"IMChatRegistry does not support any known single-handle chat creation selector."); + return nil; +} + +- (nullable IMChat *)_existingGroupChatForHandles:(NSArray *)handles registry:(IMChatRegistry *)registry +{ + if ([registry respondsToSelector:@selector(existingChatWithHandles:allowAlternativeService:groupID:displayName:joinedChatsOnly:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatWithHandles:allowAlternativeService:groupID:displayName:joinedChatsOnly:"); + return [registry existingChatWithHandles:handles + allowAlternativeService:NO + groupID:nil + displayName:nil + joinedChatsOnly:YES]; + } + + if ([registry respondsToSelector:@selector(existingChatWithHandles:allowAlternativeService:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatWithHandles:allowAlternativeService:"); + return [registry existingChatWithHandles:handles allowAlternativeService:NO]; + } + + if ([registry respondsToSelector:@selector(existingChatWithHandles:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatWithHandles:"); + return [registry existingChatWithHandles:handles]; + } + + if ([registry respondsToSelector:@selector(existingChatForIMHandles:allowRetargeting:groupID:displayName:joinedChatsOnly:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatForIMHandles:allowRetargeting:groupID:displayName:joinedChatsOnly:"); + return [registry existingChatForIMHandles:handles + allowRetargeting:NO + groupID:nil + displayName:nil + joinedChatsOnly:YES]; + } + + if ([registry respondsToSelector:@selector(existingChatForIMHandles:allowRetargeting:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatForIMHandles:allowRetargeting:"); + return [registry existingChatForIMHandles:handles allowRetargeting:NO]; + } + + if ([registry respondsToSelector:@selector(existingChatForIMHandles:)]) { + MBIMLogInfo(@"Using IMChatRegistry existingChatForIMHandles:"); + return [registry existingChatForIMHandles:handles]; + } + + MBIMLogError(@"IMChatRegistry does not support any known multi-handle existing chat lookup selector."); + return nil; +} + +- (nullable IMChat *)_createGroupChatForHandles:(NSArray *)handles registry:(IMChatRegistry *)registry +{ + if ([registry respondsToSelector:@selector(chatWithHandles:displayName:joinedChatsOnly:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatWithHandles:displayName:joinedChatsOnly:"); + return [registry chatWithHandles:handles displayName:nil joinedChatsOnly:YES]; + } + + if ([registry respondsToSelector:@selector(chatWithHandles:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatWithHandles:"); + return [registry chatWithHandles:handles]; + } + + if ([registry respondsToSelector:@selector(chatForIMHandles:displayName:joinedChatsOnly:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatForIMHandles:displayName:joinedChatsOnly:"); + return [registry chatForIMHandles:handles displayName:nil joinedChatsOnly:YES]; + } + + if ([registry respondsToSelector:@selector(chatForIMHandles:)]) { + MBIMLogInfo(@"Using IMChatRegistry chatForIMHandles:"); + return [registry chatForIMHandles:handles]; + } + + MBIMLogError(@"IMChatRegistry does not support any known multi-handle chat creation selector."); + return nil; +} + - (nullable IMChat *)_chatForHandleIDs:(NSArray *)handleIDs registry:(IMChatRegistry *)registry { MBIMLogInfo(@"Resolving send target for handles: %@", handleIDs); @@ -44,9 +156,9 @@ if ([handles count] == 1) { IMHandle *handle = [handles firstObject]; - IMChat *chat = [registry existingChatWithHandle:handle allowAlternativeService:NO]; + IMChat *chat = [self _existingSingleChatForHandle:handle registry:registry]; if (!chat) { - chat = [registry chatWithHandle:handle]; + chat = [self _createSingleChatForHandle:handle registry:registry]; } if (chat) { @@ -58,14 +170,9 @@ return chat; } - IMChat *chat = [registry existingChatWithHandles:handles - allowAlternativeService:NO - groupID:nil - displayName:nil - joinedChatsOnly:YES]; - + IMChat *chat = [self _existingGroupChatForHandles:handles registry:registry]; if (!chat) { - chat = [registry chatWithHandles:handles displayName:nil joinedChatsOnly:YES]; + chat = [self _createGroupChatForHandles:handles registry:registry]; } if (chat) {