From 3a870360c49eb6db2eb566413704682550b3e841 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 21 Feb 2024 15:15:59 -0500 Subject: [PATCH] fix: revert introduction of toPid into post intFields, manually cast toPid as int in getPostSummaryByPids if present and numeric --- src/posts/data.js | 4 ++-- src/posts/summary.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index 20f1df2991..8edd4096e6 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -8,7 +8,7 @@ const activitypub = require('../activitypub'); const utils = require('../utils'); const intFields = [ - 'uid', 'pid', 'tid', 'toPid', 'deleted', 'timestamp', + 'uid', 'pid', 'tid', 'deleted', 'timestamp', 'upvotes', 'downvotes', 'deleterUid', 'edited', 'replies', 'bookmarks', ]; @@ -62,7 +62,7 @@ function modifyPost(post, fields) { const _intFields = [...intFields]; if (post) { - ['pid', 'uid', 'tid', 'toPid'].forEach((prop) => { + ['pid', 'uid', 'tid'].forEach((prop) => { if ( post.hasOwnProperty(prop) && (activitypub.helpers.isUri(post[prop]) || validator.isUUID(String(post[prop]))) diff --git a/src/posts/summary.js b/src/posts/summary.js index a07b8e2c67..6865372cef 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -44,6 +44,10 @@ module.exports = function (Posts) { if (!uidToUser.hasOwnProperty(post.uid)) { post.uid = 0; } + + // toPid is nullable so it is casted separately + post.toPid = utils.isNumber(post.toPid) ? parseInt(post.toPid, 10) : post.toPid; + post.user = uidToUser[post.uid]; Posts.overrideGuestHandle(post, post.handle); post.handle = undefined;