diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 3b9e0d89972c6927376e9acdf13e5c77901c5441..e1138c3edc8e5a836dc7b0dc056f9ea175dd0161 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -103,23 +103,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } - // Get 'in_reply_post_id' parameter - const [inReplyToPostId, inReplyToPostIdErr] = $(params.reply_id).optional.id().$; - if (inReplyToPostIdErr) return rej('invalid in_reply_post_id'); + // Get 'reply_id' parameter + const [replyId, replyIdErr] = $(params.reply_id).optional.id().$; + if (replyIdErr) return rej('invalid reply_id'); - let inReplyToPost: IPost = null; - if (inReplyToPostId !== undefined) { + let reply: IPost = null; + if (replyId !== undefined) { // Fetch reply - inReplyToPost = await Post.findOne({ - _id: inReplyToPostId + reply = await Post.findOne({ + _id: replyId }); - if (inReplyToPost === null) { + if (reply === null) { return rej('in reply to post is not found'); } // 返信対象ãŒå¼•ç”¨ã§ãªã„Repostã ã£ãŸã‚‰ã‚¨ãƒ©ãƒ¼ - if (inReplyToPost.repost_id && !inReplyToPost.text && !inReplyToPost.media_ids) { + if (reply.repost_id && !reply.text && !reply.media_ids) { return rej('cannot reply to repost'); } } @@ -140,7 +140,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } // 返信対象ã®æŠ•ç¨¿ãŒã“ã®ãƒãƒ£ãƒ³ãƒãƒ«ã˜ã‚ƒãªã‹ã£ãŸã‚‰ãƒ€ãƒ¡ - if (inReplyToPost && !channelId.equals(inReplyToPost.channel_id)) { + if (reply && !channelId.equals(reply.channel_id)) { return rej('ãƒãƒ£ãƒ³ãƒãƒ«å†…部ã‹ã‚‰ãƒãƒ£ãƒ³ãƒãƒ«å¤–部ã®æŠ•ç¨¿ã«è¿”ä¿¡ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“'); } @@ -155,7 +155,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } else { // 返信対象ã®æŠ•ç¨¿ãŒãƒãƒ£ãƒ³ãƒãƒ«ã¸ã®æŠ•ç¨¿ã ã£ãŸã‚‰ãƒ€ãƒ¡ - if (inReplyToPost && inReplyToPost.channel_id != null) { + if (reply && reply.channel_id != null) { return rej('ãƒãƒ£ãƒ³ãƒãƒ«å¤–部ã‹ã‚‰ãƒãƒ£ãƒ³ãƒãƒ«å†…部ã®æŠ•ç¨¿ã«è¿”ä¿¡ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“'); } @@ -197,7 +197,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { media_ids: (user.latest_post.media_ids || []).map(id => id.toString()) }, { text: text, - reply: inReplyToPost ? inReplyToPost._id.toString() : null, + reply: reply ? reply._id.toString() : null, repost: repost ? repost._id.toString() : null, media_ids: (files || []).map(file => file._id.toString()) })) { @@ -211,7 +211,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { channel_id: channel ? channel._id : undefined, index: channel ? channel.index + 1 : undefined, media_ids: files ? files.map(file => file._id) : undefined, - reply_id: inReplyToPost ? inReplyToPost._id : undefined, + reply_id: reply ? reply._id : undefined, repost_id: repost ? repost._id : undefined, poll: poll, text: text, @@ -287,23 +287,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { }); // If has in reply to post - if (inReplyToPost) { + if (reply) { // Increment replies count - Post.update({ _id: inReplyToPost._id }, { + Post.update({ _id: reply._id }, { $inc: { replies_count: 1 } }); // 自分自身ã¸ã®ãƒªãƒ—ライã§ãªã„é™ã‚Šã¯é€šçŸ¥ã‚’ä½œæˆ - notify(inReplyToPost.user_id, user._id, 'reply', { + notify(reply.user_id, user._id, 'reply', { post_id: post._id }); // Fetch watchers Watching .find({ - post_id: inReplyToPost._id, + post_id: reply._id, user_id: { $ne: user._id }, // 削除ã•ã‚ŒãŸãƒ‰ã‚ュメントã¯é™¤ã deleted_at: { $exists: false } @@ -323,10 +323,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // ã“ã®æŠ•ç¨¿ã‚’Watchã™ã‚‹ // TODO: ユーザーãŒã€Œè¿”ä¿¡ã—ãŸã¨ãã«è‡ªå‹•ã§Watchã™ã‚‹ã€è¨å®šã‚’ // オフã«ã—ã¦ã„ãŸå ´åˆã¯ã—ãªã„ - watch(user._id, inReplyToPost); + watch(user._id, reply); // Add mention - addMention(inReplyToPost.user_id, 'reply'); + addMention(reply.user_id, 'reply'); } // If it is repost @@ -427,7 +427,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { if (mentionee == null) return; // æ—¢ã«è¨€åŠã•ã‚ŒãŸãƒ¦ãƒ¼ã‚¶ãƒ¼ã«å¯¾ã™ã‚‹è¿”信や引用repostã®å ´åˆã‚‚無視 - if (inReplyToPost && inReplyToPost.user_id.equals(mentionee._id)) return; + if (reply && reply.user_id.equals(mentionee._id)) return; if (repost && repost.user_id.equals(mentionee._id)) return; // Add mention