mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 18:22:23 +02:00
more fixes
This commit is contained in:
@@ -5,7 +5,11 @@ var topics = require('../topics'),
|
||||
|
||||
SocketTopics.post = function(socket, data, callback) {
|
||||
|
||||
if (socket.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
|
||||
if(!data) {
|
||||
return callback(new Error('Invalid data'));
|
||||
}
|
||||
|
||||
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Post Unsuccessful',
|
||||
message: 'You don't seem to be logged in, so you cannot reply.',
|
||||
@@ -58,7 +62,7 @@ SocketTopics.post = function(socket, data, callback) {
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback();
|
||||
callback(null);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -68,122 +72,59 @@ SocketTopics.postcount = function(socket, tid, callback) {
|
||||
};
|
||||
|
||||
SocketTopics.markAllRead = function(socket, data, callback) {
|
||||
topics.markAllRead(socket.uid, function(err, success) {
|
||||
if (!err && success) {
|
||||
callback(true);
|
||||
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', 0);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketTopics.delete = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
||||
topics.markAllRead(socket.uid, function(err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', 0);
|
||||
|
||||
threadTools.delete(data.tid, socket.uid, function(err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
module.parent.exports.emitTopicPostStats();
|
||||
|
||||
|
||||
callback(null, 'topic.delete', {
|
||||
status: 'ok',
|
||||
tid: data.tid
|
||||
});
|
||||
});
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
SocketTopics.restore = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
||||
function doTopicAction(action, socket, tid, callback) {
|
||||
if(!tid) {
|
||||
return callback(new Error('Invalid tid'));
|
||||
}
|
||||
|
||||
threadTools.privileges(tid, socket.uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!privileges.editable) {
|
||||
if(!privileges || !privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
|
||||
threadTools.restore(data.tid, socket.uid, function(err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
module.parent.exports.emitTopicPostStats();
|
||||
|
||||
callback(null, 'topic.restore', {
|
||||
status: 'ok',
|
||||
tid: data.tid
|
||||
});
|
||||
});
|
||||
|
||||
if(threadTools[action]) {
|
||||
threadTools[action](tid, socket.uid, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SocketTopics.delete = function(socket, tid, callback) {
|
||||
doTopicAction('delete', socket, tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.lock = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
|
||||
threadTools.lock(data.tid, callback);
|
||||
});
|
||||
SocketTopics.restore = function(socket, tid, callback) {
|
||||
doTopicAction('restore', socket, tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.unlock = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
|
||||
threadTools.unlock(data.tid, callback);
|
||||
});
|
||||
SocketTopics.lock = function(socket, tid, callback) {
|
||||
doTopicAction('lock', socket, tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.pin = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, sessionData.uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
|
||||
threadTools.pin(data.tid, callback);
|
||||
});
|
||||
SocketTopics.unlock = function(socket, tid, callback) {
|
||||
doTopicAction('unlock', socket, tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.unpin = function(socket, data, callback) {
|
||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
SocketTopics.pin = function(socket, tid, callback) {
|
||||
doTopicAction('pin', socket, tid, callback);
|
||||
};
|
||||
|
||||
if (!privileges.editable) {
|
||||
return callback(new Error('not-allowed'));
|
||||
}
|
||||
|
||||
threadTools.unpin(data.tid, callback);
|
||||
});
|
||||
SocketTopics.unpin = function(socket, tid, callback) {
|
||||
doTopicAction('unpin', socket, tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
||||
|
||||
@@ -66,13 +66,16 @@ var winston = require('winston'),
|
||||
|
||||
events.logTopicDelete(uid, tid);
|
||||
|
||||
websockets.emitTopicPostStats();
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_deleted', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback(null);
|
||||
callback(null, {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +86,10 @@ var winston = require('winston'),
|
||||
|
||||
events.logTopicRestore(uid, tid);
|
||||
|
||||
websockets.emitTopicPostStats();
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_restored', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
topics.getTopicField(tid, 'title', function(err, title) {
|
||||
@@ -93,75 +97,69 @@ var winston = require('winston'),
|
||||
});
|
||||
|
||||
if(callback) {
|
||||
callback(null);
|
||||
callback(null, {
|
||||
tid:tid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ThreadTools.lock = function(tid, callback) {
|
||||
ThreadTools.lock = function(tid, uid, callback) {
|
||||
topics.setTopicField(tid, 'locked', 1);
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_locked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback({
|
||||
status: 'ok',
|
||||
callback(null, {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ThreadTools.unlock = function(tid, callback) {
|
||||
ThreadTools.unlock = function(tid, uid, callback) {
|
||||
topics.setTopicField(tid, 'locked', 0);
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_unlocked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback({
|
||||
status: 'ok',
|
||||
callback(null, {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ThreadTools.pin = function(tid, callback) {
|
||||
ThreadTools.pin = function(tid, uid, callback) {
|
||||
topics.setTopicField(tid, 'pinned', 1);
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', Math.pow(2, 53), tid);
|
||||
});
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_pinned', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback({
|
||||
status: 'ok',
|
||||
callback(null, {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ThreadTools.unpin = function(tid, callback) {
|
||||
ThreadTools.unpin = function(tid, uid, callback) {
|
||||
topics.setTopicField(tid, 'pinned', 0);
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||
db.sortedSetAdd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid);
|
||||
});
|
||||
|
||||
websockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
tid: tid
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback({
|
||||
status: 'ok',
|
||||
callback(null, {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
@@ -175,9 +173,7 @@ var winston = require('winston'),
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', topicData.lastposttime, tid, function(err, result) {
|
||||
|
||||
if(err) {
|
||||
return callback({
|
||||
status: 'error'
|
||||
});
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
topics.setTopicField(tid, 'cid', cid);
|
||||
@@ -193,10 +189,7 @@ var winston = require('winston'),
|
||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
|
||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
|
||||
|
||||
callback({
|
||||
status: 'ok'
|
||||
});
|
||||
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,19 +75,24 @@ var async = require('async'),
|
||||
return callback(new Error('no-privileges'));
|
||||
} else if (!cid) {
|
||||
return callback(new Error('invalid-cid'));
|
||||
} else if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
||||
}
|
||||
|
||||
if (title) {
|
||||
title = title.trim();
|
||||
}
|
||||
|
||||
if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
||||
return callback(new Error('title-too-short'), null);
|
||||
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
||||
return callback(new Error('title-too-long'), null);
|
||||
} else if (!content || content.length < meta.config.miminumPostLength) {
|
||||
return callback(new Error('content-too-short'), null);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
content = content.trim();
|
||||
}
|
||||
if (title) {
|
||||
title = title.trim();
|
||||
|
||||
if (!content || content.length < meta.config.miminumPostLength) {
|
||||
return callback(new Error('content-too-short'), null);
|
||||
}
|
||||
|
||||
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
||||
@@ -888,7 +893,7 @@ var async = require('async'),
|
||||
Topics.markAllRead = function(uid, callback) {
|
||||
db.getSetMembers('topics:tid', function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (tids && tids.length) {
|
||||
@@ -897,7 +902,7 @@ var async = require('async'),
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, true);
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user