mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
refactor: standardization; onNewPost internal method to return a superset of post summary
... so as to not require an additional call in internal topics API to call post summary again for a standardized response
This commit is contained in:
@@ -61,7 +61,12 @@ post:
|
|||||||
status:
|
status:
|
||||||
$ref: ../../components/schemas/Status.yaml#/Status
|
$ref: ../../components/schemas/Status.yaml#/Status
|
||||||
response:
|
response:
|
||||||
$ref: ../../components/schemas/PostObject.yaml#/PostObject
|
allOf:
|
||||||
|
- $ref: ../../components/schemas/PostObject.yaml#/PostObject
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
index:
|
||||||
|
type: number
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- topics
|
- topics
|
||||||
|
|||||||
@@ -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 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 response
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
posts: [postData],
|
posts: [postData],
|
||||||
@@ -123,9 +122,9 @@ topicsAPI.reply = async function (caller, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
socketHelpers.notifyNew(caller.uid, 'newPost', result);
|
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) {
|
topicsAPI.delete = async function (caller, data) {
|
||||||
|
|||||||
@@ -228,35 +228,22 @@ module.exports = function (Topics) {
|
|||||||
return postData;
|
return postData;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function onNewPost(postData, data) {
|
async function onNewPost({ pid, tid }, { uid }) {
|
||||||
const { tid, uid } = postData;
|
const postData = (await posts.getPostSummaryByPids([pid], uid, {})).pop();
|
||||||
await Topics.markAsRead([tid], uid);
|
await Promise.all([
|
||||||
const [
|
|
||||||
userInfo,
|
|
||||||
topicInfo,
|
|
||||||
] = await Promise.all([
|
|
||||||
posts.getUserInfoForPosts([postData.uid], uid),
|
|
||||||
Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid', 'scheduled', 'tags']),
|
|
||||||
Topics.addParentPosts([postData]),
|
Topics.addParentPosts([postData]),
|
||||||
Topics.syncBacklinks(postData),
|
Topics.syncBacklinks(postData),
|
||||||
posts.parsePost(postData),
|
Topics.markAsRead([tid], uid),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
postData.user = userInfo[0];
|
// Returned data is a superset of post summary data
|
||||||
postData.topic = topicInfo;
|
postData.index = postData.topic.postcount - 1;
|
||||||
postData.index = topicInfo.postcount - 1;
|
|
||||||
|
|
||||||
posts.overrideGuestHandle(postData, data.handle);
|
|
||||||
|
|
||||||
postData.votes = 0;
|
|
||||||
postData.bookmarked = false;
|
postData.bookmarked = false;
|
||||||
postData.display_edit_tools = true;
|
postData.display_edit_tools = true;
|
||||||
postData.display_delete_tools = true;
|
postData.display_delete_tools = true;
|
||||||
postData.display_moderator_tools = true;
|
postData.display_moderator_tools = true;
|
||||||
postData.display_move_tools = true;
|
postData.display_move_tools = true;
|
||||||
postData.selfPost = false;
|
postData.selfPost = false;
|
||||||
postData.timestampISO = utils.toISOString(postData.timestamp);
|
|
||||||
postData.topic.title = String(postData.topic.title);
|
|
||||||
|
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user