Skip to content

Node.js based forum software built for the modern web

interim commit for moderator support

Julian Lambdeb7b13f151
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index 147bf46267..85aa47df9c 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -50,6 +50,16 @@
<!-- END active_users -->
</div>
</div>
+ <div class="sidebar-block img-polaroid {moderator_block_class}">
+ <div class="block-header">
+ Moderators
+ </div>
+ <div class="block-content">
+ <!-- BEGIN moderators -->
+ <a href="/users/{moderators.username}"><img style="width: 48px; height: 48px; /*temporary*/" src="/graph/users/{moderators.username}/picture" class="img-polaroid" /></a>
+ <!-- END moderators -->
+ </div>
+ </div>
</div>
</div>
diff --git a/src/categories.js b/src/categories.js
index 1ac673d262..5f35dc1d14 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -38,6 +38,20 @@ var RDB = require('./redis.js'),
});
}
+ Categories.getModerators = function(cid, callback) {
+ RDB.smembers('cid:' + cid + ':moderators', function(err, mods) {
+ user.getMultipleUserFields(mods, ['username'], function(details) {
+ var moderators = [];
+ for(u in details) {
+ if (details.hasOwnProperty(u)) {
+ moderators.push({ username: details[u].username });
+ }
+ }
+ callback(moderators);
+ });
+ });
+ }
+
Categories.get_category = function(cids, callback) {
var name = [],
description = [],
diff --git a/src/posts.js b/src/posts.js
index 42a98c83e8..527b07ffe6 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -3,7 +3,8 @@ var RDB = require('./redis.js'),
marked = require('marked'),
user = require('./user.js'),
topics = require('./topics.js'),
- config = require('../config.js');
+ config = require('../config.js'),
+ async = require('async');
marked.setOptions({
breaks: true
diff --git a/src/templates.js b/src/templates.js
index 2ad56e23ae..8d04aacf6d 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -30,7 +30,7 @@ var fs = require('fs');
Templates.init = function() {
loadTemplates([
'header', 'footer', 'register', 'home', 'topic', 'account', 'friends',
- 'login', 'reset', 'reset_code', 'logout',
+ 'login', 'reset', 'reset_code',
'403',
'admin/header', 'admin/footer', 'admin/index',
'emails/header', 'emails/footer',
diff --git a/src/topics.js b/src/topics.js
index ead41792d1..db1f70dcd8 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -81,10 +81,11 @@ var RDB = require('./redis.js'),
recent_author = replies[11];
var usernames,
- has_read;
+ has_read,
+ moderators;
function generate_topic() {
- if (!usernames || !has_read) return;
+ if (!usernames || !has_read || !moderators) return;
for (var i=0, ii=title.length; i<ii; i++) {
@@ -125,7 +126,8 @@ var RDB = require('./redis.js'),
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0,
'topics': topics,
- 'active_users': active_users
+ 'active_users': active_users,
+ 'moderators': moderators
});
}
@@ -138,6 +140,11 @@ var RDB = require('./redis.js'),
has_read = hasRead;
generate_topic();
});
+
+ categories.getModerators(category_id, function(mods) {
+ moderators = mods;
+ generate_topic();
+ })
}
else {
callback({
@@ -147,9 +154,6 @@ var RDB = require('./redis.js'),
'topics': []
});
}
-
-
-
});
});
}
diff --git a/src/user.js b/src/user.js
index e378f40bb4..dbc135e03e 100644
--- a/src/user.js
+++ b/src/user.js
@@ -505,6 +505,12 @@ var config = require('../config.js'),
});
}
+ User.isModerator = function(uid, cid, callback) {
+ RDB.sismember(uid, 'cid:' + cid + ':moderators', function(err, exists) {
+ callback(exists);
+ });
+ }
+
User.reset = {
validate: function(socket, code, callback) {
if (typeof callback !== 'function') callback = undefined;
diff --git a/src/webserver.js b/src/webserver.js
index 3de6acdc98..63a09f03d3 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -207,8 +207,8 @@ var express = require('express'),
app.get('/api/:method/:id*', api_method);
app.get('/test', function(req, res) {
- posts.getRawContent(11, function(post) {
- res.send(JSON.stringify(post));
+ categories.getModerators(2, function(mods) {
+ res.send(JSON.stringify(mods));
});
});