@ -3,7 +3,13 @@ var RDB = require('./redis.js'),
utils = require ( './utils.js' ) ,
user = require ( './user.js' ) ,
configs = require ( '../config.js' ) ,
categories = require ( './categories.js' ) ;
categories = require ( './categories.js' ) ,
marked = require ( 'marked' )
async = require ( 'async' ) ;
marked . setOptions ( {
breaks : true
} ) ;
( function ( Topics ) {
@ -30,8 +36,6 @@ var RDB = require('./redis.js'),
locked = [ ] ,
deleted = [ ] ,
pinned = [ ] ,
recent _post = [ ] ,
recent _author = [ ] ;
for ( var i = 0 , ii = tids . length ; i < ii ; i ++ ) {
title . push ( 'tid:' + tids [ i ] + ':title' ) ;
@ -42,8 +46,6 @@ var RDB = require('./redis.js'),
locked . push ( 'tid:' + tids [ i ] + ':locked' ) ;
deleted . push ( 'tid:' + tids [ i ] + ':deleted' ) ;
pinned . push ( 'tid:' + tids [ i ] + ':pinned' ) ;
recent _post . push ( 'tid:' + tids [ i ] + ':recent:post' ) ;
recent _author . push ( 'tid:' + tids [ i ] + ':recent:author' ) ;
}
var multi = RDB . multi ( )
@ -60,8 +62,6 @@ var RDB = require('./redis.js'),
. mget ( locked )
. mget ( deleted )
. mget ( pinned )
. mget ( recent _post )
. mget ( recent _author )
}
@ -84,18 +84,17 @@ var RDB = require('./redis.js'),
locked = replies [ 7 ] ;
deleted = replies [ 8 ] ;
pinned = replies [ 9 ] ;
recent _post = replies [ 10 ] ;
recent _author = replies [ 11 ] ;
var usernames ,
has _read ,
moderators ;
moderators ,
teaser _info ;
function generate _topic ( ) {
if ( ! usernames || ! has _read || ! moderators ) return ;
if ( ! usernames || ! has _read || ! moderators || ! teaser _info ) return ;
for ( var i = 0 , ii = title . length ; i < ii ; i ++ ) {
for ( var i = 0 , ii = title . length ; i < ii ; i ++ ) {
console . log ( teaser _info [ i ] ) ;
topics . push ( {
'title' : title [ i ] ,
'uid' : uid [ i ] ,
@ -109,9 +108,10 @@ var RDB = require('./redis.js'),
'pinned' : parseInt ( pinned [ i ] || 0 ) , // For sorting purposes
'pin-icon' : pinned [ i ] === '1' ? 'icon-pushpin' : 'none' ,
'badgeclass' : ( has _read [ i ] && current _user != 0 ) ? '' : 'badge-important' ,
' recent_post' : recent _post [ i ] ,
' recent_author' : recent _author [ i ]
' teaser_text': teaser _info [ i ] . text ,
' teaser_username': teaser _info [ i ] . username
} ) ;
console . log ( teaser _info [ i ] . text , teaser _info [ i ] . username ) ;
}
// Float pinned topics to the top
@ -152,7 +152,12 @@ var RDB = require('./redis.js'),
categories . getModerators ( category _id , function ( mods ) {
moderators = mods ;
generate _topic ( ) ;
} )
} ) ;
Topics . get _teasers ( tids , function ( teasers ) {
teaser _info = teasers ;
generate _topic ( ) ;
} ) ;
}
else {
callback ( {
@ -189,6 +194,42 @@ var RDB = require('./redis.js'),
} ) ;
}
Topics . get _teasers = function ( tids , callback ) {
var requests = [ ] ;
if ( Array . isArray ( tids ) ) {
for ( x = 0 , numTids = tids . length ; x < numTids ; x ++ ) {
( function ( x ) {
requests . push ( function ( next ) {
Topics . get _teaser ( tids [ x ] , function ( teaser _info ) {
next ( null , teaser _info ) ;
} ) ;
} ) ;
} ) ( x ) ;
}
async . parallel ( requests , function ( err , teasers ) {
callback ( teasers ) ;
} ) ;
} else callback ( [ ] ) ;
}
Topics . get _teaser = function ( tid , callback ) {
RDB . lrange ( 'tid:' + tid + ':posts' , - 1 , - 1 , function ( err , pid ) {
if ( pid !== null ) {
RDB . mget ( [
'pid:' + pid + ':content' ,
'pid:' + pid + ':uid'
] , function ( err , content ) {
user . getUserField ( content [ 1 ] , 'username' , function ( username ) {
callback ( {
"text" : utils . strip _tags ( marked ( content [ 0 ] ) ) ,
"username" : username
} ) ;
} ) ;
} ) ;
}
} ) ;
}
Topics . post = function ( socket , uid , title , content , category _id ) {
if ( ! category _id ) throw new Error ( 'Attempted to post without a category_id' ) ;