From 8119b8c4ae3b7ca52c38f6b8b5080b8658880506 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Mon, 3 Apr 2017 14:40:03 -0700
Subject: [PATCH] `filter:teasers.get` provided with `uid`
---
src/categories/recentreplies.js | 6 +++---
src/topics.js | 2 +-
src/topics/teaser.js | 24 ++++++++++++++++++------
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index c38fec527e..564d05d673 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -86,7 +86,7 @@ module.exports = function (Categories) {
privileges.topics.filterTids('read', tids, uid, next);
},
function (tids, next) {
- getTopics(tids, next);
+ getTopics(tids, uid, next);
},
function (topics, next) {
assignTopicsToCategories(categoryData, topics);
@@ -98,7 +98,7 @@ module.exports = function (Categories) {
], callback);
};
- function getTopics(tids, callback) {
+ function getTopics(tids, uid, callback) {
var topicData;
async.waterfall([
function (next) {
@@ -119,7 +119,7 @@ module.exports = function (Categories) {
async.parallel({
categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']),
- teasers: async.apply(topics.getTeasers, _topicData),
+ teasers: async.apply(topics.getTeasers, _topicData, uid),
}, next);
},
function (results, next) {
diff --git a/src/topics.js b/src/topics.js
index 164200016d..ed7deacc2e 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -126,7 +126,7 @@ var social = require('./social');
Topics.getUserBookmarks(tids, uid, next);
},
teasers: function (next) {
- Topics.getTeasers(topics, next);
+ Topics.getTeasers(topics, uid, next);
},
tags: function (next) {
Topics.getTopicsTagsObjects(tids, next);
diff --git a/src/topics/teaser.js b/src/topics/teaser.js
index aa64d7780f..b990b608d1 100644
--- a/src/topics/teaser.js
+++ b/src/topics/teaser.js
@@ -12,7 +12,11 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils');
module.exports = function (Topics) {
- Topics.getTeasers = function (topics, callback) {
+ Topics.getTeasers = function (topics, uid, callback) {
+ if (typeof uid === 'function') {
+ callback = uid;
+ uid = 0;
+ }
if (!Array.isArray(topics) || !topics.length) {
return callback(null, []);
}
@@ -94,7 +98,7 @@ module.exports = function (Topics) {
return tidToPost[topic.tid];
});
- plugins.fireHook('filter:teasers.get', { teasers: teasers }, next);
+ plugins.fireHook('filter:teasers.get', { teasers: teasers, uid: uid }, next);
},
function (data, next) {
next(null, data.teasers);
@@ -102,7 +106,11 @@ module.exports = function (Topics) {
], callback);
};
- Topics.getTeasersByTids = function (tids, callback) {
+ Topics.getTeasersByTids = function (tids, uid, callback) {
+ if (typeof uid === 'function') {
+ callback = uid;
+ uid = 0;
+ }
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
@@ -111,13 +119,17 @@ module.exports = function (Topics) {
Topics.getTopicsFields(tids, ['tid', 'postcount', 'teaserPid'], next);
},
function (topics, next) {
- Topics.getTeasers(topics, next);
+ Topics.getTeasers(topics, uid, next);
},
], callback);
};
- Topics.getTeaser = function (tid, callback) {
- Topics.getTeasersByTids([tid], function (err, teasers) {
+ Topics.getTeaser = function (tid, uid, callback) {
+ if (typeof uid === 'function') {
+ callback = uid;
+ uid = 0;
+ }
+ Topics.getTeasersByTids([tid], uid, function (err, teasers) {
callback(err, Array.isArray(teasers) && teasers.length ? teasers[0] : null);
});
};