Skip to content

Node.js based forum software built for the modern web

Merge branch 'master' of https://github.com/psychobunny/NodeBB

psychobunny2dccfb96e74e
diff --cc src/posts.js
index 7538cad7ca,6683ed6307..c16b7cb770
--- a/src/posts.js
+++ b/src/posts.js
@@@ -39,10 -40,10 +40,12 @@@ var RDB = require('./redis.js')
callback({
'topic_name':thread_data.topic_name,
+ 'category_name':thread_data.category_name,
+ 'category_slug':thread_data.category_slug,
'locked': parseInt(thread_data.locked) || 0,
+ 'deleted': parseInt(thread_data.deleted) || 0,
'topic_id': tid,
+ 'expose_tools': viewer_data.reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
'posts': posts
});
}
@@@ -74,8 -79,7 +77,9 @@@
.mget(post_rep)
.get('tid:' + tid + ':title')
.get('tid:' + tid + ':locked')
+ .get('tid:' + tid + ':category_name')
+ .get('tid:' + tid + ':category_slug')
+ .get('tid:' + tid + ':deleted')
.exec(function(err, replies) {
post_data = {
pid: pids,
@@@ -87,9 -91,8 +91,10 @@@
thread_data = {
topic_name: replies[4],
- locked: replies[5] || 0,
- deleted: replies[6] || 0
+ locked: replies[5],
+ category_name: replies[6],
- category_slug: replies[7]
++ category_slug: replies[7],
++ deleted: replies[8] || 0
};
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
diff --cc src/topics.js
index e43b32e67d,a71103efcc..7fc94354d2
--- a/src/topics.js
+++ b/src/topics.js
@@@ -1,8 -1,8 +1,9 @@@
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');
++ configs = require('../config.js'),
+ categories = require('./categories.js');
(function(Topics) {
@@@ -31,73 -33,59 +34,78 @@@
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()
+ .get('cid:' + category_id + ':name');
+
if (tids.length > 0) {
- RDB.multi()
+ multi
.mget(title)
.mget(uid)
.mget(timestamp)
.mget(slug)
.mget(postcount)
+ .mget(locked)
+ .mget(deleted)
- .exec(function(err, replies) {
- title = replies[0];
- uid = replies[1];
- timestamp = replies[2];
- slug = replies[3];
- postcount = replies[4];
- locked = replies[5];
- deleted = replies[6];
-
- user.get_usernames_by_uids(uid, function(userNames) {
- var topics = [];
-
- for (var i=0, ii=title.length; i<ii; i++) {
- if (deleted[i] === '1') continue;
-
- topics.push({
- 'title' : title[i],
- 'uid' : uid[i],
- 'username': userNames[i],
- 'timestamp' : timestamp[i],
- 'relativeTime': utils.relativeTime(timestamp[i]),
- 'slug' : slug[i],
- 'post_count' : postcount[i],
- icon: locked[i] === '1' ? 'icon-lock' : 'hide',
- deleted: deleted[i]
- });
- }
+ }
+
+
+ multi.exec(function(err, replies) {
+ category_name = replies[0];
+ var topics = [];
+
+ if (tids.length > 0) {
+ title = replies[1];
+ uid = replies[2];
+ timestamp = replies[3];
+ slug = replies[4];
+ postcount = replies[5];
-
-
-
++ locked = replies[6];
++ deleted = replies[7];
+
+ user.get_usernames_by_uids(uid, function(userNames) {
- callback({
- 'show_topic_button' : category_id ? 'show' : 'hidden',
- 'category_id': category_id,
- 'topics': topics
+ for (var i=0, ii=title.length; i<ii; i++) {
+
+ topics.push({
+ 'title' : title[i],
+ 'uid' : uid[i],
+ 'username': userNames[i],
+ '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]
});
+ }
+
+ callback({
+ 'category_name' : category_id ? category_name : 'Recent',
+ 'show_topic_button' : category_id ? 'show' : 'hidden',
+ 'category_id': category_id,
+ 'topics': topics
});
+
+ });
+ }
+ else {
+ callback({
+ 'category_name' : category_id ? category_name : 'Recent',
+ 'show_topic_button' : category_id ? 'show' : 'hidden',
+ 'category_id': category_id,
+ 'topics': []
+ });
+ }
+
-
- }
- );
- } else callback({'category_id': category_id, 'topics': []});
+
+ });
+ //} else callback({'category_id': category_id, 'topics': []});
});
}
@@@ -160,17 -147,72 +168,80 @@@
type: 'notify',
timeout: 2000
});
+
+
+ // in future it may be possible to add topics to several categories, so leaving the door open here.
+ categories.get_category([category_id], function(data) {
+ RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
+ RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
+ });
+
});
-
-
};
+ 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));