mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
some changes to related code
This commit is contained in:
@@ -192,25 +192,22 @@ var async = require('async'),
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function(results, next) {
|
function(results, next) {
|
||||||
if (plugins.hasListeners('filter:topic.getRelatedTopics')) {
|
|
||||||
plugins.fireHook('filter:topic.getRelatedTopics', results, next);
|
|
||||||
} else {
|
|
||||||
Topics.getRelatedTopics(results, next);
|
|
||||||
}
|
|
||||||
}, function(results, next) {
|
|
||||||
topicData.posts = results.posts;
|
topicData.posts = results.posts;
|
||||||
topicData.category = results.category;
|
topicData.category = results.category;
|
||||||
topicData.thread_tools = results.threadTools.tools;
|
topicData.thread_tools = results.threadTools.tools;
|
||||||
topicData.tags = results.tags;
|
topicData.tags = results.tags;
|
||||||
topicData.isFollowing = results.isFollowing[0];
|
topicData.isFollowing = results.isFollowing[0];
|
||||||
topicData.bookmark = results.bookmark;
|
topicData.bookmark = results.bookmark;
|
||||||
topicData.related = results.related || [];
|
|
||||||
|
|
||||||
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
||||||
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
|
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
|
||||||
topicData.locked = parseInt(topicData.locked, 10) === 1;
|
topicData.locked = parseInt(topicData.locked, 10) === 1;
|
||||||
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
|
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
|
||||||
|
|
||||||
|
Topics.getRelatedTopics(topicData, uid, next);
|
||||||
|
},
|
||||||
|
function(related, next) {
|
||||||
|
topicData.related = related || [];
|
||||||
plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, next);
|
plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, next);
|
||||||
},
|
},
|
||||||
function(data, next) {
|
function(data, next) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ var async = require('async'),
|
|||||||
|
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
user = require('../user'),
|
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
plugins = require('../plugins');
|
plugins = require('../plugins');
|
||||||
|
|
||||||
@@ -323,43 +322,33 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getRelatedTopics = function(topicData, callback) {
|
Topics.getRelatedTopics = function(topicData, uid, callback) {
|
||||||
var maximumTopics = typeof meta.config.maximumRelatedTopics !== 'undefined' ? parseInt(meta.config.maximumRelatedTopics, 10) : 5;
|
if (plugins.hasListeners('filter:topic.getRelatedTopics')) {
|
||||||
|
return plugins.fireHook('filter:topic.getRelatedTopics', {topic: topicData, uid: uid}, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
var maximumTopics = parseInt(meta.config.maximumRelatedTopics, 10) || 5;
|
||||||
|
|
||||||
if (!topicData.tags.length || maximumTopics === 0) {
|
if (!topicData.tags.length || maximumTopics === 0) {
|
||||||
return callback(null, topicData);
|
return callback(null, topicData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var related = [];
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
user.isAdministrator(topicData.threadTools.uid, function(err, isAdministrator) {
|
async.map(topicData.tags, function (tag, next) {
|
||||||
async.each(topicData.tags, function(tag, next) {
|
Topics.getTagTids(tag.value, 0, 5, next);
|
||||||
tag = tag.value;
|
}, next);
|
||||||
|
},
|
||||||
Topics.getTagTids(tag, 0, 5, function(err, tids) {
|
function (tids, next) {
|
||||||
Topics.getTopics(tids, topicData.threadTools.uid, function(err, topics) {
|
tids = _.shuffle(_.unique(_.flatten(tids))).slice(0, maximumTopics);
|
||||||
related = related.concat(topics.filter(function(topic) {
|
Topics.getTopics(tids, uid, next);
|
||||||
var doesntOwnTopic = parseInt(topic.uid, 10) !== parseInt(topicData.threadTools.uid, 10);
|
},
|
||||||
var isntSameTopic = parseInt(topic.tid, 10) !== parseInt(topicData.threadTools.topic.tid, 10);
|
function (topics, next) {
|
||||||
|
topics = topics.filter(function(topic) {
|
||||||
return doesntOwnTopic && isntSameTopic;
|
return topic && !topic.deleted && parseInt(topic.uid, 10) !== parseInt(uid, 10);
|
||||||
}));
|
|
||||||
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, function(err) {
|
|
||||||
if (!isAdministrator) {
|
|
||||||
related = related.filter(function(topic) {
|
|
||||||
return topic && !topic.deleted;
|
|
||||||
});
|
});
|
||||||
|
next(null, topics);
|
||||||
}
|
}
|
||||||
|
], callback);
|
||||||
related = _.shuffle(related).slice(0, maximumTopics);
|
|
||||||
|
|
||||||
topicData.related = related;
|
|
||||||
callback(err, topicData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user