mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-10 16:47:36 +01:00
Merge branch 'master' of https://github.com/psychobunny/NodeBB
Conflicts: src/posts.js src/topics.js
This commit is contained in:
21
src/posts.js
21
src/posts.js
@@ -1,7 +1,8 @@
|
||||
var RDB = require('./redis.js'),
|
||||
utils = require('./utils.js'),
|
||||
marked = require('marked'),
|
||||
user = require('./user.js');
|
||||
user = require('./user.js'),
|
||||
config = require('../config.js');
|
||||
|
||||
(function(Posts) {
|
||||
|
||||
@@ -9,12 +10,12 @@ var RDB = require('./redis.js'),
|
||||
if (start == null) start = 0;
|
||||
if (end == null) end = start + 10;
|
||||
|
||||
var post_data, user_data, thread_data, vote_data;
|
||||
var post_data, user_data, thread_data, vote_data, viewer_data;
|
||||
|
||||
|
||||
//compile thread after all data is asynchronously called
|
||||
function generateThread() {
|
||||
if (!post_data ||! user_data || !thread_data || !vote_data) return;
|
||||
if (!post_data ||! user_data || !thread_data || !vote_data || !viewer_data) return;
|
||||
|
||||
var posts = [];
|
||||
|
||||
@@ -42,7 +43,9 @@ var RDB = require('./redis.js'),
|
||||
'category_name':thread_data.category_name,
|
||||
'category_slug':thread_data.category_slug,
|
||||
'locked': parseInt(thread_data.locked) || 0,
|
||||
'deleted': parseInt(thread_data.deleted) || 0,
|
||||
'topic_id': tid,
|
||||
'expose_tools': viewer_data.reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
|
||||
'posts': posts
|
||||
});
|
||||
}
|
||||
@@ -76,6 +79,7 @@ var RDB = require('./redis.js'),
|
||||
.get('tid:' + tid + ':locked')
|
||||
.get('tid:' + tid + ':category_name')
|
||||
.get('tid:' + tid + ':category_slug')
|
||||
.get('tid:' + tid + ':deleted')
|
||||
.exec(function(err, replies) {
|
||||
post_data = {
|
||||
pid: pids,
|
||||
@@ -89,7 +93,8 @@ var RDB = require('./redis.js'),
|
||||
topic_name: replies[4],
|
||||
locked: replies[5],
|
||||
category_name: replies[6],
|
||||
category_slug: replies[7]
|
||||
category_slug: replies[7],
|
||||
deleted: replies[8] || 0
|
||||
};
|
||||
|
||||
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
|
||||
@@ -97,7 +102,13 @@ var RDB = require('./redis.js'),
|
||||
generateThread();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
user.getUserField(current_user, 'reputation', function(reputation){
|
||||
viewer_data = {
|
||||
reputation: reputation
|
||||
};
|
||||
generateThread();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
var RDB = require('./redis.js'),
|
||||
posts = require('./posts.js'),
|
||||
utils = require('./utils.js'),
|
||||
user = require('./user.js')
|
||||
user = require('./user.js'),
|
||||
configs = require('../config.js'),
|
||||
categories = require('./categories.js');
|
||||
|
||||
(function(Topics) {
|
||||
@@ -24,14 +25,18 @@ var RDB = require('./redis.js'),
|
||||
uid = [],
|
||||
timestamp = [],
|
||||
slug = [],
|
||||
postcount = [];
|
||||
postcount = [],
|
||||
locked = [],
|
||||
deleted = [];
|
||||
|
||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
||||
title.push('tid:' + tids[i] + ':title');
|
||||
uid.push('tid:' + tids[i] + ':uid');
|
||||
timestamp.push('tid:' + tids[i] + ':timestamp');
|
||||
slug.push('tid:' + tids[i] + ':slug');
|
||||
postcount.push('tid:' + tids[i] + ':postcount');
|
||||
postcount.push('tid:' + tids[i] + ':postcount'),
|
||||
locked.push('tid:' + tids[i] + ':locked'),
|
||||
deleted.push('tid:' + tids[i] + ':deleted');
|
||||
}
|
||||
|
||||
var multi = RDB.multi()
|
||||
@@ -44,6 +49,8 @@ var RDB = require('./redis.js'),
|
||||
.mget(timestamp)
|
||||
.mget(slug)
|
||||
.mget(postcount)
|
||||
.mget(locked)
|
||||
.mget(deleted)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +64,8 @@ var RDB = require('./redis.js'),
|
||||
timestamp = replies[3];
|
||||
slug = replies[4];
|
||||
postcount = replies[5];
|
||||
|
||||
|
||||
|
||||
locked = replies[6];
|
||||
deleted = replies[7];
|
||||
|
||||
user.get_usernames_by_uids(uid, function(userNames) {
|
||||
|
||||
@@ -72,7 +78,9 @@ var RDB = require('./redis.js'),
|
||||
'timestamp' : timestamp[i],
|
||||
'relativeTime': utils.relativeTime(timestamp[i]),
|
||||
'slug' : slug[i],
|
||||
'post_count' : postcount[i]
|
||||
'post_count' : postcount[i],
|
||||
'icon': locked[i] === '1' ? 'icon-lock' : 'hide',
|
||||
'deleted': deleted[i]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -169,8 +177,71 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
Topics.lock = function(tid, uid, socket) {
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as locked
|
||||
RDB.set('tid:' + tid + ':locked', 1);
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_locked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Topics.unlock = function(tid, uid, socket) {
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as locked
|
||||
RDB.del('tid:' + tid + ':locked');
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_unlocked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Topics.delete = function(tid, uid, socket) {
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as deleted
|
||||
RDB.set('tid:' + tid + ':deleted', 1);
|
||||
Topics.lock(tid, uid);
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Topics.restore = function(tid, uid, socket) {
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as deleted
|
||||
RDB.del('tid:' + tid + ':deleted');
|
||||
Topics.unlock(tid, uid);
|
||||
|
||||
if (socket) {
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}(exports));
|
||||
@@ -393,9 +393,8 @@ passport.deserializeUser(function(uid, done) {
|
||||
}
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
global.modules.posts.get(function(data) {
|
||||
res.send('<pre>' + JSON.stringify(data, null, 4) + '</pre>');
|
||||
}, 1, 1);
|
||||
global.modules.topics.delete(1, 1);
|
||||
res.send();
|
||||
});
|
||||
}(WebServer));
|
||||
|
||||
|
||||
@@ -62,10 +62,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||
socket.emit('event:connect', {status: 1});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
console.log('Got disconnect! SESSION ID : '+hs.sessionID+' USER ID : '+uid);
|
||||
|
||||
delete users[hs.sessionID];
|
||||
console.log(users);
|
||||
});
|
||||
|
||||
|
||||
@@ -177,6 +174,22 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||
socket.on('api:user.active.get_record', function() {
|
||||
modules.user.active.get_record(socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.delete', function(data) {
|
||||
modules.topics.delete(data.tid, uid, socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.restore', function(data) {
|
||||
modules.topics.restore(data.tid, uid, socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.lock', function(data) {
|
||||
modules.topics.lock(data.tid, uid, socket);
|
||||
});
|
||||
|
||||
socket.on('api:topic.unlock', function(data) {
|
||||
modules.topics.unlock(data.tid, uid, socket);
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user