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,10 +25,17 @@ 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) {
Categories.get_category(cids, callback);
});
}
Categories.get_category = function(cids, callback) {
var name = [], var name = [],
description = [], description = [],
icon = [], icon = [],
@ -78,7 +85,6 @@ var RDB = require('./redis.js'),
callback({'categories': categories}); callback({'categories': categories});
}); });
} else callback({'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,20 +51,25 @@ 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];
slug = replies[3];
postcount = replies[4];
locked = replies[5];
deleted = replies[6];
user.get_usernames_by_uids(uid, function(userNames) {
multi.exec(function(err, replies) {
category_name = replies[0];
var topics = []; 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) {
for (var i=0, ii=title.length; i<ii; i++) { for (var i=0, ii=title.length; i<ii; i++) {
if (deleted[i] === '1') continue;
topics.push({ topics.push({
'title' : title[i], 'title' : title[i],
@ -70,26 +79,38 @@ var RDB = require('./redis.js'),
'relativeTime': utils.relativeTime(timestamp[i]), 'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i], 'slug' : slug[i],
'post_count' : postcount[i], 'post_count' : postcount[i],
icon: locked[i] === '1' ? 'icon-lock' : 'hide', 'icon': locked[i] === '1' ? 'icon-lock' : 'hide',
deleted: deleted[i] 'deleted': deleted[i]
}); });
} }
callback({ callback({
'category_name' : category_id ? category_name : 'Recent',
'show_topic_button' : category_id ? 'show' : 'hidden', 'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id, 'category_id': category_id,
'topics': topics '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', {
@ -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