mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 07:10:30 +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:
|
||||
$ref: ../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
$ref: ../../components/schemas/PostObject.yaml#/PostObject
|
||||
allOf:
|
||||
- $ref: ../../components/schemas/PostObject.yaml#/PostObject
|
||||
- type: object
|
||||
properties:
|
||||
index:
|
||||
type: number
|
||||
delete:
|
||||
tags:
|
||||
- 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 postObj = await posts.getPostSummaryByPids([postData.pid], caller.uid, {}); // standardized API response
|
||||
|
||||
const 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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user