Bug 1489962 - Add snippets targeting, Pocket tagging and bug fixes to Activity Stream r=k88hudson

Differential Revision: https://phabricator.services.mozilla.com/D5914
This commit is contained in:
Ed Lee
2018-09-19 13:53:10 +00:00
parent 751926e5d0
commit f7f0cd229e
464 changed files with 7091 additions and 2119 deletions

View File

@@ -313,7 +313,7 @@ export class SnippetsProvider {
Object.assign(this, {
appData: {},
elementId: "snippets",
connect: true
connect: true,
}, options);
// Add listener so we know when snippets are blocked on other pages
@@ -381,17 +381,25 @@ export function addSnippetsSubscriber(store) {
store.subscribe(async () => {
const state = store.getState();
let snippetsEnabled = false;
try {
snippetsEnabled = JSON.parse(state.Prefs.values["asrouter.messageProviders"]).find(i => i.id === "snippets").enabled;
} catch (e) {}
const isASRouterEnabled = state.Prefs.values.asrouterExperimentEnabled && snippetsEnabled;
// state.Prefs.values["feeds.snippets"]: Should snippets be shown?
// state.Snippets.initialized Is the snippets data initialized?
// snippets.initialized: Is SnippetsProvider currently initialised?
if (state.Prefs.values["feeds.snippets"] &&
// If the message center experiment is enabled, don't show snippets
!isASRouterEnabled &&
/**
* Sorry this code is so complicated. It will be removed soon.
* This is what the different values actually mean:
*
* ASRouter.initialized Is ASRouter.jsm initialised?
* ASRouter.allowLegacySnippets Are ASRouter snippets turned OFF (i.e. legacy snippets are allowed)
* state.Prefs.values["feeds.snippets"] User preference for snippets
* state.Snippets.initialized Is SnippetsFeed.jsm initialised?
* snippets.initialized Is in-content snippets currently initialised?
* state.Prefs.values.disableSnippets This pref is used to disable legacy snippets in an emergency
* in a way that is not user-editable (true = disabled)
*/
/** If we should initialize snippets... */
if (
state.Prefs.values["feeds.snippets"] &&
state.ASRouter.initialized &&
state.ASRouter.allowLegacySnippets &&
!state.Prefs.values.disableSnippets &&
state.Snippets.initialized &&
!snippets.initialized &&
@@ -401,13 +409,27 @@ export function addSnippetsSubscriber(store) {
) {
initializing = true;
await snippets.init({appData: state.Snippets});
// istanbul ignore if
if (state.Prefs.values["asrouter.devtoolsEnabled"]) {
console.log("Legacy snippets initialized"); // eslint-disable-line no-console
}
initializing = false;
/** If we should remove snippets... */
} else if (
(state.Prefs.values["feeds.snippets"] === false ||
state.Prefs.values.disableSnippets === true) &&
(
state.Prefs.values["feeds.snippets"] === false ||
state.Prefs.values.disableSnippets === true ||
(state.ASRouter.initialized && !state.ASRouter.allowLegacySnippets)
) &&
snippets.initialized
) {
// Remove snippets
snippets.uninit();
// istanbul ignore if
if (state.Prefs.values["asrouter.devtoolsEnabled"]) {
console.log("Legacy snippets removed"); // eslint-disable-line no-console
}
}
});