diff --git a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift index 76dec4628..e2501df9c 100644 --- a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift @@ -139,6 +139,19 @@ public final class SessionManagementProtocol : NSObject { return promise } + @objc(repairSessionIfNeededForMessage:to:) + public static func repairSessionIfNeeded(for message: TSOutgoingMessage, to hexEncodedPublicKey: String) { + guard (message.thread as? TSGroupThread)?.groupModel.groupType == .closedGroup else { return } + DispatchQueue.main.async { + storage.dbReadWriteConnection.readWrite { transaction in + let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) + let sessionRequestMessage = SessionRequestMessage(thread: thread) + let messageSenderJobQueue = SSKEnvironment.shared.messageSenderJobQueue + messageSenderJobQueue.add(message: sessionRequestMessage, transaction: transaction) + } + } + } + // MARK: - Receiving @objc(handleDecryptionError:forHexEncodedPublicKey:using:) public static func handleDecryptionError(_ rawValue: Int32, for hexEncodedPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) { diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 1a9838fde..389bb2bcc 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1705,6 +1705,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; */ if (!bundle) { + [LKSessionManagementProtocol repairSessionIfNeededForMessage:messageSend.message to:recipientID]; NSString *missingPrekeyBundleException = @"missingPrekeyBundleException"; OWSRaiseException(missingPrekeyBundleException, @"Missing pre key bundle for: %@.", recipientID); } else {