Skip to content

Node.js based forum software built for the modern web

fix: filter undefined posts/topics

Barış Soner Uşaklıdb291ecde11a
diff --git a/src/topics/scheduled.js b/src/topics/scheduled.js
index 129f4113f3..9bf325231a 100644
--- a/src/topics/scheduled.js
+++ b/src/topics/scheduled.js
@@ -111,7 +111,9 @@ async function sendNotifications(uids, topicsData) {
const userData = await user.getUsersData(uids);
const uidToUserData = Object.fromEntries(uids.map((uid, idx) => [uid, userData[idx]]));
- const postsData = await posts.getPostsData(topicsData.map(t => t && t.mainPid));
+ let postsData = await posts.getPostsData(topicsData.map(t => t && t.mainPid));
+ topicsData = topicsData.filter((t, i) => t && postsData[i]);
+ postsData = postsData.filter(Boolean);
postsData.forEach((postData, idx) => {
if (postData) {
postData.user = uidToUserData[topicsData[idx].uid];