{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/platform-status/pulls/comments/58554249","id":58554249,"diff_hunk":"@@ -0,0 +1,298 @@\n+import redis from '../engine/redis-helper.js';\n+import webPush from 'web-push';\n+\n+const ttl = 2419200;\n+\n+if (!process.env.GCM_API_KEY) {\n+  console.warn('Set the GCM_API_KEY environment variable to support GCM');\n+}\n+webPush.setGCMAPIKey(process.env.GCM_API_KEY);\n+\n+// there is only one client (useful especially while testing)\n+let client;\n+function setClient(dbNumber) {\n+  if (client) {\n+    return Promise.resolve(client);\n+  }\n+  return redis.getClient(dbNumber)\n+  .then(redisClient => {\n+    client = redisClient;\n+    return client;\n+  });\n+}\n+\n+// eported only for test as we will not need to kill database\n+function quitClient(dbNumber) {\n+  return setClient(dbNumber)\n+  .then(() => {\n+    const p = redis.quit(client);\n+    client = null;\n+    return p;\n+  });\n+}\n+\n+// check if such device exists in database, reject if not\n+function checkDeviceId(deviceId, dbNumber) {\n+  return setClient(dbNumber)\n+  .then(() => redis.hgetall(client, `device-${deviceId}`))\n+  .then(device => {\n+    if (!device || !device.endpoint) {\n+      throw new Error('Not Found');\n+    }\n+  });\n+}\n+\n+// get all registrations for a deviceId\n+function getRegisteredFeatures(deviceId, dbNumber) {\n+  return checkDeviceId(deviceId, dbNumber)\n+  .then(() => redis.smembers(client, `${deviceId}-notifications`));\n+}\n+\n+/*\n+ * send confirmation even if deviceId is already deleted\n+ */\n+function sendConfirmation(endpoint, key, deviceId, features, dbNumber) {","path":"engine/notifications.js","position":54,"original_position":54,"commit_id":"36b2bb417a2c49c7d899f1bd6609cb45c6c1d199","original_commit_id":"36b2bb417a2c49c7d899f1bd6609cb45c6c1d199","user":{"login":"zalun","id":97885,"avatar_url":"https://avatars.githubusercontent.com/u/97885?v=3","gravatar_id":"","url":"https://api.github.com/users/zalun","html_url":"https://github.com/zalun","followers_url":"https://api.github.com/users/zalun/followers","following_url":"https://api.github.com/users/zalun/following{/other_user}","gists_url":"https://api.github.com/users/zalun/gists{/gist_id}","starred_url":"https://api.github.com/users/zalun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalun/subscriptions","organizations_url":"https://api.github.com/users/zalun/orgs","repos_url":"https://api.github.com/users/zalun/repos","events_url":"https://api.github.com/users/zalun/events{/privacy}","received_events_url":"https://api.github.com/users/zalun/received_events","type":"User","site_admin":false},"body":"We're using kue - it might even happen on a different device","created_at":"2016-04-05T15:03:25Z","updated_at":"2016-04-05T15:03:25Z","html_url":"https://github.com/mozilla/platform-status/pull/317#discussion_r58554249","pull_request_url":"https://api.github.com/repos/mozilla/platform-status/pulls/317","_links":{"self":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/comments/58554249"},"html":{"href":"https://github.com/mozilla/platform-status/pull/317#discussion_r58554249"},"pull_request":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/317"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/platform-status/pulls/317","id":59057144,"html_url":"https://github.com/mozilla/platform-status/pull/317","diff_url":"https://github.com/mozilla/platform-status/pull/317.diff","patch_url":"https://github.com/mozilla/platform-status/pull/317.patch","issue_url":"https://api.github.com/repos/mozilla/platform-status/issues/317","number":317,"state":"open","locked":false,"title":"Notifications - first stage","user":{"login":"zalun","id":97885,"avatar_url":"https://avatars.githubusercontent.com/u/97885?v=3","gravatar_id":"","url":"https://api.github.com/users/zalun","html_url":"https://github.com/zalun","followers_url":"https://api.github.com/users/zalun/followers","following_url":"https://api.github.com/users/zalun/following{/other_user}","gists_url":"https://api.github.com/users/zalun/gists{/gist_id}","starred_url":"https://api.github.com/users/zalun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalun/subscriptions","organizations_url":"https://api.github.com/users/zalun/orgs","repos_url":"https://api.github.com/users/zalun/repos","events_url":"https://api.github.com/users/zalun/events{/privacy}","received_events_url":"https://api.github.com/users/zalun/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-11T16:35:58Z","updated_at":"2016-04-05T15:03:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6790971b115f579ff7797c7f556cc3ffaf60c9e0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/platform-status/pulls/317/commits","review_comments_url":"https://api.github.com/repos/mozilla/platform-status/pulls/317/comments","review_comment_url":"https://api.github.com/repos/mozilla/platform-status/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/platform-status/issues/317/comments","statuses_url":"https://api.github.com/repos/mozilla/platform-status/statuses/36b2bb417a2c49c7d899f1bd6609cb45c6c1d199","head":{"label":"zalun:notifications","ref":"notifications","sha":"36b2bb417a2c49c7d899f1bd6609cb45c6c1d199","user":{"login":"zalun","id":97885,"avatar_url":"https://avatars.githubusercontent.com/u/97885?v=3","gravatar_id":"","url":"https://api.github.com/users/zalun","html_url":"https://github.com/zalun","followers_url":"https://api.github.com/users/zalun/followers","following_url":"https://api.github.com/users/zalun/following{/other_user}","gists_url":"https://api.github.com/users/zalun/gists{/gist_id}","starred_url":"https://api.github.com/users/zalun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalun/subscriptions","organizations_url":"https://api.github.com/users/zalun/orgs","repos_url":"https://api.github.com/users/zalun/repos","events_url":"https://api.github.com/users/zalun/events{/privacy}","received_events_url":"https://api.github.com/users/zalun/received_events","type":"User","site_admin":false},"repo":{"id":44379964,"name":"platatus","full_name":"zalun/platatus","owner":{"login":"zalun","id":97885,"avatar_url":"https://avatars.githubusercontent.com/u/97885?v=3","gravatar_id":"","url":"https://api.github.com/users/zalun","html_url":"https://github.com/zalun","followers_url":"https://api.github.com/users/zalun/followers","following_url":"https://api.github.com/users/zalun/following{/other_user}","gists_url":"https://api.github.com/users/zalun/gists{/gist_id}","starred_url":"https://api.github.com/users/zalun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalun/subscriptions","organizations_url":"https://api.github.com/users/zalun/orgs","repos_url":"https://api.github.com/users/zalun/repos","events_url":"https://api.github.com/users/zalun/events{/privacy}","received_events_url":"https://api.github.com/users/zalun/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zalun/platatus","description":"Project Platform Status","fork":true,"url":"https://api.github.com/repos/zalun/platatus","forks_url":"https://api.github.com/repos/zalun/platatus/forks","keys_url":"https://api.github.com/repos/zalun/platatus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalun/platatus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalun/platatus/teams","hooks_url":"https://api.github.com/repos/zalun/platatus/hooks","issue_events_url":"https://api.github.com/repos/zalun/platatus/issues/events{/number}","events_url":"https://api.github.com/repos/zalun/platatus/events","assignees_url":"https://api.github.com/repos/zalun/platatus/assignees{/user}","branches_url":"https://api.github.com/repos/zalun/platatus/branches{/branch}","tags_url":"https://api.github.com/repos/zalun/platatus/tags","blobs_url":"https://api.github.com/repos/zalun/platatus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalun/platatus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalun/platatus/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalun/platatus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalun/platatus/statuses/{sha}","languages_url":"https://api.github.com/repos/zalun/platatus/languages","stargazers_url":"https://api.github.com/repos/zalun/platatus/stargazers","contributors_url":"https://api.github.com/repos/zalun/platatus/contributors","subscribers_url":"https://api.github.com/repos/zalun/platatus/subscribers","subscription_url":"https://api.github.com/repos/zalun/platatus/subscription","commits_url":"https://api.github.com/repos/zalun/platatus/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalun/platatus/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalun/platatus/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalun/platatus/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalun/platatus/contents/{+path}","compare_url":"https://api.github.com/repos/zalun/platatus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalun/platatus/merges","archive_url":"https://api.github.com/repos/zalun/platatus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalun/platatus/downloads","issues_url":"https://api.github.com/repos/zalun/platatus/issues{/number}","pulls_url":"https://api.github.com/repos/zalun/platatus/pulls{/number}","milestones_url":"https://api.github.com/repos/zalun/platatus/milestones{/number}","notifications_url":"https://api.github.com/repos/zalun/platatus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalun/platatus/labels{/name}","releases_url":"https://api.github.com/repos/zalun/platatus/releases{/id}","deployments_url":"https://api.github.com/repos/zalun/platatus/deployments","created_at":"2015-10-16T11:07:19Z","updated_at":"2016-02-03T17:13:26Z","pushed_at":"2016-04-05T13:11:26Z","git_url":"git://github.com/zalun/platatus.git","ssh_url":"git@github.com:zalun/platatus.git","clone_url":"https://github.com/zalun/platatus.git","svn_url":"https://github.com/zalun/platatus","homepage":"https://mozilla.github.io/platatus/","size":1627,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"46ca62f6d749ad8383dac741c72ebdba8085d312","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":43447626,"name":"platform-status","full_name":"mozilla/platform-status","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/platform-status","description":"Project Platform Status","fork":false,"url":"https://api.github.com/repos/mozilla/platform-status","forks_url":"https://api.github.com/repos/mozilla/platform-status/forks","keys_url":"https://api.github.com/repos/mozilla/platform-status/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/platform-status/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/platform-status/teams","hooks_url":"https://api.github.com/repos/mozilla/platform-status/hooks","issue_events_url":"https://api.github.com/repos/mozilla/platform-status/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/platform-status/events","assignees_url":"https://api.github.com/repos/mozilla/platform-status/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/platform-status/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/platform-status/tags","blobs_url":"https://api.github.com/repos/mozilla/platform-status/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/platform-status/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/platform-status/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/platform-status/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/platform-status/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/platform-status/languages","stargazers_url":"https://api.github.com/repos/mozilla/platform-status/stargazers","contributors_url":"https://api.github.com/repos/mozilla/platform-status/contributors","subscribers_url":"https://api.github.com/repos/mozilla/platform-status/subscribers","subscription_url":"https://api.github.com/repos/mozilla/platform-status/subscription","commits_url":"https://api.github.com/repos/mozilla/platform-status/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/platform-status/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/platform-status/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/platform-status/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/platform-status/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/platform-status/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/platform-status/merges","archive_url":"https://api.github.com/repos/mozilla/platform-status/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/platform-status/downloads","issues_url":"https://api.github.com/repos/mozilla/platform-status/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/platform-status/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/platform-status/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/platform-status/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/platform-status/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/platform-status/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/platform-status/deployments","created_at":"2015-09-30T17:25:18Z","updated_at":"2016-04-04T13:14:10Z","pushed_at":"2016-04-05T14:01:44Z","git_url":"git://github.com/mozilla/platform-status.git","ssh_url":"git@github.com:mozilla/platform-status.git","clone_url":"https://github.com/mozilla/platform-status.git","svn_url":"https://github.com/mozilla/platform-status","homepage":"https://platform-status.mozilla.org/","size":1661,"stargazers_count":90,"watchers_count":90,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":23,"mirror_url":null,"open_issues_count":37,"forks":23,"open_issues":37,"watchers":90,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/317"},"html":{"href":"https://github.com/mozilla/platform-status/pull/317"},"issue":{"href":"https://api.github.com/repos/mozilla/platform-status/issues/317"},"comments":{"href":"https://api.github.com/repos/mozilla/platform-status/issues/317/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/317/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/platform-status/pulls/317/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/platform-status/statuses/36b2bb417a2c49c7d899f1bd6609cb45c6c1d199"}}}}