Skip to content

Commit

Permalink
Merge pull request #903 from wikimedia/bug/save_from_safari/T145652
Browse files Browse the repository at this point in the history
use database key for checking notifications on save button controller
  • Loading branch information
joewalsh authored Sep 15, 2016
2 parents c756b66 + eefba3c commit 764fd3e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@implementation MWKHistoryEntry (WMFDatabaseStorable)

+ (NSString *)databaseKeyForURL:(NSURL *)url {
return url.wmf_desktopURLWithoutFragment.absoluteString;
return url.wmf_databaseKey;
}

- (NSString *)databaseKey {
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Code/NSURL+WMFLinkParsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extern NSString *const WMFDefaultSiteDomain;

@property (nonatomic, copy, readonly) NSString *wmf_titleWithUnderScores;

@property (nullable, nonatomic, copy, readonly) NSURL *wmf_desktopURLWithoutFragment;
@property (nullable, nonatomic, copy, readonly) NSString *wmf_databaseKey; // string suitable for using as a unique key for the article

#pragma mark - Introspection

Expand Down
6 changes: 5 additions & 1 deletion Wikipedia/Code/NSURL+WMFLinkParsing.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,17 @@ - (NSString *)wmf_language {
}


- (NSURL *)wmf_desktopURLWithoutFragment {
- (NSURL *)wmf_databaseKeyURL {
NSURLComponents *components = [NSURLComponents componentsWithURL:self resolvingAgainstBaseURL:NO];
components.host = [NSURLComponents wmf_hostWithDomain:self.wmf_domain language:self.wmf_language isMobile:NO];
components.fragment = nil;
components.scheme = @"https";
return components.URL;
}

- (NSString *)wmf_databaseKey {
return self.wmf_databaseKeyURL.absoluteString.precomposedStringWithCanonicalMapping;
}

- (NSString *)wmf_title {
if (![self wmf_isWikiResource]) {
Expand Down
6 changes: 4 additions & 2 deletions Wikipedia/Code/WMFSaveButtonController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ - (instancetype)initWithControl:(UIControl *)button
url:(NSURL *)url NS_DESIGNATED_INITIALIZER;

@property (nonatomic, strong) SavedPagesFunnel *savedPagesFunnel;
@property (nonatomic, copy) NSString *databaseKey;

@end

Expand Down Expand Up @@ -72,7 +73,8 @@ - (void)setUrl:(NSURL *)url {
return;
}
[self unobserveURL:_url];
_url = url;
_url = [url copy];
self.databaseKey = _url.wmf_databaseKey;
[self observeURL:_url];
[self updateSavedButtonState];
}
Expand Down Expand Up @@ -124,7 +126,7 @@ - (void)unobserveURL:(NSURL *)url {
}

- (void)itemWasUpdatedWithNotification:(NSNotification *)note {
if ([note.object isEqual:[self.url absoluteString]]) {
if ([note.object isEqual:self.databaseKey]) {
[self updateSavedButtonState];
}
}
Expand Down

0 comments on commit 764fd3e

Please sign in to comment.