mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-11 02:23:16 +02:00
Merge branch 'master' of https://github.com/psychobunny/NodeBB
This commit is contained in:
@@ -25,60 +25,66 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Categories.edit = function(data, callback) {
|
||||
// just a reminder to self that name + slugs are stored into topics data as well.
|
||||
};
|
||||
|
||||
Categories.get = function(callback) {
|
||||
RDB.lrange('categories:cid', 0, -1, function(cids) {
|
||||
var name = [],
|
||||
description = [],
|
||||
icon = [],
|
||||
blockclass = [],
|
||||
slug = [];
|
||||
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
name.push('cid:' + cids[i] + ':name');
|
||||
description.push('cid:' + cids[i] + ':description');
|
||||
icon.push('cid:' + cids[i] + ':icon');
|
||||
blockclass.push('cid:' + cids[i] + ':blockclass');
|
||||
slug.push('cid:' + cids[i] + ':slug');
|
||||
}
|
||||
|
||||
if (cids.length > 0) {
|
||||
RDB.multi()
|
||||
.mget(name)
|
||||
.mget(description)
|
||||
.mget(icon)
|
||||
.mget(blockclass)
|
||||
.mget(slug)
|
||||
.exec(function(err, replies) {
|
||||
name = replies[0];
|
||||
description = replies[1];
|
||||
icon = replies[2];
|
||||
blockclass = replies[3];
|
||||
slug = replies[4];
|
||||
|
||||
var categories = [];
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
categories.push({
|
||||
'name' : name[i],
|
||||
'cid' : cids[i],
|
||||
'slug' : slug[i],
|
||||
'description' : description[i],
|
||||
'blockclass' : blockclass[i],
|
||||
'icon' : icon[i],
|
||||
/*'topics' : [0,1], later
|
||||
'latest_post' : {
|
||||
'uid' : 1,
|
||||
'pid' : 1,
|
||||
timestamp and shit
|
||||
}*/
|
||||
});
|
||||
}
|
||||
|
||||
callback({'categories': categories});
|
||||
});
|
||||
} else callback({'categories' : []});
|
||||
Categories.get_category(cids, callback);
|
||||
});
|
||||
}
|
||||
|
||||
Categories.get_category = function(cids, callback) {
|
||||
var name = [],
|
||||
description = [],
|
||||
icon = [],
|
||||
blockclass = [],
|
||||
slug = [];
|
||||
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
name.push('cid:' + cids[i] + ':name');
|
||||
description.push('cid:' + cids[i] + ':description');
|
||||
icon.push('cid:' + cids[i] + ':icon');
|
||||
blockclass.push('cid:' + cids[i] + ':blockclass');
|
||||
slug.push('cid:' + cids[i] + ':slug');
|
||||
}
|
||||
|
||||
if (cids.length > 0) {
|
||||
RDB.multi()
|
||||
.mget(name)
|
||||
.mget(description)
|
||||
.mget(icon)
|
||||
.mget(blockclass)
|
||||
.mget(slug)
|
||||
.exec(function(err, replies) {
|
||||
name = replies[0];
|
||||
description = replies[1];
|
||||
icon = replies[2];
|
||||
blockclass = replies[3];
|
||||
slug = replies[4];
|
||||
|
||||
var categories = [];
|
||||
for (var i=0, ii=cids.length; i<ii; i++) {
|
||||
categories.push({
|
||||
'name' : name[i],
|
||||
'cid' : cids[i],
|
||||
'slug' : slug[i],
|
||||
'description' : description[i],
|
||||
'blockclass' : blockclass[i],
|
||||
'icon' : icon[i],
|
||||
/*'topics' : [0,1], later
|
||||
'latest_post' : {
|
||||
'uid' : 1,
|
||||
'pid' : 1,
|
||||
timestamp and shit
|
||||
}*/
|
||||
});
|
||||
}
|
||||
|
||||
callback({'categories': categories});
|
||||
});
|
||||
} else callback({'categories' : []});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
15
src/posts.js
15
src/posts.js
@@ -40,8 +40,11 @@ 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,
|
||||
'pinned': parseInt(thread_data.pinned) || 0,
|
||||
'topic_id': tid,
|
||||
'expose_tools': viewer_data.reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
|
||||
'posts': posts
|
||||
@@ -61,10 +64,6 @@ var RDB = require('./redis.js'),
|
||||
pid.push(pids[i]);
|
||||
}
|
||||
|
||||
RDB.get('tid:' + tid + ':title', function(topic_name) {
|
||||
thread_data = {topic_name: topic_name};
|
||||
generateThread();
|
||||
});
|
||||
|
||||
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
|
||||
vote_data = fav_data;
|
||||
@@ -79,7 +78,10 @@ var RDB = require('./redis.js'),
|
||||
.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')
|
||||
.get('tid:' + tid + ':pinned')
|
||||
.exec(function(err, replies) {
|
||||
post_data = {
|
||||
pid: pids,
|
||||
@@ -92,7 +94,10 @@ var RDB = require('./redis.js'),
|
||||
thread_data = {
|
||||
topic_name: replies[4],
|
||||
locked: replies[5] || 0,
|
||||
deleted: replies[6] || 0
|
||||
category_name: replies[6],
|
||||
category_slug: replies[7],
|
||||
deleted: replies[8] || 0,
|
||||
pinned: replies[9] || 0
|
||||
};
|
||||
|
||||
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
|
||||
|
||||
152
src/topics.js
152
src/topics.js
@@ -2,7 +2,8 @@ var RDB = require('./redis.js'),
|
||||
posts = require('./posts.js'),
|
||||
utils = require('./utils.js'),
|
||||
user = require('./user.js'),
|
||||
configs = require('../config.js');
|
||||
configs = require('../config.js'),
|
||||
categories = require('./categories.js');
|
||||
|
||||
(function(Topics) {
|
||||
|
||||
@@ -26,20 +27,25 @@ var RDB = require('./redis.js'),
|
||||
slug = [],
|
||||
postcount = [],
|
||||
locked = [],
|
||||
deleted = [];
|
||||
deleted = [],
|
||||
pinned = [];
|
||||
|
||||
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'),
|
||||
locked.push('tid:' + tids[i] + ':locked'),
|
||||
postcount.push('tid:' + tids[i] + ':postcount');
|
||||
locked.push('tid:' + tids[i] + ':locked');
|
||||
deleted.push('tid:' + tids[i] + ':deleted');
|
||||
pinned.push('tid:' + tids[i] + ':pinned');
|
||||
}
|
||||
|
||||
var multi = RDB.multi()
|
||||
.get('cid:' + category_id + ':name');
|
||||
|
||||
if (tids.length > 0) {
|
||||
RDB.multi()
|
||||
multi
|
||||
.mget(title)
|
||||
.mget(uid)
|
||||
.mget(timestamp)
|
||||
@@ -47,49 +53,75 @@ var RDB = require('./redis.js'),
|
||||
.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];
|
||||
.mget(pinned)
|
||||
}
|
||||
|
||||
|
||||
multi.exec(function(err, replies) {
|
||||
category_name = replies[0];
|
||||
var topics = [];
|
||||
|
||||
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]
|
||||
});
|
||||
}
|
||||
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];
|
||||
pinned = replies[8];
|
||||
|
||||
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],
|
||||
'lock-icon': locked[i] === '1' ? 'icon-lock' : 'hide',
|
||||
'deleted': deleted[i],
|
||||
'pinned': parseInt(pinned[i] || 0), // For sorting purposes
|
||||
'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'hide'
|
||||
});
|
||||
}
|
||||
|
||||
// Float pinned topics to the top
|
||||
topics = topics.sort(function(a, b) {
|
||||
return b.pinned - a.pinned;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
} else callback({'category_id': category_id, 'topics': []});
|
||||
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': []});
|
||||
});
|
||||
}
|
||||
|
||||
Topics.post = function(socket, uid, title, content, category_id) {
|
||||
if (!category_id) throw new Error('Attempted to post without a category_id');
|
||||
|
||||
if (uid === 0) {
|
||||
socket.emit('event:alert', {
|
||||
@@ -112,7 +144,7 @@ var RDB = require('./redis.js'),
|
||||
RDB.lpush('topics:tid', tid);
|
||||
} else {
|
||||
// need to add some unique key sent by client so we can update this with the real uid later
|
||||
RDB.lpush('topics:queued:tid', tid);
|
||||
RDB.lpush('topics:queued:tid', tid);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,6 +179,14 @@ var RDB = require('./redis.js'),
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@@ -215,4 +255,36 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Topics.pin = 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 + ':pinned', 1);
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_pinned', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Topics.unpin = 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 + ':pinned');
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}(exports));
|
||||
@@ -145,15 +145,17 @@ passport.deserializeUser(function(uid, done) {
|
||||
|
||||
// Complex Routes
|
||||
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'topic/' + req.params.topic_id + '");});</script>' + templates['footer']);
|
||||
var topic_url = req.params.topic_id + (req.params.slug ? '/' + req.params.slug : '');
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
app.get('/category/:category_id/:slug?', function(req, res) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'category/' + req.params.category_id + '");});</script>' + templates['footer']);
|
||||
var category_url = req.params.category_id + (req.params.slug ? '/' + req.params.slug : '');
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
app.get('/confirm/:code', function(req, res) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
||||
|
||||
@@ -192,6 +192,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||
socket.on('api:topic.unlock', function(data) {
|
||||
modules.topics.unlock(data.tid, uid, socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.pin', function(data) {
|
||||
modules.topics.pin(data.tid, uid, socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.unpin', function(data) {
|
||||
modules.topics.unpin(data.tid, uid, socket);
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user