|
|
@ -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);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|