mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
use topic.getMainPids
This commit is contained in:
@@ -85,16 +85,14 @@ function searchInContent(query, data, callback) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
getMainPids(results.tids, next);
|
topics.getMainPids(results.tids, next);
|
||||||
},
|
},
|
||||||
function(mainPids, next) {
|
function(mainPids, next) {
|
||||||
results.pids.forEach(function(pid) {
|
results.pids = mainPids.concat(results.pids).filter(function(pid, index, array) {
|
||||||
if (mainPids.indexOf(pid.toString()) === -1) {
|
return pid && array.indexOf(pid) === index;
|
||||||
mainPids.push(pid);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
privileges.posts.filter('read', mainPids, data.uid, next);
|
privileges.posts.filter('read', results.pids, data.uid, next);
|
||||||
},
|
},
|
||||||
function(pids, next) {
|
function(pids, next) {
|
||||||
filterAndSort(pids, data, results.searchCategories, next);
|
filterAndSort(pids, data, results.searchCategories, next);
|
||||||
@@ -460,22 +458,6 @@ function searchInTags(query, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMainPids(tids, callback) {
|
|
||||||
if (!Array.isArray(tids) || !tids.length) {
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
topics.getTopicsFields(tids, ['mainPid'], function(err, topics) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
topics = topics.map(function(topic) {
|
|
||||||
return topic && topic.mainPid && topic.mainPid.toString();
|
|
||||||
}).filter(Boolean);
|
|
||||||
callback(null, topics);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
search.searchQuery = function(index, query, callback) {
|
search.searchQuery = function(index, query, callback) {
|
||||||
plugins.fireHook('filter:search.query', {
|
plugins.fireHook('filter:search.query', {
|
||||||
index: index,
|
index: index,
|
||||||
|
|||||||
@@ -287,13 +287,17 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getMainPids = function(tids, callback) {
|
Topics.getMainPids = function(tids, callback) {
|
||||||
|
if (!Array.isArray(tids) || !tids.length) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
|
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mainPids = topicData.map(function(topic) {
|
var mainPids = topicData.map(function(topic) {
|
||||||
return topic ? topic.mainPid : null;
|
return topic && topic.mainPid;
|
||||||
});
|
});
|
||||||
callback(null, mainPids);
|
callback(null, mainPids);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user