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 []; return [];
} }
let posts = await Posts.getPostsData(pids); let posts = await Posts.getPostsData(pids);
posts = await Promise.all(posts.map(p => Posts.parsePost(p))); posts = await Promise.all(posts.map(Posts.parsePost));
posts = await user.blocks.filter(uid, posts);
const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid }); const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid });
if (!data || !Array.isArray(data.posts)) { if (!data || !Array.isArray(data.posts)) {
return []; return [];

@ -2,12 +2,14 @@
'use strict'; 'use strict';
const topics = require('../topics'); const topics = require('../topics');
const user = require('../user');
const utils = require('../utils'); const utils = require('../utils');
module.exports = function (Posts) { module.exports = function (Posts) {
Posts.getPostsFromSet = async function (set, start, stop, uid, reverse) { Posts.getPostsFromSet = async function (set, start, stop, uid, reverse) {
const pids = await Posts.getPidsFromSet(set, start, stop, 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) { Posts.isMain = async function (pids) {

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

@ -252,7 +252,8 @@ Topics.getMainPosts = async function (tids, uid) {
}; };
async function getMainPosts(mainPids, 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) => { postData.forEach((post) => {
if (post) { if (post) {
post.index = 0; post.index = 0;

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

Loading…
Cancel
Save