@ -15,29 +15,22 @@ var RDB = require('./redis.js'),
} ) ;
} ) ;
} ) ;
} ) ;
} ,
} ,
create : function ( text , score , path , uniqueId , callback ) {
create : function ( text , path , uniqueId , callback ) {
/ *
/ * *
* Score guide :
* 0 Low priority messages ( probably unused )
* 5 Normal messages
* 10 High priority messages
*
* uniqueId is used solely to override stale nids .
* 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 .
* /
* /
RDB . incr ( 'notifications:next_nid' , function ( err , nid ) {
RDB . incr ( 'notifications:next_nid' , function ( err , nid ) {
RDB . hmset (
RDB . hmset ( 'notifications:' + nid , {
'notifications:' + nid ,
text : text || '' ,
'text' , text || '' ,
path : path || null ,
'score' , score || 5 ,
datetime : Date . now ( ) ,
'path' , path || null ,
uniqueId : uniqueId || utils . generateUUID ( )
'datetime' , Date . now ( ) ,
} , function ( err , status ) {
'uniqueId' , uniqueId || utils . generateUUID ( ) ,
if ( ! err ) callback ( nid ) ;
function ( err , status ) {
} ) ;
if ( status === 'OK' ) callback ( nid ) ;
} ) ;
} ) ;
} ) ;
} ,
} ,
push : function ( nid , uids , callback ) {
push : function ( nid , uids , callback ) {
@ -51,8 +44,8 @@ var RDB = require('./redis.js'),
if ( parseInt ( uids [ x ] ) > 0 ) {
if ( parseInt ( uids [ x ] ) > 0 ) {
( function ( uid ) {
( function ( uid ) {
notifications . remove _by _uniqueId ( notif _data . uniqueId , uid , function ( ) {
notifications . remove _by _uniqueId ( notif _data . uniqueId , uid , function ( ) {
RDB . zadd ( 'uid:' + uid + ':notifications:unread' , notif _data . scor e, nid ) ;
RDB . zadd ( 'uid:' + uid + ':notifications:unread' , notif _data . datetim e, nid ) ;
global . io . sockets . in ( 'uid_' + uid ) . emit ( 'event:new_notification' ) ;
global . io . sockets . in ( 'uid_' + uid ) . emit ( 'event:new_notification' ) ;
if ( callback ) callback ( true ) ;
if ( callback ) callback ( true ) ;
} ) ;
} ) ;
} ) ( uids [ x ] ) ;
} ) ( uids [ x ] ) ;
@ -98,7 +91,7 @@ var RDB = require('./redis.js'),
if ( parseInt ( uid ) > 0 ) {
if ( parseInt ( uid ) > 0 ) {
notifications . get ( nid , function ( notif _data ) {
notifications . get ( nid , function ( notif _data ) {
RDB . zrem ( 'uid:' + uid + ':notifications:unread' , nid ) ;
RDB . zrem ( 'uid:' + uid + ':notifications:unread' , nid ) ;
RDB . zadd ( 'uid:' + uid + ':notifications:read' , notif _data . scor e, nid ) ;
RDB . zadd ( 'uid:' + uid + ':notifications:read' , notif _data . datetim e, nid ) ;
if ( callback ) callback ( ) ;
if ( callback ) callback ( ) ;
} ) ;
} ) ;
}
}