Skip to content

Commit 31b232f

Browse files
committed
Remove knowledge of AppConfiguration from WPAccount Objective-C
1 parent 6d89d79 commit 31b232f

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

WordPress/Classes/Models/WPAccount+Lookup.swift

Lines changed: 7 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
- (void)removeBlogsObject:(Blog *)value;
4848
- (void)addBlogs:(NSSet *)values;
4949
- (void)removeBlogs:(NSSet *)values;
50-
+ (NSString *)tokenForUsername:(NSString *)username;
50+
+ (NSString *)tokenForUsername:(NSString *)username isJetpack:(BOOL)isJetpack;
5151
- (BOOL)hasAtomicSite;
5252

5353
@end

WordPress/Classes/Models/WPAccount.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ - (BOOL)hasAtomicSite {
129129

130130
#pragma mark - Static methods
131131

132-
+ (NSString *)tokenForUsername:(NSString *)username
132+
+ (NSString *)tokenForUsername:(NSString *)username isJetpack:(BOOL)isJetpack
133133
{
134+
if (isJetpack) {
135+
[WPAccount migrateAuthKeyForUsername:username];
136+
}
137+
134138
NSError *error = nil;
135-
[WPAccount migrateAuthKeyForUsername:username];
136139
NSString *authToken = [SFHFKeychainUtils getPasswordForUsername:username
137140
andServiceName:[WPAccount authKeychainServiceName]
138141
accessGroup:nil
@@ -148,10 +151,8 @@ + (void)migrateAuthKeyForUsername:(NSString *)username
148151
{
149152
static dispatch_once_t onceToken;
150153
dispatch_once(&onceToken, ^{
151-
if ([AppConfiguration isJetpack]) {
152-
SharedDataIssueSolver *sharedDataIssueSolver = [SharedDataIssueSolver instance];
153-
[sharedDataIssueSolver migrateAuthKeyFor:username];
154-
}
154+
SharedDataIssueSolver *sharedDataIssueSolver = [SharedDataIssueSolver instance];
155+
[sharedDataIssueSolver migrateAuthKeyFor:username];
155156
});
156157
}
157158

0 commit comments

Comments
 (0)