Brion VIBBER has submitted this change and it was merged.

Change subject: Fix for updating lastVisited date of article being navigated 
away from.
......................................................................


Fix for updating lastVisited date of article being navigated away from.

Change-Id: Iaade5f0555c032fb83184b58d29c3eec6b5494a0
---
M wikipedia/View Controllers/WebView/WebViewController.m
1 file changed, 38 insertions(+), 2 deletions(-)

Approvals:
  Brion VIBBER: Verified; Looks good to me, approved



diff --git a/wikipedia/View Controllers/WebView/WebViewController.m 
b/wikipedia/View Controllers/WebView/WebViewController.m
index e3f4977..1ab10f4 100644
--- a/wikipedia/View Controllers/WebView/WebViewController.m
+++ b/wikipedia/View Controllers/WebView/WebViewController.m
@@ -100,6 +100,10 @@
 @property (nonatomic) BOOL editable;
 @property (copy) NSString *protectionStatus;
 
+// These are presently only used by 
updateHistoryDateVisitedForArticleBeingNavigatedFrom method.
+@property (strong, nonatomic) NSString *currentTitle;
+@property (strong, nonatomic) NSString *currentDomain;
+
 @end
 
 #pragma mark Internal variables
@@ -1179,6 +1183,29 @@
     }
 }
 
+-(void)updateHistoryDateVisitedForArticleBeingNavigatedFrom
+{
+    [articleDataContext_.mainContext performBlockAndWait:^(){
+        NSManagedObjectID *articleID =
+        [articleDataContext_.mainContext getArticleIDForTitle: 
self.currentTitle
+                                                       domain: 
self.currentDomain];
+        if (articleID) {
+            Article *article = (Article *)[articleDataContext_.mainContext 
objectWithID:articleID];
+            if (article) {
+                if (article.history.count > 0) { // There should only be a 
single history item.
+                    History *history = [article.history anyObject];
+                    history.dateVisited = [NSDate date];
+                    NSError *error = nil;
+                    [articleDataContext_.mainContext save:&error];
+                    if (error) {
+                        NSLog(@"error = %@", error);
+                    }
+                }
+            }
+        }
+    }];
+}
+
 #pragma mark Article loading ops
 
 - (void)navigateToPage: (MWPageTitle *)title
@@ -1200,6 +1227,15 @@
     if (invalidateCache) [self invalidateCacheForPageTitle:title 
domain:domain];
     
     self.jumpToFragment = title.fragment;
+
+    // Update the history dateVisited timestamp of the article *presently 
shown* by the webView
+    // only if the article to be loaded was NOT loaded via back or forward 
buttons. The article
+    // being *navigated to* has its history dateVisited updated later in this 
method.
+    if (discoveryMethod != DISCOVERY_METHOD_BACKFORWARD) {
+        [self updateHistoryDateVisitedForArticleBeingNavigatedFrom];
+    }
+    self.currentTitle = title.text;
+    self.currentDomain = domain;
     
     [self retrieveArticleForPageTitle: title
                                domain: domain
@@ -1260,8 +1296,8 @@
     if (articleID) {
         Article *article = (Article *)[articleDataContext_.mainContext 
objectWithID:articleID];
 
-        // Update the history dateVisited timestamp only if the article was 
NOT loaded
-        // via back or forward buttons.
+        // Update the history dateVisited timestamp of the article to be 
visited only
+        // if the article was NOT loaded via back or forward buttons.
         if (![discoveryMethod isEqualToString:@"backforward"]) {
             if (article.history.count > 0) { // There should only be a single 
history item.
                 History *history = [article.history anyObject];

-- 
To view, visit https://gerrit.wikimedia.org/r/149198
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaade5f0555c032fb83184b58d29c3eec6b5494a0
Gerrit-PatchSet: 2
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to