From a65235fd3a6f542a43ff4ed513c36953e05827c4 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sat, 25 Apr 2020 12:27:17 +1000 Subject: [PATCH] Clean & add documentation --- .../xcshareddata/xcschemes/Signal.xcscheme | 3 --- SignalServiceKit/src/Contacts/TSThread.h | 2 +- .../SessionManagementProtocol.swift | 12 +++++++++--- .../src/Loki/Protocol/SessionProtocol.swift | 6 +++++- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- SignalServiceKit/src/Messages/OWSMessageSender.m | 2 +- .../AxolotlStore/OWSPrimaryStorage+SessionStore.m | 2 +- SignalServiceKit/src/Util/NSError+MessageSending.m | 2 +- SignalServiceKit/src/Util/TypingIndicators.swift | 3 +-- .../tests/Messages/OWSUDManagerTest.swift | 2 -- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme index 64a8ba432..915c5088b 100644 --- a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme +++ b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme @@ -126,9 +126,6 @@ - - diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 2afe7c567..e3ef225df 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -64,7 +64,7 @@ typedef NS_ENUM(NSInteger, LKThreadFriendRequestStatus) { @property (nonatomic, readonly) BOOL hasCurrentUserSentFriendRequest; @property (nonatomic, readonly) BOOL hasCurrentUserReceivedFriendRequest; // ======== -@property (nonatomic) BOOL isForceHidden; +@property (nonatomic) BOOL isForceHidden; // FIXME: Having both this and shouldThreadBeVisible is confusing /** * Whether the object is a group thread or not. diff --git a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift index 62d37dcc2..fe3e1b4bb 100644 --- a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift @@ -23,10 +23,10 @@ public final class SessionManagementProtocol : NSObject { @objc(createPreKeys) public static func createPreKeys() { - // We don't generate PreKeyRecords here. + // We don't generate new pre keys here like Signal does. // This is because we need the records to be linked to a contact since we don't have a central server. - // It's done automatically when we generate a pre key bundle to send to a contact (`generatePreKeyBundleForContact:`). - // You can use `getOrCreatePreKeyForContact:` to generate one if needed. + // It's done automatically when we generate a pre key bundle to send to a contact (generatePreKeyBundleForContact:). + // You can use getOrCreatePreKeyForContact: to generate one if needed. let signedPreKeyRecord = storage.generateRandomSignedRecord() signedPreKeyRecord.markAsAcceptedByService() storage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) @@ -36,6 +36,10 @@ public final class SessionManagementProtocol : NSObject { @objc(refreshSignedPreKey) public static func refreshSignedPreKey() { + // We don't generate new pre keys here like Signal does. + // This is because we need the records to be linked to a contact since we don't have a central server. + // It's done automatically when we generate a pre key bundle to send to a contact (generatePreKeyBundleForContact:). + // You can use getOrCreatePreKeyForContact: to generate one if needed. guard storage.currentSignedPrekeyId() == nil else { print("[Loki] Skipping pre key refresh; using existing signed pre key.") return @@ -51,6 +55,8 @@ public final class SessionManagementProtocol : NSObject { @objc(rotateSignedPreKey) public static func rotateSignedPreKey() { + // This is identical to what Signal does, except that it doesn't upload the signed pre key + // to a server. let signedPreKeyRecord = storage.generateRandomSignedRecord() signedPreKeyRecord.markAsAcceptedByService() storage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) diff --git a/SignalServiceKit/src/Loki/Protocol/SessionProtocol.swift b/SignalServiceKit/src/Loki/Protocol/SessionProtocol.swift index 315a4c444..8b391e99c 100644 --- a/SignalServiceKit/src/Loki/Protocol/SessionProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/SessionProtocol.swift @@ -97,6 +97,8 @@ public final class SessionProtocol : NSObject { } // MARK: Typing Indicators + /// Invoked only if typing indicators are enabled. Provides an opportunity to not + /// send them if certain conditions are met. @objc(shouldSendTypingIndicatorForThread:) public static func shouldSendTypingIndicator(for thread: TSThread) -> Bool { return !thread.isGroupThread() && !isMessageNoteToSelf(thread) @@ -109,7 +111,9 @@ public final class SessionProtocol : NSObject { return !isMessageNoteToSelf(thread) && !thread.isGroupThread() } - // TODO: Not sure how these two relate + // TODO: Not sure how these two relate. EDIT: I think the one below is used to block delivery receipts. That means that + // right now we do send delivery receipts in note to self, but not read receipts. Other than that their behavior should + // be identical. Should we just not send any kind of receipt in note to self? // Used from OWSOutgoingReceiptManager @objc(shouldSendReceiptForThread:) diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 5eb55011b..479d14cc6 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1584,7 +1584,7 @@ NS_ASSUME_NONNULL_BEGIN [incomingMessage saveWithTransaction:transaction]; - // Loki: Remove any old incoming messages + // Loki: Remove any old incoming friend requests if (incomingMessage.isFriendRequest) { [thread removeOldIncomingFriendRequestMessagesIfNeededWithTransaction:transaction]; } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 14f17bf63..0392234cc 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1254,7 +1254,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }) retainUntilComplete]; } }) - .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { // The snode is unreachable + .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { handleError(error); }) retainUntilComplete]; } diff --git a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SessionStore.m b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SessionStore.m index 568ff7742..3475ff6f9 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SessionStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SessionStore.m @@ -88,7 +88,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssertDebug(contactIdentifier.length > 0); OWSAssertDebug(deviceId >= 0); OWSAssertDebug([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); - // TODO: Needs a comment from Ryan + // FIXME: This needs a comment from Ryan explaining why it's necessary (it has to do with push notifications) if (!CurrentAppContext().isMainApp) { return; } YapDatabaseReadWriteTransaction *transaction = protocolContext; diff --git a/SignalServiceKit/src/Util/NSError+MessageSending.m b/SignalServiceKit/src/Util/NSError+MessageSending.m index 0c01ebe15..04f84e03a 100644 --- a/SignalServiceKit/src/Util/NSError+MessageSending.m +++ b/SignalServiceKit/src/Util/NSError+MessageSending.m @@ -21,7 +21,7 @@ static void *kNSError_MessageSender_IsFatal = &kNSError_MessageSender_IsFatal; { NSNumber *value = objc_getAssociatedObject(self, kNSError_MessageSender_IsRetryable); // This value should always be set for all errors by the time OWSSendMessageOperation - // queries it's value. If not, default to retrying in production. + // queries it's value. If not, default to retrying in production. return value ? [value boolValue] : YES; } diff --git a/SignalServiceKit/src/Util/TypingIndicators.swift b/SignalServiceKit/src/Util/TypingIndicators.swift index 58cff90ac..dd5723f19 100644 --- a/SignalServiceKit/src/Util/TypingIndicators.swift +++ b/SignalServiceKit/src/Util/TypingIndicators.swift @@ -322,8 +322,7 @@ public class TypingIndicatorsImpl: NSObject, TypingIndicators { guard delegate.areTypingIndicatorsEnabled() else { return } - - // Loki: Don't send typing indicators in group or note to self threads + if !SessionProtocol.shouldSendTypingIndicator(for: thread) { return } let message = TypingIndicatorMessage(thread: thread, action: action) diff --git a/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift b/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift index 6a4d844fe..87b33c579 100644 --- a/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift +++ b/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift @@ -39,7 +39,6 @@ class OWSUDManagerTest: SSKBaseTestSwift { // MARK: registration let aliceRecipientId = "+13213214321" - /* override func setUp() { super.setUp() @@ -62,7 +61,6 @@ class OWSUDManagerTest: SSKBaseTestSwift { udManager.setSenderCertificate(try! senderCertificate.serialized()) } - */ override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class.