From ac59e345970205e71bdc0238dddf555bd03fadea Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 24 Feb 2020 16:24:24 -0300 Subject: [PATCH] Leave primary to upload profile key commitment. --- SignalMessaging/profiles/OWSProfileManager.m | 11 +++++++++++ SignalMessaging/profiles/ProfileFetcherJob.swift | 9 +++++++++ .../src/Protocols/ProfileManagerProtocol.h | 3 +++ .../src/TestUtils/OWSFakeProfileManager.m | 6 ++++++ SignalServiceKit/src/groups/GroupManager.swift | 6 ++++++ 5 files changed, 35 insertions(+) diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 887609adb9..9bfa4fd666 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -430,6 +430,17 @@ const NSString *kNSNotificationKey_WasLocallyInitiated = @"kNSNotificationKey_Wa [ProfileFetcherJob fetchAndUpdateProfileWithAddress:address ignoreThrottling:YES]; } +- (AnyPromise *)fetchLocalUsersProfilePromise +{ + SignalServiceAddress *_Nullable localAddress = self.tsAccountManager.localAddress; + if (!localAddress.isValid) { + return [AnyPromise promiseWithValue:OWSErrorMakeAssertionError(@"Missing local address.")]; + } + return [ProfileFetcherJob fetchAndUpdateProfilePromiseObjcWithAddress:localAddress + mainAppOnly:NO + ignoreThrottling:YES]; +} + - (void)fetchAndUpdateProfileForUsername:(NSString *)username success:(void (^)(SignalServiceAddress *))success notFound:(void (^)(void))notFound diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift index c6f61d5d6c..cdd1cc3134 100644 --- a/SignalMessaging/profiles/ProfileFetcherJob.swift +++ b/SignalMessaging/profiles/ProfileFetcherJob.swift @@ -106,6 +106,15 @@ public class ProfileFetcherJob: NSObject { private var backgroundTask: OWSBackgroundTask? + @objc + public class func fetchAndUpdateProfilePromiseObjc(address: SignalServiceAddress, + mainAppOnly: Bool, + ignoreThrottling: Bool) -> AnyPromise { + return AnyPromise(fetchAndUpdateProfilePromise(address: address, + mainAppOnly: mainAppOnly, + ignoreThrottling: ignoreThrottling)) + } + public class func fetchAndUpdateProfilePromise(address: SignalServiceAddress, mainAppOnly: Bool = true, ignoreThrottling: Bool = false, diff --git a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h index f57e41330d..6894a8ade2 100644 --- a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h +++ b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h @@ -2,6 +2,7 @@ // Copyright (c) 2020 Open Whisper Systems. All rights reserved. // +@class AnyPromise; @class OWSAES256Key; @class SDSAnyReadTransaction; @class SDSAnyWriteTransaction; @@ -72,6 +73,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)fetchAndUpdateLocalUsersProfile; +- (AnyPromise *)fetchLocalUsersProfilePromise; + - (void)updateProfileForAddress:(SignalServiceAddress *)address; - (BOOL)recipientAddressIsUuidCapable:(SignalServiceAddress *)address transaction:(SDSAnyReadTransaction *)transaction; diff --git a/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m b/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m index abcc143cf4..fc20545b56 100644 --- a/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m +++ b/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m @@ -190,6 +190,12 @@ NS_ASSUME_NONNULL_BEGIN // Do nothing. } +- (AnyPromise *)fetchLocalUsersProfilePromise +{ + // Do nothing. + return [AnyPromise promiseWithValue:nil]; +} + - (void)updateProfileForAddress:(nonnull SignalServiceAddress *)address { // Do nothing. diff --git a/SignalServiceKit/src/groups/GroupManager.swift b/SignalServiceKit/src/groups/GroupManager.swift index 099ddf55cd..659a2a968b 100644 --- a/SignalServiceKit/src/groups/GroupManager.swift +++ b/SignalServiceKit/src/groups/GroupManager.swift @@ -1491,6 +1491,12 @@ public class GroupManager: NSObject { guard !hasLocalCredential else { return Promise.value(()) } + guard tsAccountManager.isRegisteredPrimaryDevice else { + // On secondary devices, just re-fetch the local + // profile. + return self.profileManager.fetchLocalUsersProfilePromise().asVoid() + } + // We (and other clients) need a profile key credential for // all group members to use groups v2. Other clients can't // request our profile key credential from the service until