forked from sunnypatel165/flockSO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher_test.html
52 lines (41 loc) · 1.14 KB
/
watcher_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<html>
<head>
<script>
var watcher = {};
var url = 'https://api.stackexchange.com/2.2/';
var questionAnswerUrlAppend = '?site=stackoverflow';
function addWatcher(userId, questionId) {
watcher[[userId, questionId]] = getLastActivityTime(questionId);
}
function getLastActivityTime(questionId) {
var questionUrl = url + '/questions/' + questionId + questionAnswerUrlAppend;
client.registerMethod("jsonMethod", questionUrl, "GET");
client.methods.jsonMethod(function (data, response) {
var lastActivityDate = data.items[0].last_activity_date;
console.log("Last Activity Date - " + lastActivityDate);
});
}
function startWatcher() {
while(true){
sleep(5000, checkForUpdates);
}
}
function checkForUpdates() {
for(toWatchObj in watcher){
currentTime = watcher[toWatchObj];
var questionId = toWatchObj[0];
var newTime = getLastActivityTime(questionId);
if (newTime > currentTime){
//send via bot and update the time in map
watcher[questionId] = newTime;
}
}
}
function sleep(millis, callback) {
setTimeout(function()
{ callback(); }
, milliseconds);
}
</script>
</head>
</html>