mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 10:35:55 +01:00
more fixes
This commit is contained in:
@@ -15,37 +15,25 @@ define(function() {
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case 'pin':
|
case 'pin':
|
||||||
if (!$this.hasClass('active')) {
|
if (!$this.hasClass('active')) {
|
||||||
socket.emit('topics.pin', {
|
socket.emit('topics.pin', tid, Topics.pin);
|
||||||
tid: tid
|
|
||||||
}, Topics.pin);
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit('topics.unpin', {
|
socket.emit('topics.unpin', tid, Topics.unpin);
|
||||||
tid: tid
|
|
||||||
}, Topics.unpin);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'lock':
|
case 'lock':
|
||||||
if (!$this.hasClass('active')) {
|
if (!$this.hasClass('active')) {
|
||||||
socket.emit('topics.lock', {
|
socket.emit('topics.lock', tid, Topics.lock);
|
||||||
tid: tid
|
|
||||||
}, Topics.lock);
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit('topics.unlock', {
|
socket.emit('topics.unlock', tid, Topics.unlock);
|
||||||
tid: tid
|
|
||||||
}, Topics.unlock);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
if (!$this.hasClass('active')) {
|
if (!$this.hasClass('active')) {
|
||||||
socket.emit('topics.delete', {
|
socket.emit('topics.delete', tid, Topics.setDeleted);
|
||||||
tid: tid
|
|
||||||
}, Topics.setDeleted);
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit('topics.restore', {
|
socket.emit('topics.restore', tid, Topics.restore);
|
||||||
tid: tid
|
|
||||||
}, Topics.restore);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -116,8 +104,12 @@ define(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.setDeleted = function(response) {
|
Topics.setDeleted = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="delete"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="delete"]');
|
||||||
|
|
||||||
$(btnEl).addClass('active');
|
$(btnEl).addClass('active');
|
||||||
@@ -125,8 +117,12 @@ define(function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.restore = function(response) {
|
Topics.restore = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="delete"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="delete"]');
|
||||||
|
|
||||||
$(btnEl).removeClass('active');
|
$(btnEl).removeClass('active');
|
||||||
@@ -134,16 +130,24 @@ define(function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.lock = function(response) {
|
Topics.lock = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="lock"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="lock"]');
|
||||||
|
|
||||||
$(btnEl).addClass('active');
|
$(btnEl).addClass('active');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.unlock = function(response) {
|
Topics.unlock = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="lock"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="lock"]');
|
||||||
|
|
||||||
$(btnEl).removeClass('active');
|
$(btnEl).removeClass('active');
|
||||||
@@ -151,16 +155,24 @@ define(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Topics.unpin = function(response) {
|
Topics.unpin = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="pin"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="pin"]');
|
||||||
|
|
||||||
$(btnEl).removeClass('active');
|
$(btnEl).removeClass('active');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.pin = function(response) {
|
Topics.pin = function(err, response) {
|
||||||
if (response.status === 'ok') {
|
if(err) {
|
||||||
|
return app.alert(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && response.tid) {
|
||||||
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="pin"]');
|
var btnEl = document.querySelector('li[data-tid="' + response.tid + '"] button[data-action="pin"]');
|
||||||
|
|
||||||
$(btnEl).addClass('active');
|
$(btnEl).addClass('active');
|
||||||
|
|||||||
@@ -52,16 +52,14 @@ define(['composer'], function(composer) {
|
|||||||
if (thread_state.deleted !== '1') {
|
if (thread_state.deleted !== '1') {
|
||||||
bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) {
|
bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
socket.emit('topics.delete', {
|
socket.emit('topics.delete', tid);
|
||||||
tid: tid
|
|
||||||
}, null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
bootbox.confirm('Are you sure you want to restore this thread?', function(confirm) {
|
bootbox.confirm('Are you sure you want to restore this thread?', function(confirm) {
|
||||||
if (confirm) socket.emit('topics.restore', {
|
if (confirm) {
|
||||||
tid: tid
|
socket.emit('topics.restore', tid);
|
||||||
}, null);
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -69,26 +67,18 @@ define(['composer'], function(composer) {
|
|||||||
|
|
||||||
$('.lock_thread').on('click', function(e) {
|
$('.lock_thread').on('click', function(e) {
|
||||||
if (thread_state.locked !== '1') {
|
if (thread_state.locked !== '1') {
|
||||||
socket.emit('topics.lock', {
|
socket.emit('topics.lock', tid);
|
||||||
tid: tid
|
|
||||||
}, null);
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit('topics.unlock', {
|
socket.emit('topics.unlock', tid);
|
||||||
tid: tid
|
|
||||||
}, null);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.pin_thread').on('click', function(e) {
|
$('.pin_thread').on('click', function(e) {
|
||||||
if (thread_state.pinned !== '1') {
|
if (thread_state.pinned !== '1') {
|
||||||
socket.emit('topics.pin', {
|
socket.emit('topics.pin', tid);
|
||||||
tid: tid
|
|
||||||
}, null);
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit('topics.unpin', {
|
socket.emit('topics.unpin', tid);
|
||||||
tid: tid
|
|
||||||
}, null);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -629,45 +619,47 @@ define(['composer'], function(composer) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_deleted', function(data) {
|
socket.on('event:topic_deleted', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_locked_state(true);
|
set_locked_state(true);
|
||||||
set_delete_state(true);
|
set_delete_state(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_restored', function(data) {
|
socket.on('event:topic_restored', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_locked_state(false);
|
set_locked_state(false);
|
||||||
set_delete_state(false);
|
set_delete_state(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_locked', function(data) {
|
socket.on('event:topic_locked', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_locked_state(true, 1);
|
set_locked_state(true, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_unlocked', function(data) {
|
socket.on('event:topic_unlocked', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_locked_state(false, 1);
|
set_locked_state(false, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_pinned', function(data) {
|
socket.on('event:topic_pinned', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_pinned_state(true, 1);
|
set_pinned_state(true, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_unpinned', function(data) {
|
socket.on('event:topic_unpinned', function(data) {
|
||||||
if (data.tid === tid && data.status === 'ok') {
|
if (data && data.tid === tid) {
|
||||||
set_pinned_state(false, 1);
|
set_pinned_state(false, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:topic_moved', function(data) {
|
socket.on('event:topic_moved', function(data) {
|
||||||
if (data && data.tid > 0) ajaxify.go('topic/' + data.tid);
|
if (data && data.tid > 0) {
|
||||||
|
ajaxify.go('topic/' + data.tid);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:post_edited', function(data) {
|
socket.on('event:post_edited', function(data) {
|
||||||
|
|||||||
@@ -55,8 +55,11 @@ define(function() {
|
|||||||
|
|
||||||
$('#mark-allread-btn').on('click', function() {
|
$('#mark-allread-btn').on('click', function() {
|
||||||
var btn = $(this);
|
var btn = $(this);
|
||||||
socket.emit('topics.markAllRead', {}, function(success) {
|
socket.emit('topics.markAllRead', function(err) {
|
||||||
if (success) {
|
if(err) {
|
||||||
|
return app.alertError('There was an error marking topics read!');
|
||||||
|
}
|
||||||
|
|
||||||
btn.remove();
|
btn.remove();
|
||||||
$('#topics-container').empty();
|
$('#topics-container').empty();
|
||||||
$('#category-no-topics').removeClass('hidden');
|
$('#category-no-topics').removeClass('hidden');
|
||||||
@@ -65,9 +68,6 @@ define(function() {
|
|||||||
.removeClass('badge-important')
|
.removeClass('badge-important')
|
||||||
.addClass('badge-inverse')
|
.addClass('badge-inverse')
|
||||||
.html('0');
|
.html('0');
|
||||||
} else {
|
|
||||||
app.alertError('There was an error marking topics read!');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ var topics = require('../topics'),
|
|||||||
|
|
||||||
SocketTopics.post = function(socket, data, callback) {
|
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', {
|
socket.emit('event:alert', {
|
||||||
title: 'Post Unsuccessful',
|
title: 'Post Unsuccessful',
|
||||||
message: 'You don't seem to be logged in, so you cannot reply.',
|
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',
|
type: 'success',
|
||||||
timeout: 2000
|
timeout: 2000
|
||||||
});
|
});
|
||||||
callback();
|
callback(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -68,122 +72,59 @@ SocketTopics.postcount = function(socket, tid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.markAllRead = function(socket, data, callback) {
|
SocketTopics.markAllRead = function(socket, data, callback) {
|
||||||
topics.markAllRead(socket.uid, function(err, success) {
|
topics.markAllRead(socket.uid, function(err) {
|
||||||
if (!err && success) {
|
if(err) {
|
||||||
callback(true);
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', 0);
|
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', 0);
|
||||||
} else {
|
|
||||||
callback(false);
|
callback(null);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.delete = function(socket, data, callback) {
|
function doTopicAction(action, socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
if(!tid) {
|
||||||
|
return callback(new Error('Invalid tid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
threadTools.privileges(tid, socket.uid, function(err, privileges) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!privileges.editable) {
|
if(!privileges || !privileges.editable) {
|
||||||
return callback(new Error('not-allowed'));
|
return callback(new Error('not-allowed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
threadTools.delete(data.tid, socket.uid, function(err) {
|
if(threadTools[action]) {
|
||||||
if(err) {
|
threadTools[action](tid, socket.uid, callback);
|
||||||
return callback(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.parent.exports.emitTopicPostStats();
|
|
||||||
|
|
||||||
|
|
||||||
callback(null, 'topic.delete', {
|
|
||||||
status: 'ok',
|
|
||||||
tid: data.tid
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketTopics.delete = function(socket, tid, callback) {
|
||||||
|
doTopicAction('delete', socket, tid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.restore = function(socket, data, callback) {
|
SocketTopics.restore = function(socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
doTopicAction('restore', socket, tid, callback);
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!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
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.lock = function(socket, data, callback) {
|
SocketTopics.lock = function(socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
doTopicAction('lock', socket, tid, callback);
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
return callback(new Error('not-allowed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
threadTools.lock(data.tid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.unlock = function(socket, data, callback) {
|
SocketTopics.unlock = function(socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
doTopicAction('unlock', socket, tid, callback);
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
return callback(new Error('not-allowed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
threadTools.unlock(data.tid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.pin = function(socket, data, callback) {
|
SocketTopics.pin = function(socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, sessionData.uid, function(err, privileges) {
|
doTopicAction('pin', socket, tid, callback);
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
return callback(new Error('not-allowed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
threadTools.pin(data.tid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.unpin = function(socket, data, callback) {
|
SocketTopics.unpin = function(socket, tid, callback) {
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
doTopicAction('unpin', socket, tid, callback);
|
||||||
if(err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
return callback(new Error('not-allowed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
threadTools.unpin(data.tid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
||||||
|
|||||||
@@ -66,13 +66,16 @@ var winston = require('winston'),
|
|||||||
|
|
||||||
events.logTopicDelete(uid, tid);
|
events.logTopicDelete(uid, tid);
|
||||||
|
|
||||||
|
websockets.emitTopicPostStats();
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_deleted', {
|
websockets.in('topic_' + tid).emit('event:topic_deleted', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(null);
|
callback(null, {
|
||||||
|
tid: tid
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,9 +86,10 @@ var winston = require('winston'),
|
|||||||
|
|
||||||
events.logTopicRestore(uid, tid);
|
events.logTopicRestore(uid, tid);
|
||||||
|
|
||||||
|
websockets.emitTopicPostStats();
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_restored', {
|
websockets.in('topic_' + tid).emit('event:topic_restored', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
topics.getTopicField(tid, 'title', function(err, title) {
|
topics.getTopicField(tid, 'title', function(err, title) {
|
||||||
@@ -93,75 +97,69 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback(null);
|
callback(null, {
|
||||||
|
tid:tid
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.lock = function(tid, callback) {
|
ThreadTools.lock = function(tid, uid, callback) {
|
||||||
topics.setTopicField(tid, 'locked', 1);
|
topics.setTopicField(tid, 'locked', 1);
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_locked', {
|
websockets.in('topic_' + tid).emit('event:topic_locked', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback(null, {
|
||||||
status: 'ok',
|
|
||||||
tid: tid
|
tid: tid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.unlock = function(tid, callback) {
|
ThreadTools.unlock = function(tid, uid, callback) {
|
||||||
topics.setTopicField(tid, 'locked', 0);
|
topics.setTopicField(tid, 'locked', 0);
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_unlocked', {
|
websockets.in('topic_' + tid).emit('event:topic_unlocked', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback(null, {
|
||||||
status: 'ok',
|
|
||||||
tid: tid
|
tid: tid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.pin = function(tid, callback) {
|
ThreadTools.pin = function(tid, uid, callback) {
|
||||||
topics.setTopicField(tid, 'pinned', 1);
|
topics.setTopicField(tid, 'pinned', 1);
|
||||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
db.sortedSetAdd('categories:' + cid + ':tid', Math.pow(2, 53), tid);
|
db.sortedSetAdd('categories:' + cid + ':tid', Math.pow(2, 53), tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_pinned', {
|
websockets.in('topic_' + tid).emit('event:topic_pinned', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback(null, {
|
||||||
status: 'ok',
|
|
||||||
tid: tid
|
tid: tid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.unpin = function(tid, callback) {
|
ThreadTools.unpin = function(tid, uid, callback) {
|
||||||
topics.setTopicField(tid, 'pinned', 0);
|
topics.setTopicField(tid, 'pinned', 0);
|
||||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||||
db.sortedSetAdd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid);
|
db.sortedSetAdd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
websockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
websockets.in('topic_' + tid).emit('event:topic_unpinned', {
|
||||||
tid: tid,
|
tid: tid
|
||||||
status: 'ok'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback(null, {
|
||||||
status: 'ok',
|
|
||||||
tid: tid
|
tid: tid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -175,9 +173,7 @@ var winston = require('winston'),
|
|||||||
db.sortedSetAdd('categories:' + cid + ':tid', topicData.lastposttime, tid, function(err, result) {
|
db.sortedSetAdd('categories:' + cid + ':tid', topicData.lastposttime, tid, function(err, result) {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback({
|
return callback(err);
|
||||||
status: 'error'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.setTopicField(tid, 'cid', cid);
|
topics.setTopicField(tid, 'cid', cid);
|
||||||
@@ -193,10 +189,7 @@ var winston = require('winston'),
|
|||||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
|
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
|
||||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
|
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
|
||||||
|
|
||||||
callback({
|
callback(null);
|
||||||
status: 'ok'
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,19 +75,24 @@ var async = require('async'),
|
|||||||
return callback(new Error('no-privileges'));
|
return callback(new Error('no-privileges'));
|
||||||
} else if (!cid) {
|
} else if (!cid) {
|
||||||
return callback(new Error('invalid-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);
|
return callback(new Error('title-too-short'), null);
|
||||||
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
||||||
return callback(new Error('title-too-long'), null);
|
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) {
|
if (content) {
|
||||||
content = content.trim();
|
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) {
|
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
||||||
@@ -888,7 +893,7 @@ var async = require('async'),
|
|||||||
Topics.markAllRead = function(uid, callback) {
|
Topics.markAllRead = function(uid, callback) {
|
||||||
db.getSetMembers('topics:tid', function(err, tids) {
|
db.getSetMembers('topics:tid', function(err, tids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err, null);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tids && tids.length) {
|
if (tids && tids.length) {
|
||||||
@@ -897,7 +902,7 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, true);
|
callback(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user