Skip to content

Commit ca94494

Browse files
committed
Retrieve previous comment statuses from Parse
1 parent b8d9971 commit ca94494

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/background/ghct-background.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as firebase from 'firebase/app'
22
import 'firebase/database'
3+
import * as Parse from 'parse'
34

45
firebase.initializeApp({
56
apiKey: 'AIzaSyBb_2bG5cUaW25MfCdaDP7l5HF8UbF2QR0',
@@ -10,18 +11,35 @@ firebase.initializeApp({
1011
messagingSenderId: '45909398186'
1112
})
1213

14+
Parse.initialize('ghct')
15+
Parse.serverURL = 'https://ghct.herokuapp.com/1'
16+
const parseQuery = new Parse.Query(Parse.Object.extend('CommentTracker'))
17+
const queryParse = (id, callback) => parseQuery.containedIn('commentId', [id]).first().then(callback)
18+
1319
const browser = chrome || browser // eslint-disable-line no-use-before-define
1420

1521
browser.runtime.onConnect.addListener(port => {
1622
const path = 'testing_zone/' + port.name
1723
const ref = firebase.database().ref(path)
1824

19-
const valueListener = snapshot => {
25+
const valueListener = ref.on('value', snapshot => {
2026
const id = snapshot.key
21-
const resolved = !!snapshot.child('resolved').val()
22-
port.postMessage({id, resolved})
23-
}
24-
ref.on('value', valueListener)
27+
const value = snapshot.child('resolved').val()
28+
29+
if (value === null) {
30+
queryParse(id, pValue => {
31+
if (pValue !== undefined) {
32+
if (pValue.attributes.resolved === false || pValue.attributes.resolved === true) {
33+
console.log('p:', pValue, pValue.attributes.resolved)
34+
ref.set(pValue.attributes.resolved)
35+
port.postMessage({id, resolved: pValue.attributes.resolved})
36+
}
37+
}
38+
})
39+
}
40+
41+
port.postMessage({id, resolved: !!value})
42+
})
2543

2644
port.onMessage.addListener(m => {
2745
ref.set(m)

src/background/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"webpack": "^3.0.0"
77
},
88
"dependencies": {
9-
"firebase": "^4.1.3"
9+
"firebase": "^4.1.3",
10+
"parse": "1.6.14"
1011
}
1112
}

src/background/yarn.lock

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ aws4@^1.2.1:
136136
version "1.6.0"
137137
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
138138

139+
babel-runtime@^5.8.20:
140+
version "5.8.38"
141+
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-5.8.38.tgz#1c0b02eb63312f5f087ff20450827b425c9d4c19"
142+
dependencies:
143+
core-js "^1.0.0"
144+
139145
balanced-match@^1.0.0:
140146
version "1.0.0"
141147
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -360,6 +366,10 @@ constants-browserify@^1.0.0:
360366
version "1.0.0"
361367
resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-1.0.0.tgz#c20b96d8c617748aaf1c16021760cd27fcb8cb75"
362368

369+
core-js@^1.0.0:
370+
version "1.2.7"
371+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
372+
363373
core-util-is@~1.0.0:
364374
version "1.0.2"
365375
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -1349,6 +1359,13 @@ parse-json@^2.2.0:
13491359
dependencies:
13501360
error-ex "^1.2.0"
13511361

1362+
parse@1.6.14:
1363+
version "1.6.14"
1364+
resolved "https://registry.yarnpkg.com/parse/-/parse-1.6.14.tgz#a1973823e95b3e1ac146aa554453251b1c0a761d"
1365+
dependencies:
1366+
babel-runtime "^5.8.20"
1367+
xmlhttprequest "^1.7.0"
1368+
13521369
path-browserify@0.0.0:
13531370
version "0.0.0"
13541371
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a"
@@ -1920,7 +1937,7 @@ wrappy@1:
19201937
version "1.0.2"
19211938
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
19221939

1923-
xmlhttprequest@^1.8.0:
1940+
xmlhttprequest@^1.7.0, xmlhttprequest@^1.8.0:
19241941
version "1.8.0"
19251942
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
19261943

0 commit comments

Comments
 (0)