fix: post indices if there is a blocked user in topic

isekai-main
Barış Soner Uşaklı 3 years ago
parent 3b72ff8742
commit f9279b636b

@ -45,8 +45,7 @@ Posts.getPostsByPids = async function (pids, uid) {
return [];
}
let posts = await Posts.getPostsData(pids);
posts = await Promise.all(posts.map(p => Posts.parsePost(p)));
posts = await user.blocks.filter(uid, posts);
posts = await Promise.all(posts.map(Posts.parsePost));
const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid });
if (!data || !Array.isArray(data.posts)) {
return [];

@ -2,12 +2,14 @@
'use strict';
const topics = require('../topics');
const user = require('../user');
const utils = require('../utils');
module.exports = function (Posts) {
Posts.getPostsFromSet = async function (set, start, stop, uid, reverse) {
const pids = await Posts.getPidsFromSet(set, start, stop, reverse);
return await Posts.getPostsByPids(pids, uid);
const posts = await Posts.getPostsByPids(pids, uid);
return await user.blocks.filter(uid, posts);
};
Posts.isMain = async function (pids) {

@ -98,6 +98,7 @@ SocketPosts.getReplies = async function (socket, pid) {
postData = await topics.addPostData(postData, socket.uid);
postData.forEach((postData, index) => posts.modifyPostByPrivilege(postData, postPrivileges[index]));
postData = postData.filter((postData, index) => postData && postPrivileges[index].read);
postData = await user.blocks.filter(socket.uid, postData);
return postData;
};

@ -252,7 +252,8 @@ Topics.getMainPosts = async function (tids, uid) {
};
async function getMainPosts(mainPids, uid) {
const postData = await posts.getPostsByPids(mainPids, uid);
let postData = await posts.getPostsByPids(mainPids, uid);
postData = await user.blocks.filter(uid, postData);
postData.forEach((post) => {
if (post) {
post.index = 0;

@ -44,7 +44,7 @@ module.exports = function (Topics) {
if (topicData.mainPid && start === 0) {
pids.unshift(topicData.mainPid);
}
const postData = await posts.getPostsByPids(pids, uid);
let postData = await posts.getPostsByPids(pids, uid);
if (!postData.length) {
return [];
}
@ -55,7 +55,7 @@ module.exports = function (Topics) {
}
Topics.calculatePostIndices(replies, repliesStart);
postData = await user.blocks.filter(uid, postData);
await addEventStartEnd(postData, set, reverse, topicData);
const result = await plugins.hooks.fire('filter:topic.getPosts', {
topic: topicData,

Loading…
Cancel
Save