Bug 1819456 - Update ASRouter messages when experiment recipes are updated. r=omc-reviewers,barret

Differential Revision: https://phabricator.services.mozilla.com/D171939
This commit is contained in:
Shane Hughes
2023-03-14 02:53:27 +00:00
parent fdd13dfa60
commit 3d2d5cd25f
5 changed files with 101 additions and 98 deletions

View File

@@ -97,7 +97,7 @@ const JEXL_PROVIDER_CACHE = new Set(["snippets"]);
// To observe the app locale change notification.
const TOPIC_INTL_LOCALE_CHANGED = "intl:app-locales-changed";
const TOPIC_EXPERIMENT_FORCE_ENROLLED = "nimbus:force-enroll";
const TOPIC_EXPERIMENT_ENROLLMENT_CHANGED = "nimbus:enrollments-updated";
// To observe the pref that controls if ASRouter should use the remote Fluent files for l10n.
const USE_REMOTE_L10N_PREF =
"browser.newtabpage.activity-stream.asrouter.useRemoteL10n";
@@ -627,7 +627,7 @@ class _ASRouter {
this.isUnblockedMessage = this.isUnblockedMessage.bind(this);
this.unblockAll = this.unblockAll.bind(this);
this.forceWNPanel = this.forceWNPanel.bind(this);
this._onExperimentForceEnrolled = this._onExperimentForceEnrolled.bind(
this._onExperimentEnrollmentsUpdated = this._onExperimentEnrollmentsUpdated.bind(
this
);
this.forcePBWindow = this.forcePBWindow.bind(this);
@@ -1046,8 +1046,8 @@ class _ASRouter {
lazy.SpecialMessageActions.blockMessageById = this.blockMessageById;
Services.obs.addObserver(this._onLocaleChanged, TOPIC_INTL_LOCALE_CHANGED);
Services.obs.addObserver(
this._onExperimentForceEnrolled,
TOPIC_EXPERIMENT_FORCE_ENROLLED
this._onExperimentEnrollmentsUpdated,
TOPIC_EXPERIMENT_ENROLLMENT_CHANGED
);
Services.prefs.addObserver(USE_REMOTE_L10N_PREF, this);
// sets .initialized to true and resolves .waitForInitialized promise
@@ -1079,8 +1079,8 @@ class _ASRouter {
TOPIC_INTL_LOCALE_CHANGED
);
Services.obs.removeObserver(
this._onExperimentForceEnrolled,
TOPIC_EXPERIMENT_FORCE_ENROLLED
this._onExperimentEnrollmentsUpdated,
TOPIC_EXPERIMENT_ENROLLMENT_CHANGED
);
Services.prefs.removeObserver(USE_REMOTE_L10N_PREF, this);
// If we added any CFR recommendations, they need to be removed
@@ -2029,14 +2029,13 @@ class _ASRouter {
await lazy.ToolbarPanelHub._hideToolbarButton(win);
}
async _onExperimentForceEnrolled(subject, topic, slug) {
async _onExperimentEnrollmentsUpdated() {
const experimentProvider = this.state.providers.find(
p => p.id === "messaging-experiments"
);
if (!experimentProvider.enabled) {
if (!experimentProvider?.enabled) {
return;
}
await this.loadMessagesFromAllProviders([experimentProvider]);
}