Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added boolean field 'endorsed' to Post #31

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/openapi/components/schemas/PostObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PostObject:
type: number
votes:
type: number
endorsed:
type: boolean
timestampISO:
type: string
description: An ISO 8601 formatted date string (complementing `timestamp`)
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/read/topic/topic_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ get:
type: number
downvotes:
type: number
endorsed:
type: number
bookmarks:
type: number
deleterUid:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/write/posts/pid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ get:
type: number
votes:
type: number
endorsed:
type: number
timestampISO:
type: string
description: An ISO 8601 formatted date string (complementing `timestamp`)
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/write/posts/pid/replies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ get:
type: number
bookmarks:
type: number
endorsed:
type: number
deleterUid:
type: number
edited:
Expand Down
2 changes: 2 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function (Posts) {
const content = data.content.toString();
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;
const endorsed = data.endorsed || false;

if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
Expand All @@ -35,6 +36,7 @@ module.exports = function (Posts) {
tid: tid,
content: content,
timestamp: timestamp,
endorsed: endorsed,
};

if (data.toPid) {
Expand Down
6 changes: 5 additions & 1 deletion src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const utils = require('../utils');

const intFields = [
'uid', 'pid', 'tid', 'deleted', 'timestamp',
'upvotes', 'downvotes', 'deleterUid', 'edited',
'upvotes', 'downvotes', 'endorsed', 'deleterUid', 'edited',
'replies', 'bookmarks',
];

Expand Down Expand Up @@ -67,5 +67,9 @@ function modifyPost(post, fields) {
if (post.hasOwnProperty('edited')) {
post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : '';
}

if (post.hasOwnProperty('endorsed')) {
post.endorsed = post.endorsed ? post.endorsed : false;
}
}
}
2 changes: 1 addition & 1 deletion src/posts/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (Posts) {
deleted: isDeleting ? 1 : 0,
deleterUid: isDeleting ? uid : 0,
});
const postData = await Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp']);
const postData = await Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'endorsed', 'timestamp']);
const topicData = await topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned']);
postData.cid = topicData.cid;
await Promise.all([
Expand Down
3 changes: 2 additions & 1 deletion src/posts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function (Posts) {
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];

const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'endorsed', 'replies', 'handle'].concat(options.extraFields);

let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
Expand Down Expand Up @@ -51,6 +51,7 @@ module.exports = function (Posts) {
post.category = post.topic && cidToCategory[post.topic.cid];
post.isMainPost = post.topic && post.pid === post.topic.mainPid;
post.deleted = post.deleted === 1;
post.endorsed = post.endorsed === true;
post.timestampISO = utils.toISOString(post.timestamp);
});

Expand Down
2 changes: 1 addition & 1 deletion src/posts/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module.exports = function (Posts) {
throw new Error('[[error:no-user]]');
}
let postData = await Posts.getPostsFields(pids, [
'pid', 'tid', 'uid', 'content', 'deleted', 'timestamp', 'upvotes', 'downvotes',
'pid', 'tid', 'uid', 'content', 'deleted', 'endorsed', 'timestamp', 'upvotes', 'downvotes',
]);
postData = postData.filter(p => p.pid && p.uid !== parseInt(toUid, 10));
pids = postData.map(p => p.pid);
Expand Down
2 changes: 1 addition & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function filterAndSort(pids, data) {
}

async function getMatchedPosts(pids, data) {
const postFields = ['pid', 'uid', 'tid', 'timestamp', 'deleted', 'upvotes', 'downvotes'];
const postFields = ['pid', 'uid', 'tid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'endorsed'];

let postsData = await posts.getPostsFields(pids, postFields);
postsData = postsData.filter(post => post && !post.deleted);
Expand Down
3 changes: 3 additions & 0 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ module.exports = function (Topics) {
const tid = await Topics.create(data);

let postData = data;
if (postData.endorsed === undefined) {
postData.endorsed = false;
}
postData.tid = tid;
postData.ip = data.req ? data.req.ip : null;
postData.isMain = true;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = function (Topics) {
if (!forceScheduled && topicData.scheduled) {
throw new Error('[[error:cant-move-posts-to-scheduled]]');
}
const postData = await posts.getPostFields(pid, ['tid', 'uid', 'timestamp', 'upvotes', 'downvotes']);
const postData = await posts.getPostFields(pid, ['tid', 'uid', 'timestamp', 'upvotes', 'downvotes', 'endorsed']);
if (!postData || !postData.tid) {
throw new Error('[[error:no-post]]');
}
Expand Down