mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
begin refactor of posts/topics + pagination + cleanup + async
This commit is contained in:
@@ -61,7 +61,6 @@ var RDB = require('./redis.js'),
|
|||||||
if (start == null) start = 0;
|
if (start == null) start = 0;
|
||||||
if (end == null) end = start + 10;
|
if (end == null) end = start + 10;
|
||||||
|
|
||||||
//build a proper wrapper for this and move it into above function later
|
|
||||||
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';
|
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';
|
||||||
|
|
||||||
RDB.smembers(range_var, function(err, tids) {
|
RDB.smembers(range_var, function(err, tids) {
|
||||||
|
|||||||
92
src/postTools.js
Normal file
92
src/postTools.js
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
var RDB = require('./redis.js'),
|
||||||
|
posts = require('./posts.js'),
|
||||||
|
threadTools = require('./threadTools.js'),
|
||||||
|
user = require('./user.js'),
|
||||||
|
config = require('../config.js'),
|
||||||
|
async = require('async'),
|
||||||
|
marked = require('marked');
|
||||||
|
|
||||||
|
marked.setOptions({
|
||||||
|
breaks: true
|
||||||
|
});
|
||||||
|
|
||||||
|
(function(PostTools) {
|
||||||
|
|
||||||
|
PostTools.privileges = function(pid, uid, callback) {
|
||||||
|
//todo: break early if one condition is true
|
||||||
|
|
||||||
|
function getThreadPrivileges(next) {
|
||||||
|
posts.get_tid_by_pid(pid, function(tid) {
|
||||||
|
threadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
next(null, privileges);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOwnPost(next) {
|
||||||
|
RDB.get('pid:' + pid + ':uid', function(err, author) {
|
||||||
|
if (author && parseInt(author) > 0) next(null, author === uid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasEnoughRep(next) {
|
||||||
|
// DRY fail in threadTools.
|
||||||
|
|
||||||
|
user.getUserField(uid, 'reputation', function(reputation) {
|
||||||
|
next(null, reputation >= config.privilege_thresholds.manage_content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) {
|
||||||
|
callback({
|
||||||
|
editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
|
||||||
|
view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PostTools.edit = function(uid, pid, content) {
|
||||||
|
var success = function() {
|
||||||
|
RDB.set('pid:' + pid + ':content', content);
|
||||||
|
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
||||||
|
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 || '') });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) success();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PostTools.delete = function(uid, pid) {
|
||||||
|
var success = function() {
|
||||||
|
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 });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) success();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PostTools.restore = function(uid, pid) {
|
||||||
|
var success = function() {
|
||||||
|
RDB.del('pid:' + pid + ':deleted');
|
||||||
|
|
||||||
|
posts.get_tid_by_pid(pid, function(tid) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) success();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}(exports));
|
||||||
157
src/posts.js
157
src/posts.js
@@ -4,6 +4,7 @@ var RDB = require('./redis.js'),
|
|||||||
user = require('./user.js'),
|
user = require('./user.js'),
|
||||||
topics = require('./topics.js'),
|
topics = require('./topics.js'),
|
||||||
config = require('../config.js'),
|
config = require('../config.js'),
|
||||||
|
threadTools = require('./threadTools.js'),
|
||||||
async = require('async');
|
async = require('async');
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
@@ -12,49 +13,108 @@ marked.setOptions({
|
|||||||
|
|
||||||
(function(Posts) {
|
(function(Posts) {
|
||||||
|
|
||||||
Posts.get = function(callback, pid, current_user) {
|
Posts.get = function(callback, tid, current_user, start, end) {
|
||||||
// Not used... although Topics.get could be refactored to call Posts.get for every post
|
if (start == null) start = 0;
|
||||||
|
if (end == null) end = start + 10;
|
||||||
|
|
||||||
|
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
|
||||||
|
RDB.handle(err);
|
||||||
|
|
||||||
|
if (pids.length === 0 ) {
|
||||||
|
callback(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.privileges = function(pid, uid, callback) {
|
topics.markAsRead(tid, current_user);
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
|
||||||
Posts.get_tid_by_pid(pid, function(tid) {
|
|
||||||
topics.privileges(tid, uid, function(privileges) {
|
for (var i=0, ii=pids.length; i<ii; i++) {
|
||||||
next(null, privileges);
|
content.push('pid:' + pids[i] + ':content');
|
||||||
|
uid.push('pid:' + pids[i] + ':uid');
|
||||||
|
timestamp.push('pid:' + pids[i] + ':timestamp');
|
||||||
|
post_rep.push('pid:' + pids[i] + ':rep');
|
||||||
|
editor.push('pid:' + pids[i] + ':editor');
|
||||||
|
editTime.push('pid:' + pids[i] + ':edited');
|
||||||
|
deleted.push('pid:' + pids[i] + ':deleted');
|
||||||
|
pid.push(pids[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getFavouritesData(next) {
|
||||||
|
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
|
||||||
|
next(null, fav_data);
|
||||||
|
}); // to be moved
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPostData(next) {
|
||||||
|
RDB.multi()
|
||||||
|
.mget(content)
|
||||||
|
.mget(uid)
|
||||||
|
.mget(timestamp)
|
||||||
|
.mget(post_rep)
|
||||||
|
.mget(editor)
|
||||||
|
.mget(editTime)
|
||||||
|
.mget(deleted)
|
||||||
|
.exec(function(err, replies) {
|
||||||
|
post_data = {
|
||||||
|
pid: pids,
|
||||||
|
content: replies[0],
|
||||||
|
uid: replies[1],
|
||||||
|
timestamp: replies[2],
|
||||||
|
reputation: replies[3],
|
||||||
|
editor: replies[4],
|
||||||
|
editTime: replies[5],
|
||||||
|
deleted: replies[6]
|
||||||
|
};
|
||||||
|
|
||||||
|
// below, to be deprecated
|
||||||
|
// Add any editors to the user_data object
|
||||||
|
for(var x = 0, numPosts = post_data.editor.length; x < numPosts; x++) {
|
||||||
|
if (post_data.editor[x] !== null && post_data.uid.indexOf(post_data.editor[x]) === -1) {
|
||||||
|
post_data.uid.push(post_data.editor[x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture', 'signature'], function(user_details) {
|
||||||
|
next(null, {
|
||||||
|
users: user_details,
|
||||||
|
posts: post_data
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
// above, to be deprecated
|
||||||
function(next) {
|
|
||||||
RDB.get('pid:' + pid + ':uid', function(err, author) {
|
|
||||||
if (author && parseInt(author) > 0) next(null, author === uid);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
user.getUserField(uid, 'reputation', function(reputation) {
|
|
||||||
next(null, reputation >= config.privilege_thresholds.manage_content);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err, results) {
|
|
||||||
|
async.parallel([getFavouritesData, getPostData], function(err, results) {
|
||||||
callback({
|
callback({
|
||||||
editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
|
'voteData' : results[0], // to be moved
|
||||||
view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
|
'userData' : results[1].users, // to be moved
|
||||||
|
'postData' : results[1].posts
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.get_tid_by_pid = function(pid, callback) {
|
Posts.get_tid_by_pid = function(pid, callback) {
|
||||||
RDB.get('pid:' + pid + ':tid', function(err, tid) {
|
RDB.get('pid:' + pid + ':tid', function(err, tid) {
|
||||||
if (tid && parseInt(tid) > 0) callback(tid);
|
if (tid && parseInt(tid) > 0) {
|
||||||
else callback(false);
|
callback(tid);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.get_cid_by_pid = function(pid, callback) {
|
Posts.get_cid_by_pid = function(pid, callback) {
|
||||||
Posts.get_tid_by_pid(pid, function(tid) {
|
Posts.get_tid_by_pid(pid, function(tid) {
|
||||||
if (tid) topics.get_cid_by_tid(tid, function(cid) {
|
if (tid) topics.get_cid_by_tid(tid, function(cid) {
|
||||||
if (cid) callback(cid);
|
if (cid) {
|
||||||
else callback(false);
|
callback(cid);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -81,6 +141,7 @@ marked.setOptions({
|
|||||||
|
|
||||||
// Re-add the poster, so he/she does not get an "unread" flag on this topic
|
// Re-add the poster, so he/she does not get an "unread" flag on this topic
|
||||||
topics.markAsRead(tid, uid);
|
topics.markAsRead(tid, uid);
|
||||||
|
// this will duplicate once we enter the thread, which is where we should be going
|
||||||
|
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Reply Successful',
|
title: 'Reply Successful',
|
||||||
@@ -89,7 +150,7 @@ marked.setOptions({
|
|||||||
timeout: 2000
|
timeout: 2000
|
||||||
});
|
});
|
||||||
|
|
||||||
user.getUserFields(uid, ['username','reputation','picture','signature'], function(data){
|
user.getUserFields(uid, ['username','reputation','picture','signature'], function(data) {
|
||||||
|
|
||||||
var timestamp = new Date().getTime();
|
var timestamp = new Date().getTime();
|
||||||
|
|
||||||
@@ -144,7 +205,7 @@ marked.setOptions({
|
|||||||
RDB.incr('tid:' + tid + ':postcount');
|
RDB.incr('tid:' + tid + ':postcount');
|
||||||
|
|
||||||
|
|
||||||
user.getUserFields(uid, ['username'], function(data){
|
user.getUserFields(uid, ['username'], function(data) {
|
||||||
//add active users to this category
|
//add active users to this category
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
||||||
RDB.handle(err);
|
RDB.handle(err);
|
||||||
@@ -275,48 +336,4 @@ marked.setOptions({
|
|||||||
socket.emit('api:posts.getRawPost', { post: raw });
|
socket.emit('api:posts.getRawPost', { post: raw });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.edit = function(uid, pid, content) {
|
|
||||||
var success = function() {
|
|
||||||
RDB.set('pid:' + pid + ':content', content);
|
|
||||||
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
|
||||||
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 || '') });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.privileges(pid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) success();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.delete = function(uid, pid) {
|
|
||||||
var success = function() {
|
|
||||||
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 });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.privileges(pid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) success();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.restore = function(uid, pid) {
|
|
||||||
var success = function() {
|
|
||||||
RDB.del('pid:' + pid + ':deleted');
|
|
||||||
|
|
||||||
Posts.get_tid_by_pid(pid, function(tid) {
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.privileges(pid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) success();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}(exports));
|
}(exports));
|
||||||
157
src/threadTools.js
Normal file
157
src/threadTools.js
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
var RDB = require('./redis.js'),
|
||||||
|
topics = require('./topics.js'),
|
||||||
|
categories = require('./categories.js'),
|
||||||
|
user = require('./user.js'),
|
||||||
|
config = require('../config.js'),
|
||||||
|
async = require('async');
|
||||||
|
|
||||||
|
|
||||||
|
(function(ThreadTools) {
|
||||||
|
|
||||||
|
ThreadTools.privileges = function(tid, uid, callback) {
|
||||||
|
//todo: break early if one condition is true
|
||||||
|
|
||||||
|
function getCategoryPrivileges(next) {
|
||||||
|
topics.get_cid_by_tid(tid, function(cid) {
|
||||||
|
categories.privileges(cid, uid, function(privileges) {
|
||||||
|
next(null, privileges);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasEnoughRep(next) {
|
||||||
|
// DRY fail in postTools
|
||||||
|
|
||||||
|
user.getUserField(uid, 'reputation', function(reputation) {
|
||||||
|
next(null, reputation >= config.privilege_thresholds.manage_thread);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async.parallel([getCategoryPrivileges, hasEnoughRep], function(err, results) {
|
||||||
|
callback({
|
||||||
|
editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
|
||||||
|
view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.lock = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// 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'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.unlock = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// Mark thread as unlocked
|
||||||
|
RDB.del('tid:' + tid + ':locked');
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:topic_unlocked', {
|
||||||
|
tid: tid,
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.delete = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// Mark thread as deleted
|
||||||
|
RDB.set('tid:' + tid + ':deleted', 1);
|
||||||
|
ThreadTools.lock(tid, uid);
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
|
||||||
|
tid: tid,
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.restore = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// Mark thread as restored
|
||||||
|
RDB.del('tid:' + tid + ':deleted');
|
||||||
|
ThreadTools.unlock(tid, uid);
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
|
||||||
|
tid: tid,
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.pin = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// Mark thread as pinned
|
||||||
|
RDB.set('tid:' + tid + ':pinned', 1);
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:topic_pinned', {
|
||||||
|
tid: tid,
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.unpin = function(tid, uid, socket) {
|
||||||
|
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||||
|
if (privileges.editable) {
|
||||||
|
// Mark thread as unpinned
|
||||||
|
RDB.del('tid:' + tid + ':pinned');
|
||||||
|
|
||||||
|
if (socket) {
|
||||||
|
io.sockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
||||||
|
tid: tid,
|
||||||
|
status: 'ok'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadTools.move = function(tid, cid, socket) {
|
||||||
|
RDB.get('tid:' + tid + ':cid', function(err, oldCid) {
|
||||||
|
RDB.handle(err);
|
||||||
|
|
||||||
|
RDB.smove('categories:' + oldCid + ':tid', 'categories:' + cid + ':tid', tid, function(err, result) {
|
||||||
|
if (!err && result === 1) {
|
||||||
|
RDB.set('tid:' + tid + ':cid', cid);
|
||||||
|
categories.get_category([cid], function(data) {
|
||||||
|
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 });
|
||||||
|
} else {
|
||||||
|
socket.emit('api:topic.move', { status: 'error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}(exports));
|
||||||
413
src/topics.js
413
src/topics.js
@@ -6,6 +6,7 @@ var RDB = require('./redis.js'),
|
|||||||
categories = require('./categories.js'),
|
categories = require('./categories.js'),
|
||||||
posts = require('./posts.js'),
|
posts = require('./posts.js'),
|
||||||
marked = require('marked'),
|
marked = require('marked'),
|
||||||
|
threadTools = require('./threadTools.js'),
|
||||||
async = require('async');
|
async = require('async');
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
@@ -13,188 +14,105 @@ marked.setOptions({
|
|||||||
});
|
});
|
||||||
|
|
||||||
(function(Topics) {
|
(function(Topics) {
|
||||||
|
Topics.get = function(callback, tid, current_user) {
|
||||||
|
|
||||||
Topics.get_by_category = function(callback, category, start, end) {
|
function getTopicData(next) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Topics.get = function(callback, tid, current_user, start, end) {
|
|
||||||
if (start == null) start = 0;
|
|
||||||
if (end == null) end = -1;//start + 10;
|
|
||||||
|
|
||||||
var post_data, user_data, thread_data, vote_data, privileges;
|
|
||||||
|
|
||||||
getTopicPosts();
|
|
||||||
|
|
||||||
getPrivileges();
|
|
||||||
|
|
||||||
|
|
||||||
//compile thread after all data is asynchronously called
|
|
||||||
function generateThread() {
|
|
||||||
if (!post_data || !user_data || !thread_data || !vote_data || !privileges) return;
|
|
||||||
|
|
||||||
var retrieved_posts = [],
|
|
||||||
main_posts = [];
|
|
||||||
|
|
||||||
for (var i=0, ii= post_data.pid.length; i<ii; i++) {
|
|
||||||
var uid = post_data.uid[i],
|
|
||||||
pid = post_data.pid[i];
|
|
||||||
|
|
||||||
if (post_data.deleted[i] === null || (post_data.deleted[i] === '1' && privileges.view_deleted) || current_user === uid) {
|
|
||||||
var post_obj = {
|
|
||||||
'pid' : pid,
|
|
||||||
'uid' : uid,
|
|
||||||
'content' : marked(post_data.content[i] || ''),
|
|
||||||
'post_rep' : post_data.reputation[i] || 0,
|
|
||||||
'timestamp' : post_data.timestamp[i],
|
|
||||||
'relativeTime': utils.relativeTime(post_data.timestamp[i]),
|
|
||||||
'username' : user_data[uid].username || 'anonymous',
|
|
||||||
'user_rep' : user_data[uid].reputation || 0,
|
|
||||||
'gravatar' : user_data[uid].picture || 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e',
|
|
||||||
'signature' : marked(user_data[uid].signature || ''),
|
|
||||||
'fav_star_class' : vote_data[pid] ? 'icon-star' : 'icon-star-empty',
|
|
||||||
'display_moderator_tools': (uid == current_user || privileges.editable) ? 'show' : 'none',
|
|
||||||
'edited-class': post_data.editor[i] !== null ? '' : 'none',
|
|
||||||
'editor': post_data.editor[i] !== null ? user_data[post_data.editor[i]].username : '',
|
|
||||||
'relativeEditTime': post_data.editTime !== null ? utils.relativeTime(post_data.editTime[i]) : '',
|
|
||||||
'deleted': post_data.deleted[i] || '0'
|
|
||||||
};
|
|
||||||
|
|
||||||
if (i == 0) main_posts.push(post_obj);
|
|
||||||
else retrieved_posts.push(post_obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback({
|
|
||||||
'topic_name':thread_data.topic_name,
|
|
||||||
'category_name':thread_data.category_name,
|
|
||||||
'category_slug':thread_data.category_slug,
|
|
||||||
'locked': parseInt(thread_data.locked) || 0,
|
|
||||||
'deleted': parseInt(thread_data.deleted) || 0,
|
|
||||||
'pinned': parseInt(thread_data.pinned) || 0,
|
|
||||||
'topic_id': tid,
|
|
||||||
'expose_tools': privileges.editable ? 1 : 0,
|
|
||||||
'posts': retrieved_posts,
|
|
||||||
'main_posts': main_posts
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTopicPosts() {
|
|
||||||
// get all data for thread in asynchronous fashion
|
|
||||||
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
|
|
||||||
RDB.handle(err);
|
|
||||||
|
|
||||||
if(pids.length === 0 ){
|
|
||||||
callback(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.markAsRead(tid, current_user);
|
|
||||||
|
|
||||||
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
|
|
||||||
|
|
||||||
for (var i=0, ii=pids.length; i<ii; i++) {
|
|
||||||
content.push('pid:' + pids[i] + ':content');
|
|
||||||
uid.push('pid:' + pids[i] + ':uid');
|
|
||||||
timestamp.push('pid:' + pids[i] + ':timestamp');
|
|
||||||
post_rep.push('pid:' + pids[i] + ':rep');
|
|
||||||
editor.push('pid:' + pids[i] + ':editor');
|
|
||||||
editTime.push('pid:' + pids[i] + ':edited');
|
|
||||||
deleted.push('pid:' + pids[i] + ':deleted');
|
|
||||||
pid.push(pids[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
|
|
||||||
vote_data = fav_data;
|
|
||||||
generateThread();
|
|
||||||
});
|
|
||||||
|
|
||||||
RDB.multi()
|
RDB.multi()
|
||||||
.mget(content)
|
|
||||||
.mget(uid)
|
|
||||||
.mget(timestamp)
|
|
||||||
.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_name')
|
||||||
.get('tid:' + tid + ':category_slug')
|
.get('tid:' + tid + ':category_slug')
|
||||||
.get('tid:' + tid + ':deleted')
|
.get('tid:' + tid + ':deleted')
|
||||||
.get('tid:' + tid + ':pinned')
|
.get('tid:' + tid + ':pinned')
|
||||||
.mget(editor)
|
|
||||||
.mget(editTime)
|
|
||||||
.mget(deleted)
|
|
||||||
.exec(function(err, replies) {
|
.exec(function(err, replies) {
|
||||||
post_data = {
|
next(null, {
|
||||||
pid: pids,
|
topic_name: replies[0],
|
||||||
content: replies[0],
|
locked: replies[1] || 0,
|
||||||
uid: replies[1],
|
category_name: replies[2],
|
||||||
timestamp: replies[2],
|
category_slug: replies[3],
|
||||||
reputation: replies[3],
|
deleted: replies[4] || 0,
|
||||||
editor: replies[10],
|
pinned: replies[5] || 0
|
||||||
editTime: replies[11],
|
});
|
||||||
deleted: replies[12]
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTopicPosts(next) {
|
||||||
|
posts.get(function(postData) {
|
||||||
|
next(null, postData);
|
||||||
|
}, tid, current_user, 0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPrivileges(next) {
|
||||||
|
threadTools.privileges(tid, current_user, function(privData) {
|
||||||
|
next(null, privData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {
|
||||||
|
var retrieved_posts = [],
|
||||||
|
main_posts = [];
|
||||||
|
|
||||||
|
var topicData = results[0],
|
||||||
|
postData = results[1].postData,
|
||||||
|
userData = results[1].userData,
|
||||||
|
voteData = results[1].voteData,
|
||||||
|
privileges = results[2];
|
||||||
|
|
||||||
|
for (var i=0, ii= postData.pid.length; i<ii; i++) {
|
||||||
|
var uid = postData.uid[i],
|
||||||
|
pid = postData.pid[i];
|
||||||
|
|
||||||
|
|
||||||
|
// ############ to be moved into posts.get ############
|
||||||
|
if (postData.deleted[i] === null || (postData.deleted[i] === '1' && privileges.view_deleted) || current_user === uid) {
|
||||||
|
var post_obj = {
|
||||||
|
'pid' : pid,
|
||||||
|
'uid' : uid,
|
||||||
|
'content' : marked(postData.content[i] || ''),
|
||||||
|
'post_rep' : postData.reputation[i] || 0,
|
||||||
|
'timestamp' : postData.timestamp[i],
|
||||||
|
'relativeTime': utils.relativeTime(postData.timestamp[i]),
|
||||||
|
'username' : userData[uid].username || 'anonymous',
|
||||||
|
'user_rep' : userData[uid].reputation || 0,
|
||||||
|
'gravatar' : userData[uid].picture || 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e',
|
||||||
|
'signature' : marked(userData[uid].signature || ''),
|
||||||
|
'fav_star_class' : voteData[pid] ? 'icon-star' : 'icon-star-empty',
|
||||||
|
'display_moderator_tools': (uid == current_user || privileges.editable) ? 'show' : 'none',
|
||||||
|
'edited-class': postData.editor[i] !== null ? '' : 'none',
|
||||||
|
'editor': postData.editor[i] !== null ? userData[postData.editor[i]].username : '',
|
||||||
|
'relativeEditTime': postData.editTime !== null ? utils.relativeTime(postData.editTime[i]) : '',
|
||||||
|
'deleted': postData.deleted[i] || '0'
|
||||||
};
|
};
|
||||||
|
|
||||||
thread_data = {
|
if (i == 0) {
|
||||||
topic_name: replies[4],
|
main_posts.push(post_obj);
|
||||||
locked: replies[5] || 0,
|
} else {
|
||||||
category_name: replies[6],
|
retrieved_posts.push(post_obj);
|
||||||
category_slug: replies[7],
|
|
||||||
deleted: replies[8] || 0,
|
|
||||||
pinned: replies[9] || 0
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add any editors to the user_data object
|
|
||||||
for(var x=0,numPosts=replies[10].length;x<numPosts;x++) {
|
|
||||||
if (replies[10][x] !== null && post_data.uid.indexOf(replies[10][x]) === -1) {
|
|
||||||
post_data.uid.push(replies[10][x]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ########## end to be moved into posts.get ############
|
||||||
|
}
|
||||||
|
|
||||||
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture', 'signature'], function(user_details){
|
|
||||||
user_data = user_details;
|
|
||||||
generateThread();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPrivileges() {
|
|
||||||
Topics.privileges(tid, current_user, function(user_privs) {
|
|
||||||
privileges = user_privs;
|
|
||||||
generateThread();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.privileges = function(tid, uid, callback) {
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
Topics.get_cid_by_tid(tid, function(cid) {
|
|
||||||
categories.privileges(cid, uid, function(privileges) {
|
|
||||||
next(null, privileges);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
user.getUserField(uid, 'reputation', function(reputation) {
|
|
||||||
next(null, reputation >= config.privilege_thresholds.manage_thread);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, results) {
|
|
||||||
callback({
|
callback({
|
||||||
editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
|
'topic_name':topicData.topic_name,
|
||||||
view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
|
'category_name':topicData.category_name,
|
||||||
|
'category_slug':topicData.category_slug,
|
||||||
|
'locked': parseInt(topicData.locked) || 0,
|
||||||
|
'deleted': parseInt(topicData.deleted) || 0,
|
||||||
|
'pinned': parseInt(topicData.pinned) || 0,
|
||||||
|
'topic_id': tid,
|
||||||
|
'expose_tools': privileges.editable ? 1 : 0,
|
||||||
|
'posts': retrieved_posts,
|
||||||
|
'main_posts': main_posts
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.get_topic = function(tid, uid, callback) {
|
Topics.get_topic = function(tid, uid, callback) {
|
||||||
var topicData = {};
|
var topicData = {};
|
||||||
|
|
||||||
async.parallel([
|
function get_topic_data(next) {
|
||||||
function(next) {
|
|
||||||
RDB.mget([
|
RDB.mget([
|
||||||
'tid:' + tid + ':title',
|
'tid:' + tid + ':title',
|
||||||
'tid:' + tid + ':uid',
|
'tid:' + tid + ':uid',
|
||||||
@@ -205,6 +123,10 @@ marked.setOptions({
|
|||||||
'tid:' + tid + ':pinned',
|
'tid:' + tid + ':pinned',
|
||||||
'tid:' + tid + ':deleted'
|
'tid:' + tid + ':deleted'
|
||||||
], function(err, topic) {
|
], function(err, topic) {
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
topicData.title = topic[0];
|
topicData.title = topic[0];
|
||||||
topicData.uid = topic[1];
|
topicData.uid = topic[1];
|
||||||
topicData.timestamp = topic[2];
|
topicData.timestamp = topic[2];
|
||||||
@@ -213,40 +135,54 @@ marked.setOptions({
|
|||||||
topicData.post_count = topic[4];
|
topicData.post_count = topic[4];
|
||||||
topicData.locked = topic[5];
|
topicData.locked = topic[5];
|
||||||
topicData.pinned = topic[6];
|
topicData.pinned = topic[6];
|
||||||
topicData.deleted = topic[7];
|
topiscData.deleted = topic[7];
|
||||||
|
|
||||||
user.getUserField(topic[1], 'username', function(username) {
|
user.getUserField(topic[1], 'username', function(username) {
|
||||||
topicData.username = username;
|
topicData.username = username;
|
||||||
next(null);
|
|
||||||
})
|
next();
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
function(next) {
|
}
|
||||||
|
|
||||||
|
function get_read_status(next) {
|
||||||
|
// posts.create calls this function - should be an option to skip this because its always true
|
||||||
if (uid && parseInt(uid) > 0) {
|
if (uid && parseInt(uid) > 0) {
|
||||||
RDB.sismember('tid:' + tid + ':read_by_uid', uid, function(err, read) {
|
RDB.sismember('tid:' + tid + ':read_by_uid', uid, function(err, read) {
|
||||||
topicData.badgeclass = read ? '' : 'badge-important';
|
topicData.badgeclass = read ? '' : 'badge-important';
|
||||||
next(null);
|
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
} else next(null);
|
} else {
|
||||||
},
|
next();
|
||||||
function(next) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_teaser(next) {
|
||||||
Topics.get_teaser(tid, function(teaser) {
|
Topics.get_teaser(tid, function(teaser) {
|
||||||
topicData.teaser_text = teaser.text;
|
topicData.teaser_text = teaser.text;
|
||||||
topicData.teaser_username = teaser.username;
|
topicData.teaser_username = teaser.username;
|
||||||
next(null);
|
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err) {
|
|
||||||
if (!err) {
|
async.parallel([get_topic_data, get_read_status, get_teaser], function(err) {
|
||||||
callback(topicData);
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback(topicData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.get_cid_by_tid = function(tid, callback) {
|
Topics.get_cid_by_tid = function(tid, callback) {
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
||||||
if (cid && parseInt(cid) > 0) callback(cid);
|
if (cid && parseInt(cid) > 0) {
|
||||||
else callback(false);
|
callback(cid);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,18 +210,20 @@ marked.setOptions({
|
|||||||
var requests = [];
|
var requests = [];
|
||||||
if (Array.isArray(tids)) {
|
if (Array.isArray(tids)) {
|
||||||
for(x=0,numTids=tids.length;x<numTids;x++) {
|
for(x=0,numTids=tids.length;x<numTids;x++) {
|
||||||
(function(x) {
|
(function(tid) {
|
||||||
requests.push(function(next) {
|
requests.push(function(next) {
|
||||||
Topics.get_teaser(tids[x], function(teaser_info) {
|
Topics.get_teaser(tid, function(teaser_info) {
|
||||||
next(null, teaser_info);
|
next(null, teaser_info);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})(x);
|
})(tids[x]);
|
||||||
}
|
}
|
||||||
async.parallel(requests, function(err, teasers) {
|
async.parallel(requests, function(err, teasers) {
|
||||||
callback(teasers);
|
callback(teasers);
|
||||||
});
|
});
|
||||||
} else callback([]);
|
} else {
|
||||||
|
callback([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.get_latest_undeleted_pid = function(tid, callback) {
|
Topics.get_latest_undeleted_pid = function(tid, callback) {
|
||||||
@@ -409,121 +347,4 @@ marked.setOptions({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.lock = function(tid, uid, socket) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// 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) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// Mark thread as unlocked
|
|
||||||
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) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// 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) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// Mark thread as restored
|
|
||||||
RDB.del('tid:' + tid + ':deleted');
|
|
||||||
Topics.unlock(tid, uid);
|
|
||||||
|
|
||||||
if (socket) {
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
|
|
||||||
tid: tid,
|
|
||||||
status: 'ok'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.pin = function(tid, uid, socket) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// Mark thread as pinned
|
|
||||||
RDB.set('tid:' + tid + ':pinned', 1);
|
|
||||||
|
|
||||||
if (socket) {
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:topic_pinned', {
|
|
||||||
tid: tid,
|
|
||||||
status: 'ok'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.unpin = function(tid, uid, socket) {
|
|
||||||
Topics.privileges(tid, uid, function(privileges) {
|
|
||||||
if (privileges.editable) {
|
|
||||||
// Mark thread as unpinned
|
|
||||||
RDB.del('tid:' + tid + ':pinned');
|
|
||||||
|
|
||||||
if (socket) {
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
|
||||||
tid: tid,
|
|
||||||
status: 'ok'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.move = function(tid, cid, socket) {
|
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, oldCid) {
|
|
||||||
RDB.handle(err);
|
|
||||||
|
|
||||||
RDB.smove('categories:' + oldCid + ':tid', 'categories:' + cid + ':tid', tid, function(err, result) {
|
|
||||||
if (!err && result === 1) {
|
|
||||||
RDB.set('tid:' + tid + ':cid', cid);
|
|
||||||
categories.get_category([cid], function(data) {
|
|
||||||
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 });
|
|
||||||
} else {
|
|
||||||
socket.emit('api:topic.move', { status: 'error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}(exports));
|
}(exports));
|
||||||
@@ -6,6 +6,8 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
user = require('./user.js'),
|
user = require('./user.js'),
|
||||||
posts = require('./posts.js'),
|
posts = require('./posts.js'),
|
||||||
topics = require('./topics.js'),
|
topics = require('./topics.js'),
|
||||||
|
threadTools = require('./threadTools.js'),
|
||||||
|
postTools = require('./postTools.js'),
|
||||||
categories = require('./categories.js');
|
categories = require('./categories.js');
|
||||||
|
|
||||||
(function(io) {
|
(function(io) {
|
||||||
@@ -185,27 +187,31 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.delete', function(data) {
|
socket.on('api:topic.delete', function(data) {
|
||||||
topics.delete(data.tid, uid, socket);
|
threadTools.delete(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.restore', function(data) {
|
socket.on('api:topic.restore', function(data) {
|
||||||
topics.restore(data.tid, uid, socket);
|
threadTools.restore(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.lock', function(data) {
|
socket.on('api:topic.lock', function(data) {
|
||||||
topics.lock(data.tid, uid, socket);
|
threadTools.lock(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.unlock', function(data) {
|
socket.on('api:topic.unlock', function(data) {
|
||||||
topics.unlock(data.tid, uid, socket);
|
threadTools.unlock(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.pin', function(data) {
|
socket.on('api:topic.pin', function(data) {
|
||||||
topics.pin(data.tid, uid, socket);
|
threadTools.pin(data.tid, uid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.unpin', function(data) {
|
socket.on('api:topic.unpin', function(data) {
|
||||||
topics.unpin(data.tid, uid, socket);
|
threadTools.unpin(data.tid, uid, socket);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('api:topic.move', function(data) {
|
||||||
|
threadTools.move(data.tid, data.cid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:categories.get', function() {
|
socket.on('api:categories.get', function() {
|
||||||
@@ -214,24 +220,20 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.move', function(data) {
|
|
||||||
topics.move(data.tid, data.cid, socket);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('api:posts.getRawPost', function(data) {
|
socket.on('api:posts.getRawPost', function(data) {
|
||||||
posts.getRawContent(data.pid, socket);
|
posts.getRawContent(data.pid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.edit', function(data) {
|
socket.on('api:posts.edit', function(data) {
|
||||||
posts.edit(uid, data.pid, data.content);
|
postTools.edit(uid, data.pid, data.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.delete', function(data) {
|
socket.on('api:posts.delete', function(data) {
|
||||||
posts.delete(uid, data.pid);
|
postTools.delete(uid, data.pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.restore', function(data) {
|
socket.on('api:posts.restore', function(data) {
|
||||||
posts.restore(uid, data.pid);
|
postTools.restore(uid, data.pid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user