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