This commit is contained in:
Gabriel Bazán 2016-01-04 15:56:14 -03:00
parent b193685b41
commit b7f98bb752
2 changed files with 14 additions and 12 deletions

View File

@ -49,11 +49,14 @@ var PUSHNOTIFICATIONS_TYPES = {
function PushNotificationsService() {};
PushNotificationsService.prototype.start = function(opts, cb) {
opts = opts || {};
var self = this;
async.parallel([
function(done) {
self.messageBroker = opts.messageBroker || new MessageBroker(opts.messageBrokerOpts);
self.messageBroker.onMessage(_.bind(self.sendPushNotification, self));
self.messageBroker.onMessage(_.bind(self.sendPushNotifications, self));
done();
},
], function(err) {
@ -66,8 +69,8 @@ PushNotificationsService.prototype.start = function(opts, cb) {
PushNotificationsService.prototype.sendPushNotifications = function(notification, cb) {
console.log(notification);
if (PUSHNOTIFICATIONS_TYPES[notification.type] == notification.type) {
if (PUSHNOTIFICATIONS_TYPES[notification.type]) {
if (notification.type == 'NewIncomingTx') {
var opts = {};
opts.users = [notification.walletId];
@ -112,13 +115,13 @@ PushNotificationsService.prototype.sendPushNotifications = function(notification
// }
// };
// }
if (notification.type == ' NewTxProposal') {
if (notification.type == 'NewTxProposal') {
var opts = {};
opts.users = [notification.walletId];
opts.android = {
"collapseKey": "optional",
"data": {
"title": "New proposal"
"title": "New proposal",
"message": "New transaction proposal created"
}
};
@ -129,30 +132,29 @@ PushNotificationsService.prototype.sendPushNotifications = function(notification
opts.android = {
"collapseKey": "optional",
"data": {
"title": "Rejected"
"title": "Rejected",
"message": "Transaction proposal finally rejected"
}
};
}
if (notification.type == ' TxProposalAcceptedBy') {
if (notification.type == 'TxProposalAcceptedBy') {
var opts = {};
opts.users = [notification.walletId];
opts.android = {
"collapseKey": "optional",
"data": {
"title": "Accepted"
"title": "Accepted",
"message": "Transaction proposal accepted"
}
};
}
var url = 'http://192.168.1.126:8000/send';
var url = 'http://192.168.1.121:8000/send';
request({
url: url,
method: 'POST',
json: true,
body: opts
}, function(error, response, body) {
console.log(error);
console.log(response.statusCode);
});
}

View File

@ -7,10 +7,10 @@ var log = require('npmlog');
log.debug = log.verbose;
var config = require('../config');
var PushNotificationService = require('../lib/pushnotificationsservice');
var PushNotificationsService = require('../lib/pushnotificationsservice');
var PushNotificationsService = new PushNotificationsService();
PushNotificationsService.start(config, function(err) {
var pushNotificationsService = new PushNotificationsService();
pushNotificationsService.start(config, function(err) {
if (err) throw err;
console.log('Push Notification Service started');