Conflicts:
	src/posts.js
	src/topics.js
This commit is contained in:
psychobunny
2013-05-07 18:29:20 +00:00
9 changed files with 246 additions and 39 deletions

View File

@@ -1,7 +1,8 @@
var RDB = require('./redis.js'),
posts = require('./posts.js'),
utils = require('./utils.js'),
user = require('./user.js')
user = require('./user.js'),
configs = require('../config.js'),
categories = require('./categories.js');
(function(Topics) {
@@ -24,14 +25,18 @@ var RDB = require('./redis.js'),
uid = [],
timestamp = [],
slug = [],
postcount = [];
postcount = [],
locked = [],
deleted = [];
for (var i=0, ii=tids.length; i<ii; i++) {
title.push('tid:' + tids[i] + ':title');
uid.push('tid:' + tids[i] + ':uid');
timestamp.push('tid:' + tids[i] + ':timestamp');
slug.push('tid:' + tids[i] + ':slug');
postcount.push('tid:' + tids[i] + ':postcount');
postcount.push('tid:' + tids[i] + ':postcount'),
locked.push('tid:' + tids[i] + ':locked'),
deleted.push('tid:' + tids[i] + ':deleted');
}
var multi = RDB.multi()
@@ -44,6 +49,8 @@ var RDB = require('./redis.js'),
.mget(timestamp)
.mget(slug)
.mget(postcount)
.mget(locked)
.mget(deleted)
}
@@ -57,9 +64,8 @@ var RDB = require('./redis.js'),
timestamp = replies[3];
slug = replies[4];
postcount = replies[5];
locked = replies[6];
deleted = replies[7];
user.get_usernames_by_uids(uid, function(userNames) {
@@ -72,7 +78,9 @@ var RDB = require('./redis.js'),
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i],
'post_count' : postcount[i]
'post_count' : postcount[i],
'icon': locked[i] === '1' ? 'icon-lock' : 'hide',
'deleted': deleted[i]
});
}
@@ -169,8 +177,71 @@ var RDB = require('./redis.js'),
});
});
};
Topics.lock = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as locked
RDB.set('tid:' + tid + ':locked', 1);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_locked', {
tid: tid,
status: 'ok'
});
}
}
});
}
Topics.unlock = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as locked
RDB.del('tid:' + tid + ':locked');
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_unlocked', {
tid: tid,
status: 'ok'
});
}
}
});
}
Topics.delete = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as deleted
RDB.set('tid:' + tid + ':deleted', 1);
Topics.lock(tid, uid);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
tid: tid,
status: 'ok'
});
}
}
});
}
Topics.restore = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as deleted
RDB.del('tid:' + tid + ':deleted');
Topics.unlock(tid, uid);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
tid: tid,
status: 'ok'
});
}
}
});
}
}(exports));