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

v1.18.x
Julian Lam 12 years ago
commit 6060f4fbb4

@ -2,6 +2,9 @@ var categories = require('./src/categories.js'),
templates = require('./public/src/templates.js'),
webserver = require('./src/webserver.js'),
websockets = require('./src/websockets.js'),
admin = {
'categories': require('./src/admin/categories.js')
},
fs = require('fs');
DEVELOPMENT = true;
@ -33,11 +36,13 @@ global.templates = {};
default_categories = JSON.parse(default_categories);
for (var category in default_categories) {
categories.create(default_categories[category]);
admin.categories.create(default_categories[category]);
}
});
} else console.log('Good.');
} else {
console.log('Good.');
}
});
}

@ -38,25 +38,21 @@ var socket,
socket.on('connect', function(data){
if(reconnecting) {
app.alert({
alert_id: 'connection_alert',
title: 'Connected',
message: 'Connection successful',
type: 'success',
timeout: 5000
});
setTimeout(function(){
app.alert({
alert_id: 'connection_alert',
title: 'Connected',
message: 'Connection successful.',
type: 'success',
timeout: 5000
});
}, 1000);
reconnecting = false;
}
});
socket.on('disconnect', function(data){
app.alert({
alert_id: 'connection_alert',
title: 'Disconnect',
message: 'You have disconnected from NodeBB, we will try to reconnect!',
type: 'error',
timeout: 5000
});
});
socket.on('reconnecting', function(data) {

@ -11,7 +11,7 @@
</div>
<div class="category row">
<div class="span9">
<div class="{topic_row_size}">
<ul id="topics-container">
<!-- BEGIN topics -->
<a href="../../topic/{topics.slug}"><li class="category-item {topics.deleted-class}">
@ -43,7 +43,7 @@
<!-- END topics -->
</ul>
</div>
<div class="span3">
<div class="span3 {show_category_features}">
<div class="sidebar-block img-polaroid">
<div class="block-header">
Recent Replies
@ -77,7 +77,7 @@
<hr />
<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_category_features}">New Topic</button>
<script type="text/javascript">

@ -98,7 +98,6 @@
}
})
socket.on('api:notifications.get', function(data) {
console.log(data);
var notifFrag = document.createDocumentFragment(),
notifEl = document.createElement('li'),
numRead = data.read.length,
@ -126,8 +125,10 @@
});
socket.on('api:notifications.counts', function(counts) {
var notifIcon = document.querySelector('.notifications a i');
if (counts.unread > 0) notifIcon.className = 'icon-circle active';
else notifIcon.className = 'icon-circle-blank';
if(notifIcon) {
if (counts.unread > 0) notifIcon.className = 'icon-circle active';
else notifIcon.className = 'icon-circle-blank';
}
});
socket.on('event:new_notification', function() {
console.log('WOOT');

@ -36,12 +36,12 @@
<li>
<a href="/latest">Recent <span class="badge badge-inverse">3</span></a>
</li>
<li>
<!--<li>
<a href="/popular">Popular</a>
</li>
<li>
<a href="/active">Active</a>
</li>
</li>-->
<li>
<a href="/users">Users</a>
</li>

@ -0,0 +1,31 @@
var RDB = require('./../redis.js'),
utils = require('./../../public/src/utils.js'),
categories = require('./../categories.js');
(function(CategoriesAdmin) {
CategoriesAdmin.create = function(data, callback) {
RDB.incr('global:next_category_id', function(err, cid) {
RDB.handle(err);
var slug = cid + '/' + utils.slugify(data.name);
RDB.rpush('categories:cid', cid);
// Topic Info
RDB.set('cid:' + cid + ':name', data.name);
RDB.set('cid:' + cid + ':description', data.description);
RDB.set('cid:' + cid + ':icon', data.icon);
RDB.set('cid:' + cid + ':blockclass', data.blockclass);
RDB.set('cid:' + cid + ':slug', slug);
RDB.set('category:slug:' + slug + ':cid', cid);
if (callback) callback({'status': 1});
});
};
CategoriesAdmin.edit = function(data, callback) {
// just a reminder to self that name + slugs are stored into topics data as well.
};
}(exports));

@ -7,59 +7,7 @@ var RDB = require('./redis.js'),
(function(Categories) {
// START Move into possibly admin/categories.js
// An admin-only function. Seeing how we have no control panel yet ima leave this right here. sit pretty, you
Categories.create = function(data, callback) {
RDB.incr('global:next_category_id', function(err, cid) {
RDB.handle(err);
var slug = cid + '/' + utils.slugify(data.name);
RDB.rpush('categories:cid', cid);
// Topic Info
RDB.set('cid:' + cid + ':name', data.name);
RDB.set('cid:' + cid + ':description', data.description);
RDB.set('cid:' + cid + ':icon', data.icon);
RDB.set('cid:' + cid + ':blockclass', data.blockclass);
RDB.set('cid:' + cid + ':slug', slug);
RDB.set('category:slug:' + slug + ':cid', cid);
if (callback) callback({'status': 1});
});
};
Categories.edit = function(data, callback) {
// just a reminder to self that name + slugs are stored into topics data as well.
};
// END Move into possibly admin/categories.js
Categories.privileges = function(cid, uid, callback) {
function isModerator(next) {
user.isModerator(uid, cid, function(isMod) {
next(null, isMod);
});
}
function isAdministrator(next) {
user.isAdministrator(uid, function(isAdmin) {
next(null, isAdmin);
});
}
async.parallel([isModerator, isAdministrator], function(err, results) {
callback({
editable: results.indexOf(true) !== -1 ? true : false,
view_deleted: results.indexOf(true) !== -1 ? true : false
});
});
}
Categories.get = function(callback, category_id, current_user) {
Categories.getCategoryById = function(category_id, current_user, callback) {
RDB.smembers('categories:' + category_id + ':tid', function(err, tids) {
RDB.multi()
.get('cid:' + category_id + ':name')
@ -79,7 +27,8 @@ var RDB = require('./redis.js'),
var categoryData = {
'category_name' : category_name,
'show_topic_button' : 'show',
'show_category_features' : 'show',
'topic_row_size': 'span9',
'category_id': category_id,
'active_users': active_users,
'topics' : []
@ -112,8 +61,6 @@ var RDB = require('./redis.js'),
callback(categoryData);
});
}
});
});
}
@ -123,7 +70,8 @@ var RDB = require('./redis.js'),
RDB.zrange('topics:recent', 0, -1, function(err, tids) {
var latestTopics = {
'category_name' : 'Recent',
'show_topic_button' : 'hidden',
'show_category_features' : 'hidden',
'topic_row_size': 'span12',
'category_id': false,
'topics' : []
};
@ -140,7 +88,7 @@ var RDB = require('./redis.js'),
});
}
// not the permanent location for this function
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
var title = [],
uid = [],
@ -276,6 +224,29 @@ var RDB = require('./redis.js'),
}
Categories.privileges = function(cid, uid, callback) {
function isModerator(next) {
user.isModerator(uid, cid, function(isMod) {
next(null, isMod);
});
}
function isAdministrator(next) {
user.isAdministrator(uid, function(isAdmin) {
next(null, isAdmin);
});
}
async.parallel([isModerator, isAdministrator], function(err, results) {
callback({
editable: results.indexOf(true) !== -1 ? true : false,
view_deleted: results.indexOf(true) !== -1 ? true : false
});
});
}
Categories.hasReadCategories = function(cids, uid, callback) {
var batch = RDB.multi();
@ -291,6 +262,11 @@ var RDB = require('./redis.js'),
Categories.getCategories = function(cids, callback, current_user) {
if (cids.length === 0) {
callback({'categories' : []});
return;
}
var name = [],
description = [],
icon = [],
@ -307,49 +283,47 @@ var RDB = require('./redis.js'),
slug.push('cid:' + cids[i] + ':slug');
topic_count.push('cid:' + cids[i] + ':topiccount');
}
if (cids.length > 0) {
RDB.multi()
.mget(name)
.mget(description)
.mget(icon)
.mget(blockclass)
.mget(slug)
.mget(topic_count)
.exec(function(err, replies) {
name = replies[0];
description = replies[1];
icon = replies[2];
blockclass = replies[3];
slug = replies[4];
topic_count = replies[5];
function generateCategories() {
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],
'badgeclass' : (!topic_count[i] || (has_read[i] && current_user !=0)) ? '' : 'badge-important',
'topic_count' : topic_count[i] || 0
});
}
callback({'categories': categories});
RDB.multi()
.mget(name)
.mget(description)
.mget(icon)
.mget(blockclass)
.mget(slug)
.mget(topic_count)
.exec(function(err, replies) {
name = replies[0];
description = replies[1];
icon = replies[2];
blockclass = replies[3];
slug = replies[4];
topic_count = replies[5];
function generateCategories() {
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],
'badgeclass' : (!topic_count[i] || (has_read[i] && current_user !=0)) ? '' : 'badge-important',
'topic_count' : topic_count[i] || 0
});
}
Categories.hasReadCategories(cids, current_user, function(read_data) {
has_read = read_data;
generateCategories();
});
callback({'categories': categories});
}
Categories.hasReadCategories(cids, current_user, function(read_data) {
has_read = read_data;
generateCategories();
});
} else callback({'categories' : []});
});
};
}(exports));

@ -25,7 +25,9 @@ marked.setOptions({
function isOwnPost(next) {
RDB.get('pid:' + pid + ':uid', function(err, author) {
if (author && parseInt(author) > 0) next(null, author === uid);
if (author && parseInt(author) > 0) {
next(null, author === uid);
}
});
}
@ -52,12 +54,17 @@ marked.setOptions({
RDB.set('pid:' + pid + ':editor', uid);
posts.get_tid_by_pid(pid, function(tid) {
io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });
io.sockets.in('topic_' + tid).emit('event:post_edited', {
pid: pid,
content: marked(content || '')
});
});
};
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) success();
if (privileges.editable) {
success();
}
});
}
@ -66,12 +73,16 @@ marked.setOptions({
RDB.set('pid:' + pid + ':deleted', 1);
posts.get_tid_by_pid(pid, function(tid) {
io.sockets.in('topic_' + tid).emit('event:post_deleted', { pid: pid });
io.sockets.in('topic_' + tid).emit('event:post_deleted', {
pid: pid
});
});
};
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) success();
if (privileges.editable) {
success();
}
});
}
@ -80,12 +91,16 @@ marked.setOptions({
RDB.del('pid:' + pid + ':deleted');
posts.get_tid_by_pid(pid, function(tid) {
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
io.sockets.in('topic_' + tid).emit('event:post_restored', {
pid: pid
});
});
};
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) success();
if (privileges.editable) {
success();
}
});
}

@ -14,16 +14,12 @@ marked.setOptions({
(function(Posts) {
Posts.get = function(callback, tid, current_user, start, end) {
if (start == null) start = 0;
if (end == null) end = start + 10;
Posts.getPostsByTid = function(tid, current_user, start, end, callback) {
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
RDB.handle(err);
if (pids.length === 0 ) {
callback(false);
return;
throw new Error('Topic should never have 0 posts. tid: ' + tid);
}
topics.markAsRead(tid, current_user);

@ -50,7 +50,7 @@ var user = require('./../user.js'),
}
break;
case 'topics' :
categories.get(function(data) {
categories.getCategoryById(0, 0, function(data) {
res.send(JSON.stringify(data));
});
break;

@ -145,10 +145,17 @@ var RDB = require('./redis.js'),
RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
});
socket.emit('api:topic.move', { status: 'ok' });
io.sockets.in('topic_' + tid).emit('event:topic_moved', { tid: tid });
socket.emit('api:topic.move', {
status: 'ok'
});
io.sockets.in('topic_' + tid).emit('event:topic_moved', {
tid: tid
});
} else {
socket.emit('api:topic.move', { status: 'error' });
socket.emit('api:topic.move', {
status: 'error'
});
}
});
});

@ -14,8 +14,7 @@ marked.setOptions({
});
(function(Topics) {
Topics.get = function(callback, tid, current_user) {
Topics.getTopicById = function(tid, current_user, callback) {
function getTopicData(next) {
RDB.multi()
.get('tid:' + tid + ':title')
@ -37,9 +36,9 @@ marked.setOptions({
}
function getTopicPosts(next) {
posts.get(function(postData) {
posts.getPostsByTid(tid, current_user, 0, 10, function(postData) {
next(null, postData);
}, tid, current_user, 0, 10);
});
}
function getPrivileges(next) {
@ -68,7 +67,7 @@ marked.setOptions({
pid = postData.pid[i];
// ############ to be moved into posts.get ############
// ############ to be moved into posts.getPostsByTid ############
if (postData.deleted[i] === null || (postData.deleted[i] === '1' && privileges.view_deleted) || current_user === uid) {
var post_obj = {
'pid' : pid,
@ -95,7 +94,7 @@ marked.setOptions({
retrieved_posts.push(post_obj);
}
}
// ########## end to be moved into posts.get ############
// ########## end to be moved into posts.getPostsByTid ############
}
callback({

@ -105,7 +105,8 @@ var express = require('express'),
});
// These functions are called via ajax once the initial page is loaded to populate templates with data
function api_method(req, res) {
function api_method(req, res) {
var uid = (req.user) ? req.user.uid : 0;
switch(req.params.method) {
case 'get_templates_listing' :
@ -118,7 +119,7 @@ var express = require('express'),
data.motd_class = (config.show_motd || config.show_motd === undefined) ? '' : 'none';
data.motd = marked(config.motd || "# NodeBB v0.1\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i> Get NodeBB</a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i> Fork us on Github</a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i> @dcplabs</a>");
res.send(JSON.stringify(data));
}, (req.user) ? req.user.uid : 0);
}, uid);
break;
case 'login' :
var data = {},
@ -165,43 +166,27 @@ var express = require('express'),
res.send(JSON.stringify(data));
break;
case 'topic' :
topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0);
topics.getTopicById(req.params.id, uid, function(data) {
res.send(data ? JSON.stringify(data) : false);
});
break;
case 'category' :
categories.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0);
categories.getCategoryById(req.params.id, uid, function(data) {
res.send(data ? JSON.stringify(data) : false);
}, req.params.id, uid);
break;
case 'latest' :
categories.getLatestTopics((req.user) ? req.user.uid : 0, 0, 9, function(data) {
categories.getLatestTopics(uid, 0, 9, function(data) {
res.send(JSON.stringify(data));
});
break;
case 'popular' :
categories.get(function(data) {
if(!data) {
res.send(false);
return;
}
categories.getLatestTopics(uid, 0, 9, function(data) {
res.send(JSON.stringify(data));
});
break;
case 'active' :
categories.get(function(data) {
if(!data) {
res.send(false);
return;
}
categories.getLatestTopics(uid, 0, 9, function(data) {
res.send(JSON.stringify(data));
});
break;

Loading…
Cancel
Save