-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainView.js
More file actions
55 lines (47 loc) · 1.72 KB
/
MainView.js
File metadata and controls
55 lines (47 loc) · 1.72 KB
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
53
54
55
const Observable = require('FuseJS/Observable');
var Model = require("UserData");
var Share = require("FuseJS/Share");
var Timer = require("FuseJS/Timer");
var Model = require("UserData");
var LocalNotify = require("LocalNotify");
var motivationUpdateTimer = null;
LocalNotify.on("receivedMessage", function(payload, fromNotifBar) {
if ( fromNotifBar == true ) {
router.push("navFrontPage");
router.push("navNotificationArchivePage");
}
});
function postProcessMotivationalMessages(responseObj) {
var final_response = [];
for ( i=0 ; i < responseObj.length; i++ ) {
var temp_object = {};
temp_object['title'] = responseObj[i].title;
temp_object['message'] = responseObj[i].message;
final_response[i] = temp_object;
}
return final_response;
}
function getMotivationUpdates() {
var status = 0;
var response_ok = false;
fetch('http://citengam.com/slutta-messages.json', {
method: 'GET'
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
return response.json(); // This returns a promise
}).then(function(responseObject) {
// Do something with the result
var userData = Model.getUserData();
userData["dailyNotifications"].value = postProcessMotivationalMessages(responseObject);
}).catch(function(err) {
// An error occurred somewhere in the Promise chain
});
if (motivationUpdateTimer == null) {
// motivationUpdateTimer = Timer.create(getMotivationUpdates, 10000, true);
}
}
getMotivationUpdates();
module.exports = {
getMotivationUpdates: getMotivationUpdates
};