@ -17,7 +17,7 @@ var RDB = require('./redis.js'),
//compile thread after all data is asynchronously called
function generateThread ( ) {
if ( ! post _data || ! user _data || ! thread _data || ! vote _data || ! viewer _data ) return ;
if ( ! post _data || ! user _data || ! thread _data || ! vote _data || ! viewer _data ) return ;
var posts = [ ] ;
@ -36,7 +36,10 @@ var RDB = require('./redis.js'),
'user_rep' : user _data [ uid ] . reputation || 0 ,
'gravatar' : user _data [ uid ] . picture ,
'fav_star_class' : vote _data [ pid ] ? 'icon-star' : 'icon-star-empty' ,
'display_moderator_tools' : uid == current _user ? 'show' : 'none'
'display_moderator_tools' : uid == current _user ? 'show' : 'none' ,
'edited-class' : post _data . editor [ i ] !== null ? '' : 'none' ,
'editor' : post _data . editor [ i ] !== null ? user _data [ post _data . editor [ i ] ] . username : '' ,
'relativeEditTime' : post _data . editTime !== null ? utils . relativeTime ( post _data . editTime [ i ] ) : ''
} ) ;
}
@ -58,13 +61,15 @@ var RDB = require('./redis.js'),
RDB . lrange ( 'tid:' + tid + ':posts' , start , end , function ( err , pids ) {
RDB . handle ( err ) ;
var content = [ ] , uid = [ ] , timestamp = [ ] , pid = [ ] , post _rep = [ ] ;
var content = [ ] , uid = [ ] , timestamp = [ ] , pid = [ ] , post _rep = [ ] , editor = [ ] , editTime = [ ] ;
for ( var i = 0 , ii = pids . length ; i < ii ; i ++ ) {
content . push ( 'pid:' + pids [ i ] + ':content' ) ;
uid . push ( 'pid:' + pids [ i ] + ':uid' ) ;
timestamp . push ( 'pid:' + pids [ i ] + ':timestamp' ) ;
post _rep . push ( 'pid:' + pids [ i ] + ':rep' ) ;
post _rep . push ( 'pid:' + pids [ i ] + ':rep' ) ;
editor . push ( 'pid:' + pids [ i ] + ':editor' ) ;
editTime . push ( 'pid:' + pids [ i ] + ':edited' ) ;
pid . push ( pids [ i ] ) ;
}
@ -84,13 +89,17 @@ var RDB = require('./redis.js'),
. get ( 'tid:' + tid + ':category_slug' )
. get ( 'tid:' + tid + ':deleted' )
. get ( 'tid:' + tid + ':pinned' )
. mget ( editor )
. mget ( editTime )
. exec ( function ( err , replies ) {
post _data = {
pid : pids ,
content : replies [ 0 ] ,
uid : replies [ 1 ] ,
timestamp : replies [ 2 ] ,
reputation : replies [ 3 ]
reputation : replies [ 3 ] ,
editor : replies [ 10 ] ,
editTime : replies [ 11 ]
} ;
thread _data = {
@ -102,6 +111,13 @@ var RDB = require('./redis.js'),
pinned : replies [ 9 ] || 0
} ;
// Add any editors to the user_data object
for ( var x = 0 , numPosts = replies [ 10 ] . length ; x < numPosts ; x ++ ) {
if ( replies [ 10 ] [ x ] !== null && post _data . uid . indexOf ( replies [ 10 ] [ x ] ) === - 1 ) {
post _data . uid . push ( replies [ 10 ] [ x ] ) ;
}
}
user . getMultipleUserFields ( post _data . uid , [ 'username' , 'reputation' , 'picture' ] , function ( user _details ) {
user _data = user _details ;
generateThread ( ) ;
@ -268,9 +284,12 @@ var RDB = require('./redis.js'),
} ) ;
}
Posts . edit = function ( pid, content ) {
Posts . edit = function ( uid, pid, content ) {
RDB . get ( 'pid:' + pid + ':tid' , function ( err , tid ) {
RDB . set ( 'pid:' + pid + ':content' , content ) ;
RDB . set ( 'pid:' + pid + ':edited' , new Date ( ) . getTime ( ) ) ;
RDB . set ( 'pid:' + pid + ':editor' , uid ) ;
io . sockets . in ( 'topic_' + tid ) . emit ( 'event:post_edited' , { pid : pid , content : marked ( content || '' ) } ) ;
} ) ;
}