Node.js based forum software built for the modern web
refactor: standardization; onNewPost internal method to return a superset of post summary
Julian Lam9357e7189877
diff --git a/public/openapi/write/topics/tid.yaml b/public/openapi/write/topics/tid.yamlindex 4c1acab3d6..2413e94631 100644--- a/public/openapi/write/topics/tid.yaml+++ b/public/openapi/write/topics/tid.yaml@@ -61,7 +61,12 @@ post:status:$ref: ../../components/schemas/Status.yaml#/Statusresponse:- $ref: ../../components/schemas/PostObject.yaml#/PostObject+ allOf:+ - $ref: ../../components/schemas/PostObject.yaml#/PostObject+ - type: object+ properties:+ index:+ type: numberdelete:tags:- topicsdiff --git a/src/api/topics.js b/src/api/topics.jsindex cc761e9542..4f63301c57 100644--- a/src/api/topics.js+++ b/src/api/topics.js@@ -107,7 +107,6 @@ topicsAPI.reply = async function (caller, data) {}const postData = await topics.reply(payload); // postData seems to be a subset of postObj, refactor?- const postObj = await posts.getPostSummaryByPids([postData.pid], caller.uid, {}); // standardized API responseconst result = {posts: [postData],@@ -123,9 +122,9 @@ topicsAPI.reply = async function (caller, data) {}socketHelpers.notifyNew(caller.uid, 'newPost', result);- activitypubApi.create.note(caller, { post: postObj[0] });+ activitypubApi.create.note(caller, { post: postData });- return postObj[0];+ return postData;};topicsAPI.delete = async function (caller, data) {diff --git a/src/topics/create.js b/src/topics/create.jsindex de3f8bd36c..20bd127587 100644--- a/src/topics/create.js+++ b/src/topics/create.js@@ -228,35 +228,22 @@ module.exports = function (Topics) {return postData;};- async function onNewPost(postData, data) {- const { tid, uid } = postData;- await Topics.markAsRead([tid], uid);- const [- userInfo,- topicInfo,- ] = await Promise.all([- posts.getUserInfoForPosts([postData.uid], uid),- Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid', 'scheduled', 'tags']),+ async function onNewPost({ pid, tid }, { uid }) {+ const postData = (await posts.getPostSummaryByPids([pid], uid, {})).pop();+ await Promise.all([Topics.addParentPosts([postData]),Topics.syncBacklinks(postData),- posts.parsePost(postData),+ Topics.markAsRead([tid], uid),]);- postData.user = userInfo[0];- postData.topic = topicInfo;- postData.index = topicInfo.postcount - 1;-- posts.overrideGuestHandle(postData, data.handle);-- postData.votes = 0;+ // Returned data is a superset of post summary data+ postData.index = postData.topic.postcount - 1;postData.bookmarked = false;postData.display_edit_tools = true;postData.display_delete_tools = true;postData.display_moderator_tools = true;postData.display_move_tools = true;postData.selfPost = false;- postData.timestampISO = utils.toISOString(postData.timestamp);- postData.topic.title = String(postData.topic.title);return postData;}