From d0a94cb86cf508c1ef8b30d5f29b86771ddf744d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 8 Sep 2016 15:59:10 +0300 Subject: [PATCH] filter:topics.searchTags --- src/topics/tags.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index 13dcd4b14d..50db8ccede 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -263,13 +263,29 @@ module.exports = function(Topics) { }; Topics.searchTags = function(data, callback) { + function done(matches) { + plugins.fireHook('filter:tags.search', {data: data, matches: matches}, function(err, data) { + callback(err, data ? data.matches : []); + }); + } + + if (!data || !data.query) { return callback(null, []); } + if (plugins.hasListeners('filter:topics.searchTags')) { + return plugins.fireHook('filter:topics.searchTags', {data: data}, function(err, data) { + if (err) { + return callback(err); + } + done(data.matches); + }); + } + db.getSortedSetRevRange('tags:topic:count', 0, -1, function(err, tags) { if (err) { - return callback(null, []); + return callback(err); } data.query = data.query.toLowerCase(); @@ -285,9 +301,7 @@ module.exports = function(Topics) { return a > b; }); - plugins.fireHook('filter:tags.search', {data: data, matches: matches}, function(err, data) { - callback(err, data ? data.matches : []); - }); + done(matches); }); };