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

--HG--
extra : rebase_source : 5fe3d6ad40939bfe5e842d075c1b0abc1226ac10
This commit is contained in:
Sebastian Kaspari 2016-04-13 13:01:52 +02:00
parent 3580657169
commit 46b5b88e2d

View File

@ -25,6 +25,7 @@ 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;
@ -74,7 +75,18 @@ public class CheckForUpdatesAction extends FeedAction {
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);
}
@ -108,6 +120,29 @@ public class CheckForUpdatesAction extends FeedAction {
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) {