Bug 1261836 - Content notifications: Check if new content is already in history. r=mcomella,mfinkle
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 13 Apr 2016 13:01:52 +0200
changeset 294487 9a49926c3edbf1bad4424cd206f3bd30424784b4
parent 294486 a36e52a4543d28f36975ef677ca13c720c1bc1d7
child 294488 e086812341563534fb85964abda7effdcca09e1c
push id30204
push usercbook@mozilla.com
push dateSat, 23 Apr 2016 08:46:55 +0000
treeherdermozilla-central@37f04460ddb7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, mfinkle
bugs1261836
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1261836 - Content notifications: Check if new content is already in history. r=mcomella,mfinkle If the URL of new content is already in the user's history then we won't show a notification for it. MozReview-Commit-ID: B26SBvXOnxY
mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
@@ -20,16 +20,17 @@ import android.text.format.DateFormat;
 
 import org.json.JSONException;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.UrlAnnotations;
 import org.mozilla.gecko.feeds.FeedFetcher;
 import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.parser.Feed;
 import org.mozilla.gecko.feeds.subscriptions.FeedSubscription;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.util.StringUtils;
@@ -69,17 +70,28 @@ public class CheckForUpdatesAction exten
         }
 
         try {
             while (cursor.moveToNext()) {
                 FeedSubscription subscription = FeedSubscription.fromCursor(cursor);
 
                 FeedFetcher.FeedResponse response = checkFeedForUpdates(subscription);
                 if (response != null) {
-                    updatedFeeds.add(response.feed);
+                    final Feed feed = response.feed;
+
+                    if (!hasBeenVisited(browserDB, feed.getLastItem().getURL())) {
+                        // Only notify about this update if the last item hasn't been visited yet.
+                        updatedFeeds.add(feed);
+                    } else {
+                        Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
+                        Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL,
+                                TelemetryContract.Method.SERVICE,
+                                "content_update");
+                        Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
+                    }
 
                     urlAnnotations.updateFeedSubscription(resolver, subscription);
                 }
             }
         } catch (JSONException e) {
             log("Could not deserialize subscription", e);
         } finally {
             cursor.close();
@@ -103,16 +115,39 @@ public class CheckForUpdatesAction exten
 
             return response;
 
         }
 
         return null;
     }
 
+    /**
+     * Returns true if this URL has been visited before.
+     *
+     * We do an exact match. So this can fail if the feed uses a different URL and redirects to
+     * content. But it's better than no checks at all.
+     */
+    private boolean hasBeenVisited(final BrowserDB browserDB, final String url) {
+        final Cursor cursor = browserDB.getHistoryForURL(context.getContentResolver(), url);
+        if (cursor == null) {
+            return false;
+        }
+
+        try {
+            if (cursor.moveToFirst()) {
+                return cursor.getInt(cursor.getColumnIndex(BrowserContract.History.VISITS)) > 0;
+            }
+        } finally {
+            cursor.close();
+        }
+
+        return false;
+    }
+
     private void showNotification(List<Feed> updatedFeeds) {
         final int feedCount = updatedFeeds.size();
         if (feedCount == 0) {
             return;
         }
 
         if (feedCount == 1) {
             showNotificationForSingleUpdate(updatedFeeds.get(0));