From fb8b64badc69d7288c16f1402f80e938a6c9cff3 Mon Sep 17 00:00:00 2001 From: joewalsh Date: Wed, 14 Sep 2016 13:25:54 -0400 Subject: [PATCH] use database key for checking notifications on save button controller --- Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m | 2 +- Wikipedia/Code/NSURL+WMFLinkParsing.h | 2 +- Wikipedia/Code/NSURL+WMFLinkParsing.m | 6 +++++- Wikipedia/Code/WMFSaveButtonController.m | 6 ++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m b/Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m index 6b1009e2c7f..aaa628676d1 100644 --- a/Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m +++ b/Wikipedia/Code/MWKHistoryEntry+WMFDatabaseStorable.m @@ -3,7 +3,7 @@ @implementation MWKHistoryEntry (WMFDatabaseStorable) + (NSString *)databaseKeyForURL:(NSURL *)url { - return url.wmf_desktopURLWithoutFragment.absoluteString; + return url.wmf_databaseKey; } - (NSString *)databaseKey { diff --git a/Wikipedia/Code/NSURL+WMFLinkParsing.h b/Wikipedia/Code/NSURL+WMFLinkParsing.h index 4098481803c..61064648ebe 100644 --- a/Wikipedia/Code/NSURL+WMFLinkParsing.h +++ b/Wikipedia/Code/NSURL+WMFLinkParsing.h @@ -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 diff --git a/Wikipedia/Code/NSURL+WMFLinkParsing.m b/Wikipedia/Code/NSURL+WMFLinkParsing.m index 26c6b632893..6aa131bf5c2 100644 --- a/Wikipedia/Code/NSURL+WMFLinkParsing.m +++ b/Wikipedia/Code/NSURL+WMFLinkParsing.m @@ -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]) { diff --git a/Wikipedia/Code/WMFSaveButtonController.m b/Wikipedia/Code/WMFSaveButtonController.m index 6859f2c4c61..4b506e5b873 100644 --- a/Wikipedia/Code/WMFSaveButtonController.m +++ b/Wikipedia/Code/WMFSaveButtonController.m @@ -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 @@ -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]; } @@ -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]; } }