@ -87,13 +87,15 @@ marked.setOptions({
var usernames ,
has _read ,
moderators ,
teaser _info ;
teaser _info ,
privileges ;
function generate _topic ( ) {
if ( ! usernames || ! has _read || ! moderators || ! teaser _info ) return ;
if ( ! usernames || ! has _read || ! moderators || ! teaser _info || ! privileges ) return ;
if ( tids . length > 0 ) {
for ( var i = 0 , ii = title . length ; i < ii ; i ++ ) {
if ( ! deleted [ i ] || ( deleted [ i ] && privileges . view _deleted ) || uid [ i ] === current _user ) {
topics . push ( {
'title' : title [ i ] ,
'uid' : uid [ i ] ,
@ -104,6 +106,7 @@ marked.setOptions({
'post_count' : postcount [ i ] ,
'lock-icon' : locked [ i ] === '1' ? 'icon-lock' : 'none' ,
'deleted' : deleted [ i ] ,
'deleted-class' : deleted [ i ] ? 'deleted' : '' ,
'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' ,
@ -112,6 +115,7 @@ marked.setOptions({
} ) ;
}
}
}
// Float pinned topics to the top
topics = topics . sort ( function ( a , b ) {
@ -157,39 +161,33 @@ marked.setOptions({
teaser _info = teasers ;
generate _topic ( ) ;
} ) ;
// else {
// callback({
// 'category_name' : category_id ? category_name : 'Recent',
// 'show_topic_button' : category_id ? 'show' : 'hidden',
// 'category_id': category_id || 0,
// 'topics': []
// });
// }
categories . privileges ( category _id , current _user , function ( user _privs ) {
privileges = user _privs ;
} ) ;
} ) ;
} ) ;
}
Topics . editable = function ( tid , uid , callback ) {
Topics . privileges = function ( tid , uid , callback ) {
async . parallel ( [
function ( next ) {
user . getUserField ( uid , 'reputation' , function ( reputation ) {
next ( null , reputation >= config . privilege _thresholds . manage _thread ) ;
} ) ;
} ,
function ( next ) {
Topics . get _cid _by _tid ( tid , function ( cid ) {
user. isModerator ( uid , cid , function ( isMod ) {
next ( null , isMod ) ;
categories . privileges ( cid , uid , function ( privileges ) {
next ( null , privileges ) ;
} ) ;
} ) ;
} , function ( next ) {
user . isAdministrator ( uid , function ( isAdmin ) {
next ( null , isAdmin ) ;
} ,
function ( next ) {
user . getUserField ( uid , 'reputation' , function ( reputation ) {
next ( null , reputation >= config . privilege _thresholds . manage _thread ) ;
} ) ;
}
] , function ( err , results ) {
// If any return true, allow the edit
if ( results . indexOf ( true ) !== - 1 ) callback ( true ) ;
callback ( {
editable : results [ 0 ] . editable || ( results . slice ( 1 ) . indexOf ( true ) !== - 1 ? true : false ) ,
view _deleted : results [ 0 ] . view _deleted || ( results . slice ( 1 ) . indexOf ( true ) !== - 1 ? true : false )
} ) ;
} ) ;
}
@ -383,8 +381,8 @@ marked.setOptions({
} ;
Topics . lock = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as locked
RDB . set ( 'tid:' + tid + ':locked' , 1 ) ;
@ -399,8 +397,8 @@ marked.setOptions({
}
Topics . unlock = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as unlocked
RDB . del ( 'tid:' + tid + ':locked' ) ;
@ -415,8 +413,8 @@ marked.setOptions({
}
Topics . delete = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as deleted
RDB . set ( 'tid:' + tid + ':deleted' , 1 ) ;
Topics . lock ( tid , uid ) ;
@ -432,8 +430,8 @@ marked.setOptions({
}
Topics . restore = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as restored
RDB . del ( 'tid:' + tid + ':deleted' ) ;
Topics . unlock ( tid , uid ) ;
@ -449,8 +447,8 @@ marked.setOptions({
}
Topics . pin = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as pinned
RDB . set ( 'tid:' + tid + ':pinned' , 1 ) ;
@ -465,8 +463,8 @@ marked.setOptions({
}
Topics . unpin = function ( tid , uid , socket ) {
Topics . editable( tid , uid , function ( editable ) {
if ( editable) {
Topics . privileges( tid , uid , function ( privileges ) {
if ( privileges. editable) {
// Mark thread as unpinned
RDB . del ( 'tid:' + tid + ':pinned' ) ;