Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Bug 1485345 - Add timestamp targeting (#4357)
Browse files Browse the repository at this point in the history
  • Loading branch information
piatra authored and k88hudson committed Aug 27, 2018
1 parent 851d29c commit be30a49
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
20 changes: 19 additions & 1 deletion content-src/asrouter/README.md
Expand Up @@ -5,7 +5,25 @@
Name | Used for | Type | Example value
--- | --- | --- | ---
`whitelistHosts` | Whitelist a host in order to fetch messages from its endpoint | `[String]` | `["gist.github.com", "gist.githubusercontent.com", "localhost:8000"]`
`snippetsUrl` | The main remote endpoint that serves all snippet messages | `String` | `https://activity-stream-icons.services.mozilla.com/v1/messages.json.br`
`messageProviders` | Message provider options | `Object` | [see below](#message-providers)

### Message providers

```json
[
{
"id" : "onboarding",
"type" : "local",
"localProvider" : "OnboardingMessageProvider"
},
{
"type" : "remote",
"url" : "https://snippets.cdn.mozilla.net/us-west/bundles/bundle_d6d90fb9098ce8b45e60acf601bcb91b68322309.json",
"updateCycleInMs" : 14400000,
"id" : "snippets"
}
]
```

## Admin Interface

Expand Down
10 changes: 8 additions & 2 deletions content-src/asrouter/schemas/message-format.md
Expand Up @@ -4,8 +4,6 @@ Field name | Type | Required | Description | Example / Note
--- | --- | --- | --- | ---
`id` | `string` | Yes | A unique identifier for the message that should not conflict with any other previous message | `ONBOARDING_1`
`template` | `string` | Yes | An id matching an existing Activity Stream Router template | [See example](https://github.com/mozilla/activity-stream/blob/33669c67c2269078a6d3d6d324fb48175d98f634/system-addon/content-src/message-center/templates/SimpleSnippet.jsx)
`publish_start` | `date` | No | When to start showing the message | `1524474850876`
`publish_end` | `date` | No | When to stop showing the message | `1524474850876`
`content` | `object` | Yes | An object containing all variables/props to be rendered in the template. Subset of allowed tags detailed below. | [See example below](#html-subset)
`bundled` | `integer` | No | The number of messages of the same template this one should be shown with | [See example below](#a-bundled-message-example)
`order` | `integer` | No | If bundled with other messages of the same template, which order should this one be placed in? Defaults to 0 if no order is desired | [See example below](#a-bundled-message-example)
Expand Down Expand Up @@ -96,6 +94,7 @@ Name | Type | Example value | Description
`isDefaultBrowser` | `Boolean` or `null` | Is Firefox the user's default browser? If we could not determine the default browser, this value is `null`
`profileAgeCreated` | Number | `1522843725924` | Profile creation timestamp
`profileAgeReset` | `Number` or `undefined` | `1522843725924` | When (if) the profile was reset
`currentDate` | `Date` | `Date 2018-08-22T15:48:04.100Z` | Date object of current time in UTC
`searchEngines` | `Object` | [example below](#searchengines-example) | Information about the current and available search engines
`browserSettings.attribution` | `Object` or `undefined` | [example below](#attribution-example) | Attribution for the source of of where the browser was downloaded.

Expand Down Expand Up @@ -170,4 +169,11 @@ Examples:
// targeting addon information
"targeting": "addonsInfo.addons['activity-stream@mozilla.org'].name == 'Activity Stream'"
}

{
"id": "7866",
"content": {...},
// targeting based on time
"targeting": "currentDate > '2018-08-08'|date"
}
```
3 changes: 3 additions & 0 deletions lib/ASRouterTargeting.jsm
Expand Up @@ -67,6 +67,9 @@ const TargetingGetters = {
update: settings.update
};
},
get currentDate() {
return new Date();
},
get profileAgeCreated() {
return new ProfileAge(null, null).created;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/ActivityStream.jsm
Expand Up @@ -210,7 +210,7 @@ const PREFS_CONFIG = new Map([
}, {
id: "snippets",
type: "remote",
url: "https://activity-stream-icons.services.mozilla.com/v1/messages.json.br",
url: "https://snippets.cdn.mozilla.net/us-west/bundles/bundle_d6d90fb9098ce8b45e60acf601bcb91b68322309.json",
updateCycleInMs: ONE_HOUR_IN_MS * 4,
enabled: AppConstants.MOZ_UPDATE_CHANNEL !== "release"
}, {
Expand Down
10 changes: 10 additions & 0 deletions test/browser/browser_asrouter_targeting.js
Expand Up @@ -110,6 +110,16 @@ add_task(async function checkProfileAgeReset() {
"should select correct item by profile age reset");
});

add_task(async function checkCurrentDate() {
let message = {id: "foo", targeting: `currentDate < '${new Date(Date.now() + 1000)}'|date`};
is(await ASRouterTargeting.findMatchingMessage({messages: [message]}), message,
"should select message based on currentDate < timestamp");

message = {id: "foo", targeting: `currentDate > '${new Date(Date.now() - 1000)}'|date`};
is(await ASRouterTargeting.findMatchingMessage({messages: [message]}), message,
"should select message based on currentDate > timestamp");
});

add_task(async function checkhasFxAccount() {
await pushPrefs(["services.sync.username", "someone@foo.com"]);
is(await ASRouterTargeting.Environment.hasFxAccount, true,
Expand Down

0 comments on commit be30a49

Please sign in to comment.