Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions WordPress/Classes/Services/AccountService.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ - (void)setupAppExtensionsWithDefaultAccount:(WPAccount *)defaultAccount inConte
NSNumber *siteId = defaultBlog.dotComID;
NSString *blogName = defaultBlog.settings.name;
NSString *blogUrl = defaultBlog.displayURL;

NSString *oauth2Token = defaultAccount.authToken;
TodayExtensionService *service = [TodayExtensionService new];
if (defaultBlog == nil || defaultBlog.isDeleted) {
dispatch_async(dispatch_get_main_queue(), ^{
TodayExtensionService *service = [TodayExtensionService new];
[service removeTodayWidgetConfiguration];

[ShareExtensionService removeShareExtensionConfiguration];
Expand All @@ -415,9 +415,6 @@ - (void)setupAppExtensionsWithDefaultAccount:(WPAccount *)defaultAccount inConte
});
} else {
// Required Attributes

NSString *oauth2Token = defaultAccount.authToken;

// For the Today Extensions, if the user has set a non-primary site, use that.
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:WPAppGroupName];
NSNumber *todayExtensionSiteID = [sharedDefaults objectForKey:AppConfigurationWidgetStatsToday.userDefaultsSiteIdKey];
Expand All @@ -441,8 +438,7 @@ - (void)setupAppExtensionsWithDefaultAccount:(WPAccount *)defaultAccount inConte
[service configureTodayWidgetWithSiteID:todayExtensionSiteID
blogName:todayExtensionBlogName
blogUrl:todayExtensionBlogUrl
siteTimeZone:timeZone
andOAuth2Token:oauth2Token];
siteTimeZone:timeZone];

[ShareExtensionService configureShareExtensionDefaultSiteID:siteId.integerValue defaultSiteName:blogName];
[ShareExtensionService configureShareExtensionToken:defaultAccount.authToken];
Expand All @@ -456,7 +452,11 @@ - (void)setupAppExtensionsWithDefaultAccount:(WPAccount *)defaultAccount inConte
[NotificationSupportService insertServiceExtensionUserID:defaultAccount.userID.stringValue];
});
}

if (oauth2Token.length > 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[service configureTodayWidgetOAuth2Token:oauth2Token];
});
}
}

- (void)purgeAccountIfUnused:(WPAccount *)account
Expand Down
5 changes: 3 additions & 2 deletions WordPress/Classes/Services/TodayExtensionService.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

@interface TodayExtensionService : NSObject

- (void)configureTodayWidgetOAuth2Token:(NSString *)oauth2Token;

- (void)configureTodayWidgetWithSiteID:(NSNumber *)siteID
blogName:(NSString *)blogName
blogUrl:(NSString *)blogUrl
siteTimeZone:(NSTimeZone *)timeZone
andOAuth2Token:(NSString *)oauth2Token;
siteTimeZone:(NSTimeZone *)timeZone;

- (void)removeTodayWidgetConfiguration;

Expand Down
29 changes: 15 additions & 14 deletions WordPress/Classes/Services/TodayExtensionService.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@

@implementation TodayExtensionService

- (void)configureTodayWidgetOAuth2Token:(NSString *)oauth2Token {
NSParameterAssert(oauth2Token.length > 0);

NSError *error;
[SFHFKeychainUtils storeUsername:AppConfigurationWidgetStats.keychainTokenKey
andPassword:oauth2Token
forServiceName:AppConfigurationWidgetStats.keychainServiceName
accessGroup:WPAppKeychainAccessGroup
updateExisting:YES
error:&error];
if (error) {
DDLogError(@"Today Widget OAuth2Token error: %@", error);
}
}

- (void)configureTodayWidgetWithSiteID:(NSNumber *)siteID
blogName:(NSString *)blogName
blogUrl:(NSString *)blogUrl
siteTimeZone:(NSTimeZone *)timeZone
andOAuth2Token:(NSString *)oauth2Token
{
NSParameterAssert(siteID != nil);
NSParameterAssert(blogName != nil);
NSParameterAssert(timeZone != nil);
NSParameterAssert(oauth2Token.length > 0);

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:WPAppGroupName];

Expand All @@ -30,18 +43,6 @@ - (void)configureTodayWidgetWithSiteID:(NSNumber *)siteID
[sharedDefaults setObject:siteID forKey:AppConfigurationWidgetStatsToday.userDefaultsSiteIdKey];
[sharedDefaults setObject:blogName forKey:AppConfigurationWidgetStatsToday.userDefaultsSiteNameKey];
[sharedDefaults setObject:blogUrl forKey:AppConfigurationWidgetStatsToday.userDefaultsSiteUrlKey];

NSError *error;

[SFHFKeychainUtils storeUsername:AppConfigurationWidgetStats.keychainTokenKey
andPassword:oauth2Token
forServiceName:AppConfigurationWidgetStats.keychainServiceName
accessGroup:WPAppKeychainAccessGroup
updateExisting:YES
error:&error];
if (error) {
DDLogError(@"Today Widget OAuth2Token error: %@", error);
}
}

- (void)removeTodayWidgetConfiguration
Expand Down
4 changes: 2 additions & 2 deletions WordPress/Classes/ViewRelated/Stats/StatsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ - (void)saveSiteDetailsForTodayWidget
{
TodayExtensionService *service = [TodayExtensionService new];

[service configureTodayWidgetOAuth2Token:SiteStatsInformation.sharedInstance.oauth2Token];
[service configureTodayWidgetWithSiteID:SiteStatsInformation.sharedInstance.siteID
blogName:self.blog.settings.name
blogUrl:self.blog.displayURL
siteTimeZone:SiteStatsInformation.sharedInstance.siteTimeZone
andOAuth2Token:SiteStatsInformation.sharedInstance.oauth2Token];
siteTimeZone:SiteStatsInformation.sharedInstance.siteTimeZone];
}


Expand Down