This commit is contained in:
こぴなたみぽ 2017-11-01 10:45:01 +09:00
parent 60a7640eb1
commit 23282c2414
1 changed files with 20 additions and 20 deletions

View File

@ -103,23 +103,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
} }
} }
// Get 'in_reply_post_id' parameter // Get 'reply_id' parameter
const [inReplyToPostId, inReplyToPostIdErr] = $(params.reply_id).optional.id().$; const [replyId, replyIdErr] = $(params.reply_id).optional.id().$;
if (inReplyToPostIdErr) return rej('invalid in_reply_post_id'); if (replyIdErr) return rej('invalid reply_id');
let inReplyToPost: IPost = null; let reply: IPost = null;
if (inReplyToPostId !== undefined) { if (replyId !== undefined) {
// Fetch reply // Fetch reply
inReplyToPost = await Post.findOne({ reply = await Post.findOne({
_id: inReplyToPostId _id: replyId
}); });
if (inReplyToPost === null) { if (reply === null) {
return rej('in reply to post is not found'); return rej('in reply to post is not found');
} }
// 返信対象が引用でないRepostだったらエラー // 返信対象が引用でない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'); 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('チャンネル内部からチャンネル外部の投稿に返信することはできません'); return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
} }
@ -155,7 +155,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
} }
} else { } else {
// 返信対象の投稿がチャンネルへの投稿だったらダメ // 返信対象の投稿がチャンネルへの投稿だったらダメ
if (inReplyToPost && inReplyToPost.channel_id != null) { if (reply && reply.channel_id != null) {
return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません'); 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()) media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
}, { }, {
text: text, text: text,
reply: inReplyToPost ? inReplyToPost._id.toString() : null, reply: reply ? reply._id.toString() : null,
repost: repost ? repost._id.toString() : null, repost: repost ? repost._id.toString() : null,
media_ids: (files || []).map(file => file._id.toString()) 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, channel_id: channel ? channel._id : undefined,
index: channel ? channel.index + 1 : undefined, index: channel ? channel.index + 1 : undefined,
media_ids: files ? files.map(file => file._id) : 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, repost_id: repost ? repost._id : undefined,
poll: poll, poll: poll,
text: text, text: text,
@ -287,23 +287,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}); });
// If has in reply to post // If has in reply to post
if (inReplyToPost) { if (reply) {
// Increment replies count // Increment replies count
Post.update({ _id: inReplyToPost._id }, { Post.update({ _id: reply._id }, {
$inc: { $inc: {
replies_count: 1 replies_count: 1
} }
}); });
// 自分自身へのリプライでない限りは通知を作成 // 自分自身へのリプライでない限りは通知を作成
notify(inReplyToPost.user_id, user._id, 'reply', { notify(reply.user_id, user._id, 'reply', {
post_id: post._id post_id: post._id
}); });
// Fetch watchers // Fetch watchers
Watching Watching
.find({ .find({
post_id: inReplyToPost._id, post_id: reply._id,
user_id: { $ne: user._id }, user_id: { $ne: user._id },
// 削除されたドキュメントは除く // 削除されたドキュメントは除く
deleted_at: { $exists: false } deleted_at: { $exists: false }
@ -323,10 +323,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// この投稿をWatchする // この投稿をWatchする
// TODO: ユーザーが「返信したときに自動でWatchする」設定を // TODO: ユーザーが「返信したときに自動でWatchする」設定を
// オフにしていた場合はしない // オフにしていた場合はしない
watch(user._id, inReplyToPost); watch(user._id, reply);
// Add mention // Add mention
addMention(inReplyToPost.user_id, 'reply'); addMention(reply.user_id, 'reply');
} }
// If it is repost // If it is repost
@ -427,7 +427,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
if (mentionee == null) return; if (mentionee == null) return;
// 既に言及されたユーザーに対する返信や引用repostの場合も無視 // 既に言及されたユーザーに対する返信や引用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; if (repost && repost.user_id.equals(mentionee._id)) return;
// Add mention // Add mention