Merge branch 'master' of github.com:psychobunny/node-forum

v1.18.x
Julian Lam 12 years ago
commit 8bccc8466e

@ -1,3 +1,11 @@
<div class="container">
<ul class="breadcrumb">
<li><a href="/">Home</a><span class="divider">/</span></li>
<li class="active">{category_name}</li>
<div id="category_active_users"></div>
</ul>
</div>
<button id="new_post" class="btn btn-primary btn-large {show_topic_button}">New Topic</button> <button id="new_post" class="btn btn-primary btn-large {show_topic_button}">New Topic</button>
<ul class="topic-container"> <ul class="topic-container">
<!-- BEGIN topics --> <!-- BEGIN topics -->

@ -1,6 +1,7 @@
<div class="container"> <div class="container">
<ul class="breadcrumb"> <ul class="breadcrumb">
<li><a href="/">Home</a> <span class="divider">/</span></li> <li><a href="/">Home</a><span class="divider">/</span></li>
<li><a href="/category/{category_slug}">{category_name}</a><span class="divider">/</span></li>
<li class="active">{topic_name}</li> <li class="active">{topic_name}</li>
<div id="thread_active_users"></div> <div id="thread_active_users"></div>
</ul> </ul>

@ -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) { Categories.get = function(callback) {
RDB.lrange('categories:cid', 0, -1, function(cids) { RDB.lrange('categories:cid', 0, -1, function(cids) {
var name = [], Categories.get_category(cids, callback);
description = [], });
icon = [], }
blockclass = [],
slug = [];
for (var i=0, ii=cids.length; i<ii; i++) { Categories.get_category = function(cids, callback) {
name.push('cid:' + cids[i] + ':name'); var name = [],
description.push('cid:' + cids[i] + ':description'); description = [],
icon.push('cid:' + cids[i] + ':icon'); icon = [],
blockclass.push('cid:' + cids[i] + ':blockclass'); blockclass = [],
slug.push('cid:' + cids[i] + ':slug'); slug = [];
}
if (cids.length > 0) { for (var i=0, ii=cids.length; i<ii; i++) {
RDB.multi() name.push('cid:' + cids[i] + ':name');
.mget(name) description.push('cid:' + cids[i] + ':description');
.mget(description) icon.push('cid:' + cids[i] + ':icon');
.mget(icon) blockclass.push('cid:' + cids[i] + ':blockclass');
.mget(blockclass) slug.push('cid:' + cids[i] + ':slug');
.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}); if (cids.length > 0) {
}); RDB.multi()
} else callback({'categories' : []}); .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)); }(exports));

@ -40,6 +40,8 @@ var RDB = require('./redis.js'),
callback({ callback({
'topic_name':thread_data.topic_name, 'topic_name':thread_data.topic_name,
'category_name':thread_data.category_name,
'category_slug':thread_data.category_slug,
'locked': parseInt(thread_data.locked) || 0, 'locked': parseInt(thread_data.locked) || 0,
'deleted': parseInt(thread_data.deleted) || 0, 'deleted': parseInt(thread_data.deleted) || 0,
'topic_id': tid, 'topic_id': tid,
@ -61,10 +63,6 @@ var RDB = require('./redis.js'),
pid.push(pids[i]); 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) { Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
vote_data = fav_data; vote_data = fav_data;
@ -79,6 +77,8 @@ var RDB = require('./redis.js'),
.mget(post_rep) .mget(post_rep)
.get('tid:' + tid + ':title') .get('tid:' + tid + ':title')
.get('tid:' + tid + ':locked') .get('tid:' + tid + ':locked')
.get('tid:' + tid + ':category_name')
.get('tid:' + tid + ':category_slug')
.get('tid:' + tid + ':deleted') .get('tid:' + tid + ':deleted')
.exec(function(err, replies) { .exec(function(err, replies) {
post_data = { post_data = {
@ -91,8 +91,10 @@ var RDB = require('./redis.js'),
thread_data = { thread_data = {
topic_name: replies[4], topic_name: replies[4],
locked: replies[5] || 0, locked: replies[5],
deleted: replies[6] || 0 category_name: replies[6],
category_slug: replies[7],
deleted: replies[8] || 0
}; };
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){ user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){

@ -2,7 +2,8 @@ var RDB = require('./redis.js'),
posts = require('./posts.js'), posts = require('./posts.js'),
utils = require('./utils.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) { (function(Topics) {
@ -38,8 +39,11 @@ var RDB = require('./redis.js'),
deleted.push('tid:' + tids[i] + ':deleted'); deleted.push('tid:' + tids[i] + ':deleted');
} }
var multi = RDB.multi()
.get('cid:' + category_id + ':name');
if (tids.length > 0) { if (tids.length > 0) {
RDB.multi() multi
.mget(title) .mget(title)
.mget(uid) .mget(uid)
.mget(timestamp) .mget(timestamp)
@ -47,49 +51,66 @@ var RDB = require('./redis.js'),
.mget(postcount) .mget(postcount)
.mget(locked) .mget(locked)
.mget(deleted) .mget(deleted)
.exec(function(err, replies) { }
title = replies[0];
uid = replies[1];
timestamp = replies[2]; multi.exec(function(err, replies) {
slug = replies[3]; category_name = replies[0];
postcount = replies[4]; var topics = [];
locked = replies[5];
deleted = replies[6]; if (tids.length > 0) {
title = replies[1];
user.get_usernames_by_uids(uid, function(userNames) { uid = replies[2];
var topics = []; timestamp = replies[3];
slug = replies[4];
for (var i=0, ii=title.length; i<ii; i++) { postcount = replies[5];
if (deleted[i] === '1') continue; locked = replies[6];
deleted = replies[7];
topics.push({
'title' : title[i], user.get_usernames_by_uids(uid, function(userNames) {
'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]
});
}
callback({ for (var i=0, ii=title.length; i<ii; i++) {
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id, topics.push({
'topics': topics '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]
}); });
}
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': []});
}); });
} }
Topics.post = function(socket, uid, title, content, category_id) { 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) { if (uid === 0) {
socket.emit('event:alert', { socket.emit('event:alert', {
@ -112,7 +133,7 @@ var RDB = require('./redis.js'),
RDB.lpush('topics:tid', tid); RDB.lpush('topics:tid', tid);
} else { } else {
// need to add some unique key sent by client so we can update this with the real uid later // 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 +168,14 @@ var RDB = require('./redis.js'),
type: 'notify', type: 'notify',
timeout: 2000 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);
});
}); });
}; };

Loading…
Cancel
Save