Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 98e4257939

@ -94,11 +94,8 @@
var templates = require('./public/src/templates'), var templates = require('./public/src/templates'),
translator = require('./public/src/translator'), translator = require('./public/src/translator'),
webserver = require('./src/webserver'); webserver = require('./src/webserver'),
console.log('here now'); sockets = require('./src/socket.io'),
// SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], 'browser client minification': true}),
// websockets = require('./src/websockets'),
var sockets = require('./src/socket.io'),
plugins = require('./src/plugins'), plugins = require('./src/plugins'),
notifications = require('./src/notifications'), notifications = require('./src/notifications'),
upgrade = require('./src/upgrade'); upgrade = require('./src/upgrade');
@ -107,7 +104,7 @@
upgrade.check(function(schema_ok) { upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) { if (schema_ok || nconf.get('check-schema') === false) {
// websockets.init(SocketIO);
sockets.init(); sockets.init();
plugins.init(); plugins.init();

@ -434,21 +434,25 @@ define(['taskbar'], function(taskbar) {
'title' : titleEl.val(), 'title' : titleEl.val(),
'content' : bodyEl.val(), 'content' : bodyEl.val(),
'category_id' : postData.cid 'category_id' : postData.cid
}, function() {
composer.discard(post_uuid);
}); });
} else if (parseInt(postData.tid) > 0) { } else if (parseInt(postData.tid) > 0) {
socket.emit('api:posts.reply', { socket.emit('api:posts.reply', {
'topic_id' : postData.tid, 'topic_id' : postData.tid,
'content' : bodyEl.val() 'content' : bodyEl.val()
}, function() {
composer.discard(post_uuid);
}); });
} else if (parseInt(postData.pid) > 0) { } else if (parseInt(postData.pid) > 0) {
socket.emit('api:posts.edit', { socket.emit('api:posts.edit', {
pid: postData.pid, pid: postData.pid,
content: bodyEl.val(), content: bodyEl.val(),
title: titleEl.val() title: titleEl.val()
}, function() {
composer.discard(post_uuid);
}); });
} }
composer.discard(post_uuid);
} }
function composerAlert(title, message) { function composerAlert(title, message) {

@ -154,9 +154,11 @@
</div> </div>
<button type="submit" class="btn btn-default hide">[[global:search]]</button> <button type="submit" class="btn btn-default hide">[[global:search]]</button>
</div> </div>
<button id="search-button" type="button" class="btn btn-link hide"><i class="fa fa-search"></i></button>
</form> </form>
</li> </li>
<li>
<a id="search-button" class="hide"><i class="fa fa-search"></i></a>
</li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right pagination-block"> <ul class="nav navbar-nav navbar-right pagination-block">

@ -120,6 +120,7 @@ Sockets.init = function() {
}); });
socket.on('*', function(payload, callback) { socket.on('*', function(payload, callback) {
// Ignore all non-api messages // Ignore all non-api messages
if (payload.name.substr(0, 4) !== 'api:') { if (payload.name.substr(0, 4) !== 'api:') {
return; return;

@ -6,7 +6,7 @@ var posts = require('../posts'),
SocketPosts = {}; SocketPosts = {};
SocketPosts.reply = function(data, sessionData) { SocketPosts.reply = function(data, callback, sessionData) {
if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
sessionData.socket.emit('event:alert', { sessionData.socket.emit('event:alert', {
title: 'Reply Unsuccessful', title: 'Reply Unsuccessful',
@ -17,12 +17,6 @@ SocketPosts.reply = function(data, sessionData) {
return; return;
} }
// FIXME: postDelay in sockets? I am disappoint.
// if (Date.now() - lastPostTime < meta.config.postDelay * 1000) {
// module.parent.exports.emitTooManyPostsAlert(sessionData.socket);
// return;
// }
topics.reply(data.topic_id, sessionData.uid, data.content, function(err, postData) { topics.reply(data.topic_id, sessionData.uid, data.content, function(err, postData) {
if(err) { if(err) {
if (err.message === 'content-too-short') { if (err.message === 'content-too-short') {
@ -48,7 +42,7 @@ SocketPosts.reply = function(data, sessionData) {
} }
if (postData) { if (postData) {
lastPostTime = Date.now();
module.parent.exports.emitTopicPostStats(); module.parent.exports.emitTopicPostStats();
sessionData.socket.emit('event:alert', { sessionData.socket.emit('event:alert', {
@ -63,7 +57,7 @@ SocketPosts.reply = function(data, sessionData) {
sessionData.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData); sessionData.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
sessionData.server.sockets.in('recent_posts').emit('event:new_post', socketData); sessionData.server.sockets.in('recent_posts').emit('event:new_post', socketData);
sessionData.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData); sessionData.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
callback();
} }
}); });
@ -93,7 +87,7 @@ SocketPosts.getRawPost = function(data, callback) {
}); });
}; };
SocketPosts.edit = function(data, sessionData) { SocketPosts.edit = function(data, callback, sessionData) {
if(!sessionData.uid) { if(!sessionData.uid) {
sessionData.socket.emit('event:alert', { sessionData.socket.emit('event:alert', {
title: 'Can&apos;t edit', title: 'Can&apos;t edit',
@ -111,6 +105,7 @@ SocketPosts.edit = function(data, sessionData) {
} }
postTools.edit(sessionData.uid, data.pid, data.title, data.content, data.images); postTools.edit(sessionData.uid, data.pid, data.title, data.content, data.images);
callback();
}; };
SocketPosts.delete = function(data, callback, sessionData) { SocketPosts.delete = function(data, callback, sessionData) {

@ -3,7 +3,7 @@ var topics = require('../topics'),
SocketTopics = {}; SocketTopics = {};
SocketTopics.post = function(data, sessionData) { SocketTopics.post = function(data, callback, sessionData) {
if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Post Unsuccessful', title: 'Post Unsuccessful',
@ -57,6 +57,7 @@ SocketTopics.post = function(data, sessionData) {
type: 'success', type: 'success',
timeout: 2000 timeout: 2000
}); });
callback();
} }
}); });
}; };

@ -134,6 +134,10 @@ var async = require('async'),
Topics.reply = function(tid, uid, content, callback) { Topics.reply = function(tid, uid, content, callback) {
threadTools.privileges(tid, uid, function(err, privileges) { threadTools.privileges(tid, uid, function(err, privileges) {
if(err) {
return callback(err);
}
if (content) { if (content) {
content = content.trim(); content = content.trim();
} }
@ -144,54 +148,68 @@ var async = require('async'),
return callback(new Error('no-privileges')); return callback(new Error('no-privileges'));
} }
posts.create(uid, tid, content, function(err, postData) { user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
if(err) { if(err) {
return callback(err, null); return callback(err);
} else if(!postData) {
callback(new Error('reply-error'), null);
} }
posts.getCidByPid(postData.pid, function(err, cid) { if(!lastposttime) {
lastposttime = 0;
}
if (Date.now() - lastposttime < meta.config.postDelay * 1000) {
return callback(new Error('too-many-posts'), null);
}
posts.create(uid, tid, content, function(err, postData) {
if(err) { if(err) {
return callback(err, null); return callback(err);
} else if(!postData) {
callback(new Error('reply-error'), null);
} }
db.delete('cid:' + cid + ':read_by_uid', function(err) { posts.getCidByPid(postData.pid, function(err, cid) {
Topics.markAsUnreadForAll(tid, function(err) { if(err) {
if(err) { return callback(err, null);
return callback(err, null); }
}
db.delete('cid:' + cid + ':read_by_uid', function(err) {
Topics.markAsUnreadForAll(tid, function(err) {
if(err) {
return callback(err, null);
}
Topics.markAsRead(tid, uid); Topics.markAsRead(tid, uid);
Topics.pushUnreadCount(); Topics.pushUnreadCount();
});
}); });
}); });
});
db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) { db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) {
var now = Date.now(); var now = Date.now();
if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) { if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) {
feed.updateTopic(tid); feed.updateTopic(tid);
db.setObjectField('tid:lastFeedUpdate', tid, now); db.setObjectField('tid:lastFeedUpdate', tid, now);
} }
}); });
feed.updateRecent(); feed.updateRecent();
threadTools.notifyFollowers(tid, uid); threadTools.notifyFollowers(tid, uid);
user.sendPostNotificationToFollowers(uid, tid, postData.pid); user.sendPostNotificationToFollowers(uid, tid, postData.pid);
posts.addUserInfoToPost(postData, function(err) { posts.addUserInfoToPost(postData, function(err) {
if(err) { if(err) {
return callback(err, null); return callback(err, null);
} }
postData.favourited = false; postData.favourited = false;
postData.display_moderator_tools = true; postData.display_moderator_tools = true;
postData.relativeTime = new Date(postData.timestamp).toISOString(); postData.relativeTime = new Date(postData.timestamp).toISOString();
callback(null, postData); callback(null, postData);
});
}); });
}); });
}); });

Loading…
Cancel
Save