2015-02-21 20:35:25 -08:00
|
|
|
var _ = require('lodash');
|
2015-02-11 11:03:26 -08:00
|
|
|
var Uuid = require('uuid');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* notifications examples
|
|
|
|
*
|
2015-02-11 18:11:30 -08:00
|
|
|
* NewCopayer -
|
|
|
|
* NewAddress -
|
|
|
|
* NewTxProposal - (amount)
|
|
|
|
* TxProposalAcceptedBy - (txProposalId, copayerId)
|
|
|
|
* TxProposalRejectedBy - (txProposalId, copayerId)
|
|
|
|
* txProposalFinallyRejected - txProposalId
|
|
|
|
* txProposalFinallyAccepted - txProposalId
|
|
|
|
*
|
2015-03-30 13:22:45 -07:00
|
|
|
* NewIncomingTx (address, txid)
|
2015-03-30 12:57:55 -07:00
|
|
|
* NewOutgoingTx - (txProposalId, txid)
|
2015-02-11 11:03:26 -08:00
|
|
|
*
|
|
|
|
* data Examples:
|
|
|
|
* { amount: 'xxx', address: 'xxx'}
|
|
|
|
* { txProposalId: 'xxx', copayerId: 'xxx' }
|
2015-02-11 18:11:30 -08:00
|
|
|
*
|
2015-02-17 16:20:08 -08:00
|
|
|
* Data is meant to provide only the needed information
|
|
|
|
* to notify the user
|
2015-02-11 18:11:30 -08:00
|
|
|
*
|
2015-02-11 11:03:26 -08:00
|
|
|
*/
|
2015-08-27 06:47:32 -07:00
|
|
|
function Notification() {};
|
2015-02-11 11:03:26 -08:00
|
|
|
|
2015-02-17 16:20:08 -08:00
|
|
|
Notification.create = function(opts) {
|
2015-02-11 11:03:26 -08:00
|
|
|
opts = opts || {};
|
|
|
|
|
2015-02-17 16:20:08 -08:00
|
|
|
var x = new Notification();
|
|
|
|
|
2015-08-27 06:47:32 -07:00
|
|
|
x.version = '1.0.0';
|
2015-02-12 05:26:13 -08:00
|
|
|
var now = Date.now();
|
2015-10-15 11:14:29 -07:00
|
|
|
|
2015-02-17 16:20:08 -08:00
|
|
|
x.createdOn = Math.floor(now / 1000);
|
2015-02-21 20:35:25 -08:00
|
|
|
x.id = _.padLeft(now, 14, '0') + _.padLeft(opts.ticker || 0, 4, '0');
|
2015-02-17 16:20:08 -08:00
|
|
|
x.type = opts.type || 'general';
|
|
|
|
x.data = opts.data;
|
2015-03-30 07:24:33 -07:00
|
|
|
x.walletId = opts.walletId;
|
2015-03-24 08:46:54 -07:00
|
|
|
x.creatorId = opts.creatorId;
|
2015-02-17 16:20:08 -08:00
|
|
|
|
|
|
|
return x;
|
2015-02-11 11:03:26 -08:00
|
|
|
};
|
|
|
|
|
2015-02-12 05:26:13 -08:00
|
|
|
Notification.fromObj = function(obj) {
|
2015-02-17 16:20:08 -08:00
|
|
|
var x = new Notification();
|
2015-02-11 11:03:26 -08:00
|
|
|
|
2015-08-27 06:47:32 -07:00
|
|
|
x.version = obj.version;
|
2015-02-11 11:03:26 -08:00
|
|
|
x.createdOn = obj.createdOn;
|
2015-02-17 16:20:08 -08:00
|
|
|
x.id = obj.id;
|
2015-02-11 11:03:26 -08:00
|
|
|
x.type = obj.type,
|
2015-02-12 05:26:13 -08:00
|
|
|
x.data = obj.data;
|
2015-03-30 07:24:33 -07:00
|
|
|
x.walletId = obj.walletId;
|
2015-03-24 08:46:54 -07:00
|
|
|
x.creatorId = obj.creatorId;
|
2015-02-11 11:03:26 -08:00
|
|
|
|
|
|
|
return x;
|
|
|
|
};
|
|
|
|
|
2015-02-11 18:11:30 -08:00
|
|
|
module.exports = Notification;
|