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() {
|
function RequestHighlightsLinks() {
|
||||||
return RequestExpect("HIGHLIGHTS_LINKS_REQUEST", "HIGHLIGHTS_LINKS_RESPONSE", {meta: {getRecommendation: true}});
|
return RequestExpect("HIGHLIGHTS_LINKS_REQUEST", "HIGHLIGHTS_LINKS_RESPONSE");
|
||||||
}
|
}
|
||||||
|
|
||||||
function RequestSearchState() {
|
function RequestSearchState() {
|
||||||
|
|
|
@ -18,6 +18,7 @@ const {PlacesProvider} = require("lib/PlacesProvider");
|
||||||
const {SearchProvider} = require("lib/SearchProvider");
|
const {SearchProvider} = require("lib/SearchProvider");
|
||||||
const {TabTracker} = require("lib/TabTracker");
|
const {TabTracker} = require("lib/TabTracker");
|
||||||
const {PreviewProvider} = require("lib/PreviewProvider");
|
const {PreviewProvider} = require("lib/PreviewProvider");
|
||||||
|
const {RecommendationProvider} = require("lib/RecommendationProvider");
|
||||||
const {TelemetrySender} = require("lib/TelemetrySender");
|
const {TelemetrySender} = require("lib/TelemetrySender");
|
||||||
const {PerfMeter} = require("lib/PerfMeter");
|
const {PerfMeter} = require("lib/PerfMeter");
|
||||||
const {AppURLHider} = require("lib/AppURLHider");
|
const {AppURLHider} = require("lib/AppURLHider");
|
||||||
|
@ -47,6 +48,7 @@ const DEFAULT_OPTIONS = {
|
||||||
onRemoveWorker: null,
|
onRemoveWorker: null,
|
||||||
previewCacheTimeout: 21600000, // every 6 hours, rebuild/repopulate the cache
|
previewCacheTimeout: 21600000, // every 6 hours, rebuild/repopulate the cache
|
||||||
placesCacheTimeout: 1800000, // every 30 minutes, 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 = [
|
const PLACES_CHANGES_EVENTS = [
|
||||||
|
@ -107,6 +109,15 @@ function ActivityStreams(metadataStore, options = {}) {
|
||||||
|
|
||||||
this._asyncBuildPreviewCache();
|
this._asyncBuildPreviewCache();
|
||||||
this._startPeriodicBuildPreviewCache(this.options.previewCacheTimeout);
|
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 = {
|
ActivityStreams.prototype = {
|
||||||
|
@ -114,6 +125,7 @@ ActivityStreams.prototype = {
|
||||||
_pagemod: null,
|
_pagemod: null,
|
||||||
_button: null,
|
_button: null,
|
||||||
_previewCacheTimeoutID: null,
|
_previewCacheTimeoutID: null,
|
||||||
|
_newRecommendationTimeoutID: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to a worker
|
* Send a message to a worker
|
||||||
|
@ -195,6 +207,9 @@ ActivityStreams.prototype = {
|
||||||
case am.type("NOTIFY_UNBLOCK_ALL"):
|
case am.type("NOTIFY_UNBLOCK_ALL"):
|
||||||
PlacesProvider.links.unblockAll();
|
PlacesProvider.links.unblockAll();
|
||||||
break;
|
break;
|
||||||
|
case am.type("NOTIFY_BLOCK_RECOMMENDATION"):
|
||||||
|
this._recommendationProvider.setBlockedRecommendation(msg.data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -204,7 +219,12 @@ ActivityStreams.prototype = {
|
||||||
_processAndSendLinks(placesLinks, responseType, worker, options) {
|
_processAndSendLinks(placesLinks, responseType, worker, options) {
|
||||||
let {append, previewsOnly, skipPreviewRequest} = options || {};
|
let {append, previewsOnly, skipPreviewRequest} = options || {};
|
||||||
const event = this._tabTracker.generateEvent({source: responseType});
|
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));
|
cachedLinks.then(linksToSend => this.send(am.actions.Response(responseType, linksToSend, {append}), worker));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -293,6 +313,11 @@ ActivityStreams.prototype = {
|
||||||
this._tabTracker.handleUserEvent(msg.data);
|
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} = {}) {
|
_onRouteChange({msg} = {}) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
this._tabTracker.handleRouteChange(tabs.activeTab, msg.data);
|
this._tabTracker.handleRouteChange(tabs.activeTab, msg.data);
|
||||||
|
@ -309,6 +334,8 @@ ActivityStreams.prototype = {
|
||||||
return this._handleUserEvent(args);
|
return this._handleUserEvent(args);
|
||||||
case am.type("EXPERIMENTS_REQUEST"):
|
case am.type("EXPERIMENTS_REQUEST"):
|
||||||
return this._respondToExperimentsRequest(args);
|
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
|
* Sets up communications with the pages and manages the lifecycle of workers
|
||||||
*/
|
*/
|
||||||
|
@ -574,7 +616,13 @@ ActivityStreams.prototype = {
|
||||||
let defaultUnload = () => {
|
let defaultUnload = () => {
|
||||||
clearTimeout(this._previewCacheTimeoutID);
|
clearTimeout(this._previewCacheTimeoutID);
|
||||||
clearTimeout(this._placesCacheTimeoutID);
|
clearTimeout(this._placesCacheTimeoutID);
|
||||||
|
if (this._newRecommendationTimeoutID) {
|
||||||
|
clearTimeout(this._newRecommendationTimeoutID);
|
||||||
|
}
|
||||||
this._previewProvider.uninit();
|
this._previewProvider.uninit();
|
||||||
|
if (this._recommendationProvider) {
|
||||||
|
this._recommendationProvider.uninit();
|
||||||
|
}
|
||||||
NewTabURL.reset();
|
NewTabURL.reset();
|
||||||
Services.prefs.clearUserPref("places.favicons.optimizeToDimension");
|
Services.prefs.clearUserPref("places.favicons.optimizeToDimension");
|
||||||
this.workers.clear();
|
this.workers.clear();
|
||||||
|
|
|
@ -142,7 +142,7 @@
|
||||||
"name": "recommendations",
|
"name": "recommendations",
|
||||||
"title": "Show me recommendations",
|
"title": "Show me recommendations",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"value": true
|
"value": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": "mozilla/activity-stream",
|
"repository": "mozilla/activity-stream",
|
||||||
|
|
Загрузка…
Ссылка в новой задаче