зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1721239 - Pocket newtab server signal to toggle pocket collections. r=gvn
Differential Revision: https://phabricator.services.mozilla.com/D121150
This commit is contained in:
Родитель
b7b8e6f938
Коммит
6fda0f10ac
|
@ -1465,6 +1465,7 @@ pref("browser.newtabpage.activity-stream.discoverystream.hardcoded-basic-layout"
|
|||
pref("browser.newtabpage.activity-stream.discoverystream.spoc-positions", "2,4,11,20");
|
||||
pref("browser.newtabpage.activity-stream.discoverystream.spocs-endpoint", "");
|
||||
pref("browser.newtabpage.activity-stream.discoverystream.spocs-endpoint-query", "");
|
||||
pref("browser.newtabpage.activity-stream.discoverystream.sponsored-collections.enabled", false);
|
||||
|
||||
// List of regions that do not get stories, regardless of locale-list-config.
|
||||
pref("browser.newtabpage.activity-stream.discoverystream.region-stories-block", "FR");
|
||||
|
|
|
@ -66,6 +66,8 @@ const PREF_SHOW_SPONSORED = "showSponsored";
|
|||
const PREF_SPOC_IMPRESSIONS = "discoverystream.spoc.impressions";
|
||||
const PREF_FLIGHT_BLOCKS = "discoverystream.flight.blocks";
|
||||
const PREF_REC_IMPRESSIONS = "discoverystream.rec.impressions";
|
||||
const PREF_COLLECTIONS_ENABLED =
|
||||
"discoverystream.sponsored-collections.enabled";
|
||||
const PREF_COLLECTION_DISMISSIBLE = "discoverystream.isCollectionDismissible";
|
||||
const PREF_RECS_PERSONALIZED = "discoverystream.recs.personalized";
|
||||
const PREF_SPOCS_PERSONALIZED = "discoverystream.spocs.personalized";
|
||||
|
@ -451,7 +453,7 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
}
|
||||
|
||||
if (!layoutResp || !layoutResp.layout) {
|
||||
const isBasic =
|
||||
const isBasicLayout =
|
||||
this.config.hardcoded_basic_layout ||
|
||||
this.store.getState().Prefs.values[PREF_HARDCODED_BASIC_LAYOUT] ||
|
||||
this.store.getState().Prefs.values[PREF_REGION_BASIC_LAYOUT];
|
||||
|
@ -460,12 +462,17 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
.getState()
|
||||
.Prefs.values?.pocketConfig?.spocPositions?.split(`,`);
|
||||
|
||||
const sponsoredCollectionsEnabled = this.store.getState().Prefs.values[
|
||||
PREF_COLLECTIONS_ENABLED
|
||||
];
|
||||
|
||||
// Set a hardcoded layout if one is needed.
|
||||
// Changing values in this layout in memory object is unnecessary.
|
||||
layoutResp = getHardcodedLayout(
|
||||
isBasic,
|
||||
this.parseSpocPositions(spocPositions)
|
||||
);
|
||||
layoutResp = getHardcodedLayout({
|
||||
isBasicLayout,
|
||||
spocPositions: this.parseSpocPositions(spocPositions),
|
||||
sponsoredCollectionsEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
sendUpdate({
|
||||
|
@ -722,6 +729,19 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
}
|
||||
}
|
||||
|
||||
updateSponsoredCollectionsPref(collectionEnabled = false) {
|
||||
const currentState = this.store.getState().Prefs.values[
|
||||
PREF_COLLECTIONS_ENABLED
|
||||
];
|
||||
|
||||
// If the current state does not match the new state, update the pref.
|
||||
if (currentState !== collectionEnabled) {
|
||||
this.store.dispatch(
|
||||
ac.SetPref(PREF_COLLECTIONS_ENABLED, collectionEnabled)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async loadSpocs(sendUpdate, isStartup) {
|
||||
const cachedData = (await this.cache.get()) || {};
|
||||
let spocsState;
|
||||
|
@ -766,6 +786,9 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
// Without a version 1, the override is now a command to turn off personalization.
|
||||
!spocsResponse.settings.feature_flags.spoc_v2
|
||||
);
|
||||
this.updateSponsoredCollectionsPref(
|
||||
spocsResponse.settings.feature_flags.collections
|
||||
);
|
||||
}
|
||||
|
||||
const spocsResultPromises = this.getPlacements().map(
|
||||
|
@ -1579,6 +1602,9 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
// This is a config reset directly related to Discovery Stream pref.
|
||||
this.configReset();
|
||||
break;
|
||||
case PREF_COLLECTIONS_ENABLED:
|
||||
this.onPocketConfigChanged();
|
||||
break;
|
||||
case PREF_USER_TOPSTORIES:
|
||||
case PREF_SYSTEM_TOPSTORIES:
|
||||
if (!action.data.value) {
|
||||
|
@ -1818,7 +1844,11 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
|
|||
//
|
||||
// NOTE: There is some branching logic in the template based on `isBasicLayout`
|
||||
//
|
||||
getHardcodedLayout = (isBasicLayout, spocPositions = [2, 4, 11, 20]) => ({
|
||||
getHardcodedLayout = ({
|
||||
isBasicLayout,
|
||||
spocPositions = [2, 4, 11, 20],
|
||||
sponsoredCollectionsEnabled = false,
|
||||
}) => ({
|
||||
lastUpdate: Date.now(),
|
||||
spocs: {
|
||||
url: "https://spocs.getpocket.com/spocs",
|
||||
|
@ -1836,34 +1866,38 @@ getHardcodedLayout = (isBasicLayout, spocPositions = [2, 4, 11, 20]) => ({
|
|||
},
|
||||
properties: {},
|
||||
},
|
||||
{
|
||||
type: "CollectionCardGrid",
|
||||
properties: {
|
||||
items: 3,
|
||||
},
|
||||
header: {
|
||||
title: "",
|
||||
},
|
||||
placement: {
|
||||
name: "sponsored-collection",
|
||||
ad_types: [3617],
|
||||
zone_ids: [217759, 218031],
|
||||
},
|
||||
spocs: {
|
||||
probability: 1,
|
||||
positions: [
|
||||
...(sponsoredCollectionsEnabled
|
||||
? [
|
||||
{
|
||||
index: 0,
|
||||
type: "CollectionCardGrid",
|
||||
properties: {
|
||||
items: 3,
|
||||
},
|
||||
header: {
|
||||
title: "",
|
||||
},
|
||||
placement: {
|
||||
name: "sponsored-collection",
|
||||
ad_types: [3617],
|
||||
zone_ids: [217759, 218031],
|
||||
},
|
||||
spocs: {
|
||||
probability: 1,
|
||||
positions: [
|
||||
{
|
||||
index: 0,
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
type: "Message",
|
||||
header: {
|
||||
|
|
|
@ -177,6 +177,11 @@ this.PrefsFeed = class PrefsFeed {
|
|||
this._setBoolPref(values, "logowordmark.alwaysVisible", false);
|
||||
this._setBoolPref(values, "feeds.section.topstories", false);
|
||||
this._setBoolPref(values, "discoverystream.enabled", false);
|
||||
this._setBoolPref(
|
||||
values,
|
||||
"discoverystream.sponsored-collections.enabled",
|
||||
false
|
||||
);
|
||||
this._setBoolPref(values, "discoverystream.isCollectionDismissible", false);
|
||||
this._setBoolPref(values, "discoverystream.hardcoded-basic-layout", false);
|
||||
this._setBoolPref(values, "discoverystream.recs.personalized", false);
|
||||
|
|
|
@ -325,7 +325,7 @@ describe("DiscoveryStreamFeed", () => {
|
|||
"https://spocs.getpocket.com/spocs"
|
||||
);
|
||||
const { layout } = feed.store.getState().DiscoveryStream;
|
||||
assert.equal(layout[0].components[3].properties.items, 3);
|
||||
assert.equal(layout[0].components[2].properties.items, 3);
|
||||
});
|
||||
it("should use 1 row layout if specified", async () => {
|
||||
feed.config.hardcoded_layout = true;
|
||||
|
@ -348,7 +348,7 @@ describe("DiscoveryStreamFeed", () => {
|
|||
await feed.loadLayout(feed.store.dispatch);
|
||||
|
||||
const { layout } = feed.store.getState().DiscoveryStream;
|
||||
assert.equal(layout[0].components[3].properties.items, 3);
|
||||
assert.equal(layout[0].components[2].properties.items, 3);
|
||||
});
|
||||
it("should use 7 row layout if specified", async () => {
|
||||
feed.config.hardcoded_layout = true;
|
||||
|
@ -371,7 +371,7 @@ describe("DiscoveryStreamFeed", () => {
|
|||
await feed.loadLayout(feed.store.dispatch);
|
||||
|
||||
const { layout } = feed.store.getState().DiscoveryStream;
|
||||
assert.equal(layout[0].components[3].properties.items, 21);
|
||||
assert.equal(layout[0].components[2].properties.items, 21);
|
||||
});
|
||||
it("should use new spocs endpoint if in the config", async () => {
|
||||
feed.config.spocs_endpoint = "https://spocs.getpocket.com/spocs2";
|
||||
|
@ -410,7 +410,7 @@ describe("DiscoveryStreamFeed", () => {
|
|||
"https://spocs.getpocket.com/spocs"
|
||||
);
|
||||
const { layout } = feed.store.getState().DiscoveryStream;
|
||||
assert.equal(layout[0].components[3].properties.items, 3);
|
||||
assert.equal(layout[0].components[2].properties.items, 3);
|
||||
});
|
||||
it("should use new spocs endpoint if in a FF pref", async () => {
|
||||
feed.store = createStore(combineReducers(reducers), {
|
||||
|
@ -2098,6 +2098,16 @@ describe("DiscoveryStreamFeed", () => {
|
|||
|
||||
assert.calledOnce(feed.onPocketConfigChanged);
|
||||
});
|
||||
it("should fire onPocketConfigChanged when collections pref changes", async () => {
|
||||
sandbox.stub(feed, "onPocketConfigChanged").returns(Promise.resolve());
|
||||
|
||||
await feed.onAction({
|
||||
type: at.PREF_CHANGED,
|
||||
data: { name: "discoverystream.sponsored-collections.enabled" },
|
||||
});
|
||||
|
||||
assert.calledOnce(feed.onPocketConfigChanged);
|
||||
});
|
||||
it("should call clearSpocs when sponsored content is turned off", async () => {
|
||||
sandbox.stub(feed, "clearSpocs").returns(Promise.resolve());
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче