diff --git a/lib/pushnotificationsservice.js b/lib/pushnotificationsservice.js index b1c3d7b..f199847 100644 --- a/lib/pushnotificationsservice.js +++ b/lib/pushnotificationsservice.js @@ -1,48 +1,47 @@ 'use strict'; -var _ = require('lodash'); -var $ = require('preconditions').singleton(); var async = require('async'); -var Mustache = require('mustache'); var log = require('npmlog'); log.debug = log.verbose; -var fs = require('fs'); -var path = require('path'); -var nodemailer = require('nodemailer'); var request = require('request'); - -var Utils = require('./common/utils'); -var Storage = require('./storage'); var MessageBroker = require('./messagebroker'); -var Lock = require('./lock'); -var BlockchainExplorer = require('./blockchainexplorer'); - -var Model = require('./model'); var PUSHNOTIFICATIONS_TYPES = { 'NewCopayer': { - filename: 'new_copayer', - notifyDoer: false, + title: "New copayer", + message: function(notification) { + return ("Copayer: " + notification.data.copayerName + " has joined!"); + }; }, 'WalletComplete': { - filename: 'wallet_complete', - notifyDoer: true, + title: "Wallet complete", + message: function(notification) { + return ("All copayers has joined!"); + }; }, 'NewTxProposal': { - filename: 'new_tx_proposal', - notifyDoer: false, + title: "New proposal", + message: function(notification) { + return ("New transaction proposal created"); + }; }, 'NewOutgoingTx': { - filename: 'new_outgoing_tx', - notifyDoer: true, + title: "New outgoing transaction", + message: function(notification) { + return ((notification.data.amount / 100) + " bits"); + }; }, 'NewIncomingTx': { - filename: 'new_incoming_tx', - notifyDoer: true, + title: "New incoming transaction", + message: function(notification) { + return ((notification.data.amount / 100) + " bits"); + }; }, 'TxProposalFinallyRejected': { - filename: 'txp_finally_rejected', - notifyDoer: false, + title: "Rejected", + message: function(notification) { + return ("Transaction proposal finally rejected"); + }; }, }; @@ -68,96 +67,29 @@ PushNotificationsService.prototype.start = function(opts, cb) { }; PushNotificationsService.prototype.sendPushNotifications = function(notification, cb) { - console.log(notification); + log.debug(notification); - if (PUSHNOTIFICATIONS_TYPES[notification.type]) { - if (notification.type == 'NewIncomingTx') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "New incoming transaction", - "message": notification.data.amount / 100 + " bits" - } - }; + if (!PUSHNOTIFICATIONS_TYPES[notification.type]) return; + + var opts = {}; + opts.users = [notification.walletId]; + opts.android = { + "data": { + "title": PUSHNOTIFICATIONS_TYPES[notification.type].title, + "message": PUSHNOTIFICATIONS_TYPES[notification.type].message(notification) } - if (notification.type == 'NewOutgoingTx') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "New outgoing transaction", - "message": notification.data.amount / 100 + " bits" - } - }; - } - if (notification.type == 'NewCopayer') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "New copayer", - "message": "Copayer: " + notification.data.copayerName + " has joined" - } - }; - } - // if (notification.type == 'WalletComplete') { - // var opts = {}; - // opts.users = [notification.walletId]; - // opts.android = { - // "collapseKey": "optional", - // "data": { - // "title": "Wallet complete", - // "message": "Wallet complete" - // } - // }; - // } - if (notification.type == 'NewTxProposal') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "New proposal", - "message": "New transaction proposal created" - } - }; - } - if (notification.type == 'TxProposalFinallyRejected') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "Rejected", - "message": "Transaction proposal finally rejected" - } - }; - } - if (notification.type == 'TxProposalAcceptedBy') { - var opts = {}; - opts.users = [notification.walletId]; - opts.android = { - "collapseKey": "optional", - "data": { - "title": "Accepted", - "message": "Transaction proposal accepted" - } - }; - } - var url = 'http://192.168.1.121:8000/send'; - request({ - url: url, - method: 'POST', - json: true, - body: opts - }, function(error, response, body) { - console.log(response.statusCode); - }); - } + }; + + var url = 'http://192.168.1.121:8000/send'; + request({ + url: url, + method: 'POST', + json: true, + body: opts + }, function(error, response, body) { + log.debug(response.statusCode); + }); +} }; module.exports = PushNotificationsService; diff --git a/pushnotificationsservice/pushnotificationsservice.js b/pushnotificationsservice/pushnotificationsservice.js index f2359e7..b0acaeb 100644 --- a/pushnotificationsservice/pushnotificationsservice.js +++ b/pushnotificationsservice/pushnotificationsservice.js @@ -2,7 +2,6 @@ 'use strict'; -var _ = require('lodash'); var log = require('npmlog'); log.debug = log.verbose;