Merge branch 'closed-groups' into database-3

pull/213/head
nielsandriesse 5 years ago
commit 203c25b382

@ -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

@ -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)

@ -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<Void> in
return threadPromise.then(on: DispatchQueue.main) { thread -> Promise<Void> in // Intentionally the main queue
let message = messageSend.message
let messageSender = SSKEnvironment.shared.messageSender
let (promise, seal) = Promise<Void>.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)
}
}
}

@ -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<String> = []

@ -578,7 +578,6 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
return;
}
OWSFailDebug(@"Could not decrypt UD message: %@.", underlyingError);
failureBlock(underlyingError);
return;
}

@ -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;

Loading…
Cancel
Save