diff --git a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift index 4dbf6411b..ee48d838a 100644 --- a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift +++ b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift @@ -47,7 +47,8 @@ final class NewClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegat super.viewDidLoad() setUpGradientBackground() setUpNavBarStyle() - setNavBarTitle(NSLocalizedString("New Closed Group", comment: "")) + let customTitleFontSize = isSmallScreen ? Values.largeFontSize : Values.veryLargeFontSize + setNavBarTitle(NSLocalizedString("New Closed Group", comment: ""), customFontSize: customTitleFontSize) // Set up navigation bar buttons let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close)) closeButton.tintColor = Colors.text diff --git a/SignalServiceKit/src/Loki/Protocol/Closed Groups/ClosedGroupsProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Closed Groups/ClosedGroupsProtocol.swift index ec5a18a7f..13c9275aa 100644 --- a/SignalServiceKit/src/Loki/Protocol/Closed Groups/ClosedGroupsProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Closed Groups/ClosedGroupsProtocol.swift @@ -38,6 +38,7 @@ public final class ClosedGroupsProtocol : NSObject { guard hexEncodedPublicKey != getUserHexEncodedPublicKey() else { return } let hasSession = storage.containsSession(hexEncodedPublicKey, deviceId: Int32(OWSDevicePrimaryDeviceId), protocolContext: transaction) guard !hasSession else { return } + print("[Loki] Establishing session with: \(hexEncodedPublicKey).") let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) thread.save(with: transaction) let sessionRequestMessage = SessionRequestMessage(thread: thread) diff --git a/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift index 4a944c6b8..807a1446c 100644 --- a/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift @@ -9,6 +9,9 @@ import PromiseKit // • Document the expected cases for everything. // • Express those cases in tests. +// FIXME: We're manually attaching the sender certificate and UD recipient access to message sends in a lot of places. It'd be great +// to clean this up and just do it in one spot. + @objc(LKMultiDeviceProtocol) public final class MultiDeviceProtocol : NSObject { @@ -46,9 +49,15 @@ public final class MultiDeviceProtocol : NSObject { storage.dbReadConnection.read { transaction in recipient = SignalRecipient.getOrBuildUnsavedRecipient(forRecipientId: destination.hexEncodedPublicKey, transaction: transaction) } - // TODO: Why is it okay that the thread, sender certificate, etc. don't get changed? + let udManager = SSKEnvironment.shared.udManager + let senderCertificate = udManager.getSenderCertificate() + var recipientUDAccess: OWSUDAccess? + if let senderCertificate = senderCertificate { + recipientUDAccess = udManager.udAccess(forRecipientId: destination.hexEncodedPublicKey, requireSyncAccess: true) // Starts a new write transaction internally + } + // TODO: Why is it okay that the thread doesn't get changed? return OWSMessageSend(message: messageSend.message, thread: messageSend.thread, recipient: recipient, - senderCertificate: messageSend.senderCertificate, udAccess: messageSend.udAccess, localNumber: messageSend.localNumber, success: { + senderCertificate: senderCertificate, udAccess: recipientUDAccess, localNumber: messageSend.localNumber, success: { seal.fulfill(()) }, failure: { error in seal.reject(error) @@ -67,7 +76,7 @@ public final class MultiDeviceProtocol : NSObject { threadPromiseSeal.fulfill(thread) } } - return threadPromise.then(on: OWSDispatch.sendingQueue()) { thread -> Promise in + return threadPromise.then(on: DispatchQueue.main) { thread -> Promise in // Intentionally the main queue let message = messageSend.message let messageSender = SSKEnvironment.shared.messageSender let (promise, seal) = Promise.pending() @@ -76,7 +85,9 @@ public final class MultiDeviceProtocol : NSObject { && message.shouldBeSaved() // shouldBeSaved indicates it isn't a transient message if !shouldSendAutoGeneratedFR { let messageSendCopy = copy(messageSend, for: destination, with: seal) - messageSender.sendMessage(messageSendCopy) + OWSDispatch.sendingQueue().async { + messageSender.sendMessage(messageSendCopy) + } } else { Storage.write { transaction in getAutoGeneratedMultiDeviceFRMessageSend(for: destination.hexEncodedPublicKey, in: transaction, seal: seal) @@ -131,10 +142,20 @@ public final class MultiDeviceProtocol : NSObject { messageSend.failure(errors.first!) } } - }.catch(on: OWSDispatch.sendingQueue()) { error in + }.catch(on: DispatchQueue.main) { error in // Intentionally the main queue // Proceed even if updating the recipient's device links failed, so that message sending // is independent of whether the file server is online - messageSender.sendMessage(messageSend) + let udManager = SSKEnvironment.shared.udManager + let senderCertificate = udManager.getSenderCertificate() + var recipientUDAccess: OWSUDAccess? + if let senderCertificate = senderCertificate { + recipientUDAccess = udManager.udAccess(forRecipientId: recipientID, requireSyncAccess: true) // Starts a new write transaction internally + } + messageSend.senderCertificate = senderCertificate + messageSend.udAccess = recipientUDAccess + OWSDispatch.sendingQueue().async { + messageSender.sendMessage(messageSend) + } } } diff --git a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift index 2c9afcc96..167386f88 100644 --- a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift @@ -141,7 +141,13 @@ public final class SessionManagementProtocol : NSObject { @objc(repairSessionIfNeededForMessage:to:) public static func repairSessionIfNeeded(for message: TSOutgoingMessage, to hexEncodedPublicKey: String) { guard (message.thread as? TSGroupThread)?.groupModel.groupType == .closedGroup else { return } + var hasSentSessionRequest = false + storage.dbReadConnection.read { transaction in + hasSentSessionRequest = storage.getSessionRequestTimestamp(for: hexEncodedPublicKey, in: transaction) != nil + } + guard !hasSentSessionRequest else { return } Storage.write { transaction in + print("[Loki] Repairing session with: \(hexEncodedPublicKey).") let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) let sessionRequestMessage = SessionRequestMessage(thread: thread) storage.setSessionRequestTimestamp(for: hexEncodedPublicKey, to: Date(), in: transaction) @@ -194,6 +200,7 @@ public final class SessionManagementProtocol : NSObject { if let sentSessionRequestTimestamp = storage.getSessionRequestTimestamp(for: hexEncodedPublicKey, in: transaction), envelope.timestamp < NSDate.ows_millisecondsSince1970(for: sentSessionRequestTimestamp) { // We sent a session request after this one was sent + print("[Loki] Ignoring session request from: \(hexEncodedPublicKey).") return } var closedGroupMembers: Set = [] diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index 0ba7046a7..98abe0f45 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -578,7 +578,6 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes return; } - OWSFailDebug(@"Could not decrypt UD message: %@.", underlyingError); failureBlock(underlyingError); return; } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 95547d963..a47de736e 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -928,6 +928,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; { OWSAssertDebug(messageSend); OWSAssertDebug(messageSend.thread || [messageSend.message isKindOfClass:[OWSOutgoingSyncMessage class]]); + OWSAssertDebug(messageSend.isUDSend); TSOutgoingMessage *message = messageSend.message; SignalRecipient *recipient = messageSend.recipient;