Skip to content

Commit e98ba7e

Browse files
authoredMar 20, 2025··
Remove knowledge of AppConfiguration from WPAccount Objective-C (#24231)
* Remove knowledge of `AppConfiguration` from WPAccount Objective-C * Account for token coming from `WPAccount` possibly being `nil`
1 parent 9b65f8f commit e98ba7e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed
 

‎WordPress/Classes/Models/WPAccount+Lookup.swift

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ public extension WPAccount {
1515
return self.uuid == uuid
1616
}
1717

18+
// This is here in an extension that belongs to the apps target so we can decouple WPAccount from AppConfiguration.
19+
// Decoupling allows moving the type to WordPressData, see https://github.com/wordpress-mobile/WordPress-iOS/issues/24165.
20+
@objc
21+
static func tokenForUsername(_ username: String) -> String? {
22+
token(forUsername: username, isJetpack: AppConfiguration.isJetpack)
23+
}
24+
1825
/// Does this `WPAccount` object have any associated blogs?
1926
///
2027
@objc

‎WordPress/Classes/Models/WPAccount.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
- (void)removeBlogsObject:(Blog *)value;
5050
- (void)addBlogs:(NSSet *)values;
5151
- (void)removeBlogs:(NSSet *)values;
52-
+ (NSString *)tokenForUsername:(NSString *)username;
52+
+ (NSString *)tokenForUsername:(NSString *)username isJetpack:(BOOL)isJetpack;
5353
- (BOOL)hasAtomicSite;
5454

5555
@end

‎WordPress/Classes/Models/WPAccount.m

+7-6
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ - (BOOL)hasAtomicSite {
128128

129129
#pragma mark - Static methods
130130

131-
+ (NSString *)tokenForUsername:(NSString *)username
131+
+ (NSString *)tokenForUsername:(NSString *)username isJetpack:(BOOL)isJetpack
132132
{
133+
if (isJetpack) {
134+
[WPAccount migrateAuthKeyForUsername:username];
135+
}
136+
133137
NSError *error = nil;
134-
[WPAccount migrateAuthKeyForUsername:username];
135138
NSString *authToken = [SFHFKeychainUtils getPasswordForUsername:username
136139
andServiceName:[WPAccount authKeychainServiceName]
137140
accessGroup:nil
@@ -147,10 +150,8 @@ + (void)migrateAuthKeyForUsername:(NSString *)username
147150
{
148151
static dispatch_once_t onceToken;
149152
dispatch_once(&onceToken, ^{
150-
if ([AppConfiguration isJetpack]) {
151-
SharedDataIssueSolver *sharedDataIssueSolver = [SharedDataIssueSolver instance];
152-
[sharedDataIssueSolver migrateAuthKeyFor:username];
153-
}
153+
SharedDataIssueSolver *sharedDataIssueSolver = [SharedDataIssueSolver instance];
154+
[sharedDataIssueSolver migrateAuthKeyFor:username];
154155
});
155156
}
156157

0 commit comments

Comments
 (0)
Please sign in to comment.