From 2e8663a1b00ce85cc7821a8292c5a74b11664f2c Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 18 Jun 2020 09:56:34 +1000 Subject: [PATCH] Debug --- Pods | 2 +- .../Loki/Components/ConversationCell.swift | 1 + SignalMessaging/profiles/OWSProfileManager.h | 1 + SignalMessaging/profiles/OWSProfileManager.m | 20 +++++++++++++------ .../src/Loki/API/LokiAPI+SwarmAPI.swift | 6 +++--- .../src/Loki/API/LokiPoller.swift | 1 + .../Sync Messages/SyncMessagesProtocol.swift | 4 ++-- .../src/Protocols/ProfileManagerProtocol.h | 1 + 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Pods b/Pods index 1b8608351..62dbf6a40 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 1b860835167058d16fb18db2416f8482d08b982c +Subproject commit 62dbf6a4090b77d62b3e073eed44b4b36b866797 diff --git a/Signal/src/Loki/Components/ConversationCell.swift b/Signal/src/Loki/Components/ConversationCell.swift index ff00980d2..e5b1f2641 100644 --- a/Signal/src/Loki/Components/ConversationCell.swift +++ b/Signal/src/Loki/Components/ConversationCell.swift @@ -155,6 +155,7 @@ final class ConversationCell : UITableViewCell { let randomUsers = users.sorted().prefix(2) // Sort to provide a level of stability profilePictureView.hexEncodedPublicKey = randomUsers.count >= 1 ? randomUsers[0] : "" profilePictureView.additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : "" + profilePictureView.isRSSFeed = false } } else { // A one-on-one chat profilePictureView.hexEncodedPublicKey = threadViewModel.contactIdentifier! diff --git a/SignalMessaging/profiles/OWSProfileManager.h b/SignalMessaging/profiles/OWSProfileManager.h index 7f3cf32e0..073c1d7a1 100644 --- a/SignalMessaging/profiles/OWSProfileManager.h +++ b/SignalMessaging/profiles/OWSProfileManager.h @@ -75,6 +75,7 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; - (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId; - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID; +- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction; - (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId; - (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index d9308c977..b232160f7 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -176,13 +176,12 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); #pragma mark - Local Profile -- (OWSUserProfile *)localUserProfile +- (OWSUserProfile *)getLocalUserProfileWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { @synchronized(self) { if (!_localUserProfile) { - _localUserProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:kLocalProfileUniqueId - dbConnection:self.dbConnection]; + _localUserProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:kLocalProfileUniqueId transaction:transaction]; } } @@ -1023,13 +1022,22 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); } - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID +{ + __block NSString *result; + [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + result = [self profileNameForRecipientWithID:recipientID transaction:transaction]; + } error:nil]; + return result; +} + +- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssertDebug(recipientID.length > 0); // For "local reads", use the local user profile. - OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientID] - ? self.localUserProfile - : [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientID dbConnection:self.dbConnection]); + OWSUserProfile *userProfile = [self.tsAccountManager.localNumber isEqualToString:recipientID] + ? [self getLocalUserProfileWithTransaction:transaction] + : [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientID transaction:transaction]; return userProfile.profileName; } diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift index 2d480bf59..7e142bc2d 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift @@ -86,13 +86,13 @@ public extension LokiAPI { let parameters: [String:Any] = [ "pubKey" : hexEncodedPublicKey ] return getRandomSnode().then2 { invoke(.getSwarm, on: $0, associatedWith: hexEncodedPublicKey, parameters: parameters) - }.map2 { - parseTargets(from: $0) - }.get2 { swarm in + }.map2 { rawSnodes in + let swarm = parseTargets(from: rawSnodes) swarmCache[hexEncodedPublicKey] = swarm try! Storage.writeSync { transaction in storage.setSwarm(swarm, for: hexEncodedPublicKey, in: transaction) } + return swarm } } } diff --git a/SignalServiceKit/src/Loki/API/LokiPoller.swift b/SignalServiceKit/src/Loki/API/LokiPoller.swift index 84be750d9..58fe10165 100644 --- a/SignalServiceKit/src/Loki/API/LokiPoller.swift +++ b/SignalServiceKit/src/Loki/API/LokiPoller.swift @@ -94,6 +94,7 @@ public final class LokiPoller : NSObject { } private func poll(_ target: LokiAPITarget, seal longTermSeal: Resolver) -> Promise { + guard !hasStopped else { return Promise { $0.fulfill(()) } } return LokiAPI.getRawMessages(from: target, usingLongPolling: false).then2 { [weak self] rawResponse -> Promise in guard let strongSelf = self, !strongSelf.hasStopped else { return Promise { $0.fulfill(()) } } let messages = LokiAPI.parseRawMessagesResponse(rawResponse, from: target) diff --git a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift index 71ce766e5..0e15360b9 100644 --- a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift @@ -237,7 +237,7 @@ public final class SyncMessagesProtocol : NSObject { } @objc(handleOpenGroupSyncMessageIfNeeded:wrappedIn:using:) - public static func handleOpenGroupSyncMessageIfNeeded(_ syncMessage: SSKProtoSyncMessage, wrappedIn envelope: SSKProtoEnvelope, using transaction: YapDatabaseReadTransaction) { + public static func handleOpenGroupSyncMessageIfNeeded(_ syncMessage: SSKProtoSyncMessage, wrappedIn envelope: SSKProtoEnvelope, using transaction: YapDatabaseReadWriteTransaction) { let hexEncodedPublicKey = envelope.source! // Set during UD decryption let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: hexEncodedPublicKey, in: transaction) let wasSentByLinkedDevice = linkedDevices.contains(hexEncodedPublicKey) @@ -249,7 +249,7 @@ public final class SyncMessagesProtocol : NSObject { let openGroupManager = LokiPublicChatManager.shared guard openGroupManager.getChat(server: openGroup.url, channel: openGroup.channel) == nil else { return } let userPublicKey = UserDefaults.standard[.masterHexEncodedPublicKey] ?? getUserHexEncodedPublicKey() - let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: userPublicKey) + let displayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: userPublicKey, transaction: transaction) LokiPublicChatAPI.setDisplayName(to: displayName, on: openGroup.url) openGroupManager.addChat(server: openGroup.url, channel: openGroup.channel) } diff --git a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h index 3bc40c054..1a5c6e3e7 100644 --- a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h +++ b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSString *)localProfileName; - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID; +- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID transaction:(YapDatabaseReadWriteTransaction *)transaction; - (nullable NSString *)profilePictureURL; - (nullable NSData *)profileKeyDataForRecipientId:(NSString *)recipientId;