@ -53,21 +53,30 @@ var async = require('async'),
} ) ;
} ) ;
} ;
} ;
Notifications . create = function ( text, path , uniqueId , callback ) {
Notifications . create = function ( data , callback ) {
/ * *
/ * *
* uniqueId is used solely to override stale nids .
* data. uniqueId is used solely to override stale nids .
* If a new nid is pushed to a user and an existing nid in the user ' s
* If a new nid is pushed to a user and an existing nid in the user ' s
* ( un ) read list contains the same uniqueId , it will be removed , and
* ( un ) read list contains the same uniqueId , it will be removed , and
* the new one put in its place .
* the new one put in its place .
* /
* /
// Add default values to data Object if not already set
var defaults = {
text : '' ,
path : null ,
datetime : Date . now ( ) ,
uniqueId : utils . generateUUID ( )
} ;
for ( var v in defaults ) {
if ( defaults . hasOwnProperty ( v ) && ! data [ v ] ) {
data [ v ] = defaults [ v ] ;
}
}
db . incrObjectField ( 'global' , 'nextNid' , function ( err , nid ) {
db . incrObjectField ( 'global' , 'nextNid' , function ( err , nid ) {
db . setAdd ( 'notifications' , nid ) ;
db . setAdd ( 'notifications' , nid ) ;
db . setObject ( 'notifications:' + nid , {
db . setObject ( 'notifications:' + nid , data , function ( err , status ) {
text : text || '' ,
path : path || null ,
datetime : Date . now ( ) ,
uniqueId : uniqueId || utils . generateUUID ( )
} , function ( err , status ) {
if ( ! err ) {
if ( ! err ) {
callback ( nid ) ;
callback ( nid ) ;
}
}
@ -75,18 +84,6 @@ var async = require('async'),
} ) ;
} ) ;
} ;
} ;
function destroy ( nid ) {
db . delete ( 'notifications:' + nid , function ( err , result ) {
db . setRemove ( 'notifications' , nid , function ( err , result ) {
if ( err ) {
winston . error ( 'Problem deleting expired notifications. Stack follows.' ) ;
winston . error ( err . stack ) ;
}
} ) ;
} ) ;
}
Notifications . push = function ( nid , uids , callback ) {
Notifications . push = function ( nid , uids , callback ) {
var websockets = require ( './socket.io' ) ;
var websockets = require ( './socket.io' ) ;
if ( ! Array . isArray ( uids ) ) {
if ( ! Array . isArray ( uids ) ) {