mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #3611
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
/* globals socket, ajaxify, app, define */
|
||||
/* globals socket, ajaxify, app, define, config */
|
||||
|
||||
define('search', ['navigator', 'translator'], function(nav, translator) {
|
||||
|
||||
@@ -77,7 +77,7 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
|
||||
term: term
|
||||
}, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
if (Array.isArray(pids)) {
|
||||
@@ -126,8 +126,13 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
|
||||
if (Search.current.results.length > 0) {
|
||||
topicSearchEl.find('.count').html((index+1) + ' / ' + Search.current.results.length);
|
||||
topicSearchEl.find('.prev, .next').removeAttr('disabled');
|
||||
socket.emit('posts.getPidIndex', Search.current.results[index], function(err, postIndex) {
|
||||
nav.scrollToPost(postIndex-1, true); // why -1? Ask @barisusakli
|
||||
var data = {
|
||||
pid: Search.current.results[index],
|
||||
tid: Search.current.tid,
|
||||
topicPostSort: config.topicPostSort
|
||||
};
|
||||
socket.emit('posts.getPidIndex', data, function(err, postIndex) {
|
||||
nav.scrollToPost(postIndex, true);
|
||||
});
|
||||
} else {
|
||||
translator.translate('[[search:no-matches]]', function(text) {
|
||||
|
||||
20
src/posts.js
20
src/posts.js
@@ -168,25 +168,13 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getPidIndex = function(pid, uid, callback) {
|
||||
async.parallel({
|
||||
settings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
tid: function(next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
var set = results.settings.topicPostSort === 'most_votes' ? 'tid:' + results.tid + ':posts:votes' : 'tid:' + results.tid + ':posts';
|
||||
Posts.getPidIndex = function(pid, tid, topicPostSort, callback) {
|
||||
var set = topicPostSort === 'most_votes' ? 'tid:' + tid + ':posts:votes' : 'tid:' + tid + ':posts';
|
||||
db.sortedSetRank(set, pid, function(err, index) {
|
||||
if (!utils.isNumber(index)) {
|
||||
return callback(err, 1);
|
||||
return callback(err, 0);
|
||||
}
|
||||
callback(err, parseInt(index, 10) + 2);
|
||||
});
|
||||
callback(err, parseInt(index, 10) + 1);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -579,7 +579,7 @@ function loadMorePosts(set, uid, data, callback) {
|
||||
}
|
||||
|
||||
SocketPosts.getRecentPosts = function(socket, data, callback) {
|
||||
if(!data || !data.count) {
|
||||
if (!data || !data.count) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
@@ -590,8 +590,11 @@ SocketPosts.getCategory = function(socket, pid, callback) {
|
||||
posts.getCidByPid(pid, callback);
|
||||
};
|
||||
|
||||
SocketPosts.getPidIndex = function(socket, pid, callback) {
|
||||
posts.getPidIndex(pid, socket.uid, callback);
|
||||
SocketPosts.getPidIndex = function(socket, data, callback) {
|
||||
if (!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
posts.getPidIndex(data.pid, data.tid, data.topicPostSort, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketPosts;
|
||||
|
||||
@@ -131,7 +131,10 @@ module.exports = function(Topics) {
|
||||
Topics.create({uid: data.uid, title: data.title, cid: data.cid, thumb: data.thumb, tags: data.tags, timestamp: data.timestamp}, next);
|
||||
},
|
||||
function(tid, next) {
|
||||
Topics.reply({uid: data.uid, tid: tid, handle: data.handle, content: data.content, timestamp: data.timestamp, req: data.req}, next);
|
||||
posts.create({uid: data.uid, tid: tid, handle: data.handle, content: data.content, timestamp: data.timestamp, ip: data.req ? data.req.ip : null}, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
onNewPost(postData, data, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
async.parallel({
|
||||
@@ -163,6 +166,7 @@ module.exports = function(Topics) {
|
||||
data.topicData = data.topicData[0];
|
||||
data.topicData.unreplied = 1;
|
||||
data.topicData.mainPost = data.postData;
|
||||
data.postData.index = 0;
|
||||
|
||||
plugins.fireHook('action:topic.post', data.topicData);
|
||||
|
||||
@@ -232,8 +236,40 @@ module.exports = function(Topics) {
|
||||
function(next) {
|
||||
posts.create({uid: uid, tid: tid, handle: data.handle, content: content, toPid: data.toPid, timestamp: data.timestamp, ip: data.req ? data.req.ip : null}, next);
|
||||
},
|
||||
function(data, next) {
|
||||
postData = data;
|
||||
function(_postData, next) {
|
||||
postData = _postData;
|
||||
onNewPost(postData, data, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
function(settings, next) {
|
||||
if (settings.followTopicsOnReply) {
|
||||
Topics.follow(postData.tid, uid);
|
||||
}
|
||||
|
||||
posts.getPidIndex(postData.pid, postData.tid, settings.topicPostSort, next);
|
||||
},
|
||||
function(postIndex, next) {
|
||||
postData.index = postIndex;
|
||||
|
||||
if (parseInt(uid, 10)) {
|
||||
Topics.notifyFollowers(postData, uid);
|
||||
user.setUserField(uid, 'lastonline', Date.now());
|
||||
}
|
||||
|
||||
plugins.fireHook('action:topic.reply', postData);
|
||||
|
||||
next(null, postData);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
function onNewPost(postData, data, callback) {
|
||||
var tid = postData.tid;
|
||||
var uid = postData.uid;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
Topics.markAsUnreadForAll(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
@@ -247,12 +283,6 @@ module.exports = function(Topics) {
|
||||
topicInfo: function(next) {
|
||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount'], next);
|
||||
},
|
||||
settings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
postIndex: function(next) {
|
||||
posts.getPidIndex(postData.pid, uid, next);
|
||||
},
|
||||
content: function(next) {
|
||||
posts.parsePost(postData, next);
|
||||
}
|
||||
@@ -267,31 +297,18 @@ module.exports = function(Topics) {
|
||||
postData.user.username = validator.escape(data.handle);
|
||||
}
|
||||
|
||||
if (results.settings.followTopicsOnReply) {
|
||||
Topics.follow(postData.tid, uid);
|
||||
}
|
||||
postData.index = results.postIndex - 1;
|
||||
postData.favourited = false;
|
||||
postData.votes = 0;
|
||||
postData.display_moderator_tools = true;
|
||||
postData.display_move_tools = true;
|
||||
postData.selfPost = false;
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
|
||||
if (parseInt(uid, 10) && data.req) {
|
||||
Topics.notifyFollowers(postData, uid);
|
||||
user.setUserField(uid, 'lastonline', Date.now());
|
||||
}
|
||||
|
||||
if (postData.index > 0) {
|
||||
plugins.fireHook('action:topic.reply', postData);
|
||||
}
|
||||
|
||||
postData.topic.title = validator.escape(postData.topic.title);
|
||||
|
||||
next(null, postData);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
}
|
||||
|
||||
function checkTitleLength(title, callback) {
|
||||
if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
||||
|
||||
@@ -46,6 +46,9 @@ module.exports = function(Topics) {
|
||||
|
||||
Topics.follow = function(tid, uid, callback) {
|
||||
callback = callback || function() {};
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback();
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Topics.exists(tid, next);
|
||||
|
||||
Reference in New Issue
Block a user