feat(addon): Invoke the Recommendation Provider on addon-side
This commit is contained in:
Родитель
3b695a7290
Коммит
9a52a6b1c2
|
@ -124,7 +124,7 @@ function RequestMoreRecentLinks(beforeDate) {
|
|||
}
|
||||
|
||||
function RequestHighlightsLinks() {
|
||||
return RequestExpect("HIGHLIGHTS_LINKS_REQUEST", "HIGHLIGHTS_LINKS_RESPONSE", {meta: {getRecommendation: true}});
|
||||
return RequestExpect("HIGHLIGHTS_LINKS_REQUEST", "HIGHLIGHTS_LINKS_RESPONSE");
|
||||
}
|
||||
|
||||
function RequestSearchState() {
|
||||
|
|
|
@ -18,6 +18,7 @@ const {PlacesProvider} = require("lib/PlacesProvider");
|
|||
const {SearchProvider} = require("lib/SearchProvider");
|
||||
const {TabTracker} = require("lib/TabTracker");
|
||||
const {PreviewProvider} = require("lib/PreviewProvider");
|
||||
const {RecommendationProvider} = require("lib/RecommendationProvider");
|
||||
const {TelemetrySender} = require("lib/TelemetrySender");
|
||||
const {PerfMeter} = require("lib/PerfMeter");
|
||||
const {AppURLHider} = require("lib/AppURLHider");
|
||||
|
@ -47,6 +48,7 @@ const DEFAULT_OPTIONS = {
|
|||
onRemoveWorker: null,
|
||||
previewCacheTimeout: 21600000, // every 6 hours, rebuild/repopulate the cache
|
||||
placesCacheTimeout: 1800000, // every 30 minutes, rebuild/repopulate the cache
|
||||
recommendationTTL: 3600000, // every hour, get a new recommendation
|
||||
};
|
||||
|
||||
const PLACES_CHANGES_EVENTS = [
|
||||
|
@ -107,6 +109,15 @@ function ActivityStreams(metadataStore, options = {}) {
|
|||
|
||||
this._asyncBuildPreviewCache();
|
||||
this._startPeriodicBuildPreviewCache(this.options.previewCacheTimeout);
|
||||
|
||||
// Only create RecommendationProvider if they are in the experiment
|
||||
if (this._experimentProvider.data.recommendedHighlight) {
|
||||
this._recommendationProvider = new RecommendationProvider(this._previewProvider);
|
||||
if (simplePrefs.prefs.recommendations) {
|
||||
this._recommendationProvider.asyncSetRecommendedContent();
|
||||
}
|
||||
this._refreshRecommendations(this.options.recommendationTTL);
|
||||
}
|
||||
}
|
||||
|
||||
ActivityStreams.prototype = {
|
||||
|
@ -114,6 +125,7 @@ ActivityStreams.prototype = {
|
|||
_pagemod: null,
|
||||
_button: null,
|
||||
_previewCacheTimeoutID: null,
|
||||
_newRecommendationTimeoutID: null,
|
||||
|
||||
/**
|
||||
* Send a message to a worker
|
||||
|
@ -195,6 +207,9 @@ ActivityStreams.prototype = {
|
|||
case am.type("NOTIFY_UNBLOCK_ALL"):
|
||||
PlacesProvider.links.unblockAll();
|
||||
break;
|
||||
case am.type("NOTIFY_BLOCK_RECOMMENDATION"):
|
||||
this._recommendationProvider.setBlockedRecommendation(msg.data);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -204,7 +219,12 @@ ActivityStreams.prototype = {
|
|||
_processAndSendLinks(placesLinks, responseType, worker, options) {
|
||||
let {append, previewsOnly, skipPreviewRequest} = options || {};
|
||||
const event = this._tabTracker.generateEvent({source: responseType});
|
||||
const cachedLinks = this._previewProvider.getLinkMetadata(placesLinks, event, skipPreviewRequest, previewsOnly);
|
||||
let inExperiment = this._experimentProvider.data.recommendedHighlight;
|
||||
let isAHighlight = responseType === "HIGHLIGHTS_LINKS_RESPONSE";
|
||||
let shouldGetRecommendation = isAHighlight && simplePrefs.prefs.recommendations && inExperiment;
|
||||
let recommendation = shouldGetRecommendation ? this._recommendationProvider.getRecommendation() : null;
|
||||
let linksToProcess = placesLinks.concat([recommendation]).filter(link => link);
|
||||
const cachedLinks = this._previewProvider.getLinkMetadata(linksToProcess, event, skipPreviewRequest, previewsOnly);
|
||||
cachedLinks.then(linksToSend => this.send(am.actions.Response(responseType, linksToSend, {append}), worker));
|
||||
},
|
||||
|
||||
|
@ -293,6 +313,11 @@ ActivityStreams.prototype = {
|
|||
this._tabTracker.handleUserEvent(msg.data);
|
||||
},
|
||||
|
||||
_respondToRecommendationToggle() {
|
||||
simplePrefs.prefs.recommendations = !simplePrefs.prefs.recommendations;
|
||||
this.broadcast(am.actions.Response("RECEIVE_RECOMMENDATION_TOGGLE", {recommendationStatus: simplePrefs.prefs.recommendations}));
|
||||
},
|
||||
|
||||
_onRouteChange({msg} = {}) {
|
||||
if (msg) {
|
||||
this._tabTracker.handleRouteChange(tabs.activeTab, msg.data);
|
||||
|
@ -309,6 +334,8 @@ ActivityStreams.prototype = {
|
|||
return this._handleUserEvent(args);
|
||||
case am.type("EXPERIMENTS_REQUEST"):
|
||||
return this._respondToExperimentsRequest(args);
|
||||
case am.type("NOTIFY_TOGGLE_RECOMMENDATIONS"):
|
||||
return this._respondToRecommendationToggle();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -442,6 +469,21 @@ ActivityStreams.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Start a timer to fetch a new recommendation every hour. This will only
|
||||
* run for those in the experiment
|
||||
*/
|
||||
_refreshRecommendations(recommendationTTL) {
|
||||
if (recommendationTTL) {
|
||||
this._newRecommendationTimeoutID = setTimeout(() => {
|
||||
if (simplePrefs.prefs.recommendations) {
|
||||
this._recommendationProvider.getRecommendation(true);
|
||||
}
|
||||
this._refreshRecommendations(recommendationTTL);
|
||||
}, recommendationTTL);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets up communications with the pages and manages the lifecycle of workers
|
||||
*/
|
||||
|
@ -574,7 +616,13 @@ ActivityStreams.prototype = {
|
|||
let defaultUnload = () => {
|
||||
clearTimeout(this._previewCacheTimeoutID);
|
||||
clearTimeout(this._placesCacheTimeoutID);
|
||||
if (this._newRecommendationTimeoutID) {
|
||||
clearTimeout(this._newRecommendationTimeoutID);
|
||||
}
|
||||
this._previewProvider.uninit();
|
||||
if (this._recommendationProvider) {
|
||||
this._recommendationProvider.uninit();
|
||||
}
|
||||
NewTabURL.reset();
|
||||
Services.prefs.clearUserPref("places.favicons.optimizeToDimension");
|
||||
this.workers.clear();
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
"name": "recommendations",
|
||||
"title": "Show me recommendations",
|
||||
"type": "bool",
|
||||
"value": true
|
||||
"value": false
|
||||
}
|
||||
],
|
||||
"repository": "mozilla/activity-stream",
|
||||
|
|
Загрузка…
Ссылка в новой задаче