summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/posts')
-rw-r--r--src/api/endpoints/posts/categorize.ts8
-rw-r--r--src/api/endpoints/posts/context.ts14
-rw-r--r--src/api/endpoints/posts/create.ts152
-rw-r--r--src/api/endpoints/posts/favorites/create.ts16
-rw-r--r--src/api/endpoints/posts/favorites/delete.ts10
-rw-r--r--src/api/endpoints/posts/mentions.ts2
-rw-r--r--src/api/endpoints/posts/polls/recommendation.ts8
-rw-r--r--src/api/endpoints/posts/polls/vote.ts32
-rw-r--r--src/api/endpoints/posts/reactions.ts10
-rw-r--r--src/api/endpoints/posts/reactions/create.ts42
-rw-r--r--src/api/endpoints/posts/reactions/delete.ts14
-rw-r--r--src/api/endpoints/posts/replies.ts8
-rw-r--r--src/api/endpoints/posts/reposts.ts8
-rw-r--r--src/api/endpoints/posts/search.ts74
-rw-r--r--src/api/endpoints/posts/show.ts6
-rw-r--r--src/api/endpoints/posts/timeline.ts30
-rw-r--r--src/api/endpoints/posts/trend.ts8
17 files changed, 221 insertions, 221 deletions
diff --git a/src/api/endpoints/posts/categorize.ts b/src/api/endpoints/posts/categorize.ts
index 0c85c2b4e0..0436c8e697 100644
--- a/src/api/endpoints/posts/categorize.ts
+++ b/src/api/endpoints/posts/categorize.ts
@@ -12,13 +12,13 @@ import Post from '../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- if (!user.account.is_pro) {
+ if (!user.account.isPro) {
return rej('This endpoint is available only from a Pro account');
}
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get categorizee
const post = await Post.findOne({
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts
index 5ba3758975..44a77d102e 100644
--- a/src/api/endpoints/posts/context.ts
+++ b/src/api/endpoints/posts/context.ts
@@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
@@ -48,13 +48,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return;
}
- if (p.reply_id) {
- await get(p.reply_id);
+ if (p.replyId) {
+ await get(p.replyId);
}
}
- if (post.reply_id) {
- await get(post.reply_id);
+ if (post.replyId) {
+ await get(post.replyId);
}
// Serialize
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 286e18bb76..2a3d974fe8 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -33,9 +33,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text');
- // Get 'via_mobile' parameter
- const [viaMobile = false, viaMobileErr] = $(params.via_mobile).optional.boolean().$;
- if (viaMobileErr) return rej('invalid via_mobile');
+ // Get 'viaMobile' parameter
+ const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$;
+ if (viaMobileErr) return rej('invalid viaMobile');
// Get 'tags' parameter
const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
@@ -53,9 +53,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
.$;
if (geoErr) return rej('invalid geo');
- // Get 'media_ids' parameter
- const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
- if (mediaIdsErr) return rej('invalid media_ids');
+ // Get 'mediaIds' parameter
+ const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$;
+ if (mediaIdsErr) return rej('invalid mediaIds');
let files = [];
if (mediaIds !== undefined) {
@@ -67,7 +67,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// SELECT _id
const entity = await DriveFile.findOne({
_id: mediaId,
- 'metadata.user_id': user._id
+ 'metadata.userId': user._id
});
if (entity === null) {
@@ -80,9 +80,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
files = null;
}
- // Get 'repost_id' parameter
- const [repostId, repostIdErr] = $(params.repost_id).optional.id().$;
- if (repostIdErr) return rej('invalid repost_id');
+ // Get 'repostId' parameter
+ const [repostId, repostIdErr] = $(params.repostId).optional.id().$;
+ if (repostIdErr) return rej('invalid repostId');
let repost: IPost = null;
let isQuote = false;
@@ -94,13 +94,13 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
if (repost == null) {
return rej('repostee is not found');
- } else if (repost.repost_id && !repost.text && !repost.media_ids) {
+ } else if (repost.repostId && !repost.text && !repost.mediaIds) {
return rej('cannot repost to repost');
}
// Fetch recently post
const latestPost = await Post.findOne({
- user_id: user._id
+ userId: user._id
}, {
sort: {
_id: -1
@@ -111,8 +111,8 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// 直近と同じRepost対象かつ引用じゃなかったらエラー
if (latestPost &&
- latestPost.repost_id &&
- latestPost.repost_id.equals(repost._id) &&
+ latestPost.repostId &&
+ latestPost.repostId.equals(repost._id) &&
!isQuote) {
return rej('cannot repost same post that already reposted in your latest post');
}
@@ -125,9 +125,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
}
- // Get 'reply_id' parameter
- const [replyId, replyIdErr] = $(params.reply_id).optional.id().$;
- if (replyIdErr) return rej('invalid reply_id');
+ // Get 'replyId' parameter
+ const [replyId, replyIdErr] = $(params.replyId).optional.id().$;
+ if (replyIdErr) return rej('invalid replyId');
let reply: IPost = null;
if (replyId !== undefined) {
@@ -141,14 +141,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
// 返信対象が引用でないRepostだったらエラー
- if (reply.repost_id && !reply.text && !reply.media_ids) {
+ if (reply.repostId && !reply.text && !reply.mediaIds) {
return rej('cannot reply to repost');
}
}
- // Get 'channel_id' parameter
- const [channelId, channelIdErr] = $(params.channel_id).optional.id().$;
- if (channelIdErr) return rej('invalid channel_id');
+ // Get 'channelId' parameter
+ const [channelId, channelIdErr] = $(params.channelId).optional.id().$;
+ if (channelIdErr) return rej('invalid channelId');
let channel: IChannel = null;
if (channelId !== undefined) {
@@ -162,12 +162,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
// 返信対象の投稿がこのチャンネルじゃなかったらダメ
- if (reply && !channelId.equals(reply.channel_id)) {
+ if (reply && !channelId.equals(reply.channelId)) {
return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
}
// Repost対象の投稿がこのチャンネルじゃなかったらダメ
- if (repost && !channelId.equals(repost.channel_id)) {
+ if (repost && !channelId.equals(repost.channelId)) {
return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
}
@@ -177,12 +177,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
} else {
// 返信対象の投稿がチャンネルへの投稿だったらダメ
- if (reply && reply.channel_id != null) {
+ if (reply && reply.channelId != null) {
return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
}
// Repost対象の投稿がチャンネルへの投稿だったらダメ
- if (repost && repost.channel_id != null) {
+ if (repost && repost.channelId != null) {
return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
}
}
@@ -206,7 +206,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
if (text === undefined && files === null && repost === null && poll === undefined) {
- return rej('text, media_ids, repost_id or poll is required');
+ return rej('text, mediaIds, repostId or poll is required');
}
// 直近の投稿と重複してたらエラー
@@ -214,14 +214,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
if (user.latest_post) {
if (deepEqual({
text: user.latest_post.text,
- reply: user.latest_post.reply_id ? user.latest_post.reply_id.toString() : null,
- repost: user.latest_post.repost_id ? user.latest_post.repost_id.toString() : null,
- media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
+ reply: user.latest_post.replyId ? user.latest_post.replyId.toString() : null,
+ repost: user.latest_post.repostId ? user.latest_post.repostId.toString() : null,
+ mediaIds: (user.latest_post.mediaIds || []).map(id => id.toString())
}, {
text: text,
reply: reply ? reply._id.toString() : null,
repost: repost ? repost._id.toString() : null,
- media_ids: (files || []).map(file => file._id.toString())
+ mediaIds: (files || []).map(file => file._id.toString())
})) {
return rej('duplicate');
}
@@ -246,23 +246,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// 投稿を作成
const post = await Post.insert({
- created_at: new Date(),
- channel_id: channel ? channel._id : undefined,
+ createdAt: new Date(),
+ channelId: channel ? channel._id : undefined,
index: channel ? channel.index + 1 : undefined,
- media_ids: files ? files.map(file => file._id) : undefined,
- reply_id: reply ? reply._id : undefined,
- repost_id: repost ? repost._id : undefined,
+ mediaIds: files ? files.map(file => file._id) : undefined,
+ replyId: reply ? reply._id : undefined,
+ repostId: repost ? repost._id : undefined,
poll: poll,
text: text,
tags: tags,
- user_id: user._id,
- app_id: app ? app._id : null,
- via_mobile: viaMobile,
+ userId: user._id,
+ appId: app ? app._id : null,
+ viaMobile: viaMobile,
geo,
// 以下非正規化データ
- _reply: reply ? { user_id: reply.user_id } : undefined,
- _repost: repost ? { user_id: repost.user_id } : undefined,
+ _reply: reply ? { userId: reply.userId } : undefined,
+ _repost: repost ? { userId: repost.userId } : undefined,
});
// Serialize
@@ -293,10 +293,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Publish event
if (!user._id.equals(mentionee)) {
const mentioneeMutes = await Mute.find({
- muter_id: mentionee,
- deleted_at: { $exists: false }
+ muterId: mentionee,
+ deletedAt: { $exists: false }
});
- const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString());
+ const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString());
if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
event(mentionee, reason, postObj);
pushSw(mentionee, reason, postObj);
@@ -312,17 +312,17 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Fetch all followers
const followers = await Following
.find({
- followee_id: user._id,
+ followeeId: user._id,
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
- follower_id: true,
+ followerId: true,
_id: false
});
// Publish event to followers stream
followers.forEach(following =>
- event(following.follower_id, 'post', postObj));
+ event(following.followerId, 'post', postObj));
}
// チャンネルへの投稿
@@ -339,21 +339,21 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Get channel watchers
const watches = await ChannelWatching.find({
- channel_id: channel._id,
+ channelId: channel._id,
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
});
// チャンネルの視聴者(のタイムライン)に配信
watches.forEach(w => {
- event(w.user_id, 'post', postObj);
+ event(w.userId, 'post', postObj);
});
}
// Increment my posts count
User.update({ _id: user._id }, {
$inc: {
- posts_count: 1
+ postsCount: 1
}
});
@@ -367,26 +367,26 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
});
// 自分自身へのリプライでない限りは通知を作成
- notify(reply.user_id, user._id, 'reply', {
- post_id: post._id
+ notify(reply.userId, user._id, 'reply', {
+ postId: post._id
});
// Fetch watchers
Watching
.find({
- post_id: reply._id,
- user_id: { $ne: user._id },
+ postId: reply._id,
+ userId: { $ne: user._id },
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
fields: {
- user_id: true
+ userId: true
}
})
.then(watchers => {
watchers.forEach(watcher => {
- notify(watcher.user_id, user._id, 'reply', {
- post_id: post._id
+ notify(watcher.userId, user._id, 'reply', {
+ postId: post._id
});
});
});
@@ -397,33 +397,33 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
// Add mention
- addMention(reply.user_id, 'reply');
+ addMention(reply.userId, 'reply');
}
// If it is repost
if (repost) {
// Notify
const type = text ? 'quote' : 'repost';
- notify(repost.user_id, user._id, type, {
- post_id: post._id
+ notify(repost.userId, user._id, type, {
+ postId: post._id
});
// Fetch watchers
Watching
.find({
- post_id: repost._id,
- user_id: { $ne: user._id },
+ postId: repost._id,
+ userId: { $ne: user._id },
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
fields: {
- user_id: true
+ userId: true
}
})
.then(watchers => {
watchers.forEach(watcher => {
- notify(watcher.user_id, user._id, type, {
- post_id: post._id
+ notify(watcher.userId, user._id, type, {
+ postId: post._id
});
});
});
@@ -436,18 +436,18 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// If it is quote repost
if (text) {
// Add mention
- addMention(repost.user_id, 'quote');
+ addMention(repost.userId, 'quote');
} else {
// Publish event
- if (!user._id.equals(repost.user_id)) {
- event(repost.user_id, 'repost', postObj);
+ if (!user._id.equals(repost.userId)) {
+ event(repost.userId, 'repost', postObj);
}
}
// 今までで同じ投稿をRepostしているか
const existRepost = await Post.findOne({
- user_id: user._id,
- repost_id: repost._id,
+ userId: user._id,
+ repostId: repost._id,
_id: {
$ne: post._id
}
@@ -494,15 +494,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
if (mentionee == null) return;
// 既に言及されたユーザーに対する返信や引用repostの場合も無視
- if (reply && reply.user_id.equals(mentionee._id)) return;
- if (repost && repost.user_id.equals(mentionee._id)) return;
+ if (reply && reply.userId.equals(mentionee._id)) return;
+ if (repost && repost.userId.equals(mentionee._id)) return;
// Add mention
addMention(mentionee._id, 'mention');
// Create notification
notify(mentionee._id, user._id, 'mention', {
- post_id: post._id
+ postId: post._id
});
return;
diff --git a/src/api/endpoints/posts/favorites/create.ts b/src/api/endpoints/posts/favorites/create.ts
index f9dee271b5..6100e10b23 100644
--- a/src/api/endpoints/posts/favorites/create.ts
+++ b/src/api/endpoints/posts/favorites/create.ts
@@ -13,9 +13,9 @@ import Post from '../../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get favoritee
const post = await Post.findOne({
@@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// if already favorited
const exist = await Favorite.findOne({
- post_id: post._id,
- user_id: user._id
+ postId: post._id,
+ userId: user._id
});
if (exist !== null) {
@@ -38,9 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Create favorite
await Favorite.insert({
- created_at: new Date(),
- post_id: post._id,
- user_id: user._id
+ createdAt: new Date(),
+ postId: post._id,
+ userId: user._id
});
// Send response
diff --git a/src/api/endpoints/posts/favorites/delete.ts b/src/api/endpoints/posts/favorites/delete.ts
index c4fe7d3234..b1b4fcebc4 100644
--- a/src/api/endpoints/posts/favorites/delete.ts
+++ b/src/api/endpoints/posts/favorites/delete.ts
@@ -13,9 +13,9 @@ import Post from '../../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get favoritee
const post = await Post.findOne({
@@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// if already favorited
const exist = await Favorite.findOne({
- post_id: post._id,
- user_id: user._id
+ postId: post._id,
+ userId: user._id
});
if (exist === null) {
diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts
index 7127db0ad1..da90583bbd 100644
--- a/src/api/endpoints/posts/mentions.ts
+++ b/src/api/endpoints/posts/mentions.ts
@@ -48,7 +48,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
if (following) {
const followingIds = await getFriends(user._id);
- query.user_id = {
+ query.userId = {
$in: followingIds
};
}
diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts
index 4a3fa3f55e..19ef0975fa 100644
--- a/src/api/endpoints/posts/polls/recommendation.ts
+++ b/src/api/endpoints/posts/polls/recommendation.ts
@@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Get votes
const votes = await Vote.find({
- user_id: user._id
+ userId: user._id
}, {
fields: {
_id: false,
- post_id: true
+ postId: true
}
});
- const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : [];
+ const nin = votes && votes.length != 0 ? votes.map(v => v.postId) : [];
const posts = await Post
.find({
_id: {
$nin: nin
},
- user_id: {
+ userId: {
$ne: user._id
},
poll: {
diff --git a/src/api/endpoints/posts/polls/vote.ts b/src/api/endpoints/posts/polls/vote.ts
index 16ce76a6fa..e87474ae6e 100644
--- a/src/api/endpoints/posts/polls/vote.ts
+++ b/src/api/endpoints/posts/polls/vote.ts
@@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get votee
const post = await Post.findOne({
@@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// if already voted
const exist = await Vote.findOne({
- post_id: post._id,
- user_id: user._id
+ postId: post._id,
+ userId: user._id
});
if (exist !== null) {
@@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Create vote
await Vote.insert({
- created_at: new Date(),
- post_id: post._id,
- user_id: user._id,
+ createdAt: new Date(),
+ postId: post._id,
+ userId: user._id,
choice: choice
});
@@ -73,27 +73,27 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
publishPostStream(post._id, 'poll_voted');
// Notify
- notify(post.user_id, user._id, 'poll_vote', {
- post_id: post._id,
+ notify(post.userId, user._id, 'poll_vote', {
+ postId: post._id,
choice: choice
});
// Fetch watchers
Watching
.find({
- post_id: post._id,
- user_id: { $ne: user._id },
+ postId: post._id,
+ userId: { $ne: user._id },
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
fields: {
- user_id: true
+ userId: true
}
})
.then(watchers => {
watchers.forEach(watcher => {
- notify(watcher.user_id, user._id, 'poll_vote', {
- post_id: post._id,
+ notify(watcher.userId, user._id, 'poll_vote', {
+ postId: post._id,
choice: choice
});
});
diff --git a/src/api/endpoints/posts/reactions.ts b/src/api/endpoints/posts/reactions.ts
index feb140ab41..f753ba7c29 100644
--- a/src/api/endpoints/posts/reactions.ts
+++ b/src/api/endpoints/posts/reactions.ts
@@ -13,9 +13,9 @@ import Reaction, { pack } from '../../models/post-reaction';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
@@ -41,8 +41,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Issue query
const reactions = await Reaction
.find({
- post_id: post._id,
- deleted_at: { $exists: false }
+ postId: post._id,
+ deletedAt: { $exists: false }
}, {
limit: limit,
skip: offset,
diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts
index f77afed40c..7031d28e56 100644
--- a/src/api/endpoints/posts/reactions/create.ts
+++ b/src/api/endpoints/posts/reactions/create.ts
@@ -18,9 +18,9 @@ import { publishPostStream, pushSw } from '../../../event';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get 'reaction' parameter
const [reaction, reactionErr] = $(params.reaction).string().or([
@@ -46,15 +46,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Myself
- if (post.user_id.equals(user._id)) {
+ if (post.userId.equals(user._id)) {
return rej('cannot react to my post');
}
// if already reacted
const exist = await Reaction.findOne({
- post_id: post._id,
- user_id: user._id,
- deleted_at: { $exists: false }
+ postId: post._id,
+ userId: user._id,
+ deletedAt: { $exists: false }
});
if (exist !== null) {
@@ -63,9 +63,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Create reaction
await Reaction.insert({
- created_at: new Date(),
- post_id: post._id,
- user_id: user._id,
+ createdAt: new Date(),
+ postId: post._id,
+ userId: user._id,
reaction: reaction
});
@@ -83,33 +83,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
publishPostStream(post._id, 'reacted');
// Notify
- notify(post.user_id, user._id, 'reaction', {
- post_id: post._id,
+ notify(post.userId, user._id, 'reaction', {
+ postId: post._id,
reaction: reaction
});
- pushSw(post.user_id, 'reaction', {
- user: await packUser(user, post.user_id),
- post: await packPost(post, post.user_id),
+ pushSw(post.userId, 'reaction', {
+ user: await packUser(user, post.userId),
+ post: await packPost(post, post.userId),
reaction: reaction
});
// Fetch watchers
Watching
.find({
- post_id: post._id,
- user_id: { $ne: user._id },
+ postId: post._id,
+ userId: { $ne: user._id },
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
fields: {
- user_id: true
+ userId: true
}
})
.then(watchers => {
watchers.forEach(watcher => {
- notify(watcher.user_id, user._id, 'reaction', {
- post_id: post._id,
+ notify(watcher.userId, user._id, 'reaction', {
+ postId: post._id,
reaction: reaction
});
});
diff --git a/src/api/endpoints/posts/reactions/delete.ts b/src/api/endpoints/posts/reactions/delete.ts
index 922c57ab18..18fdabcdc2 100644
--- a/src/api/endpoints/posts/reactions/delete.ts
+++ b/src/api/endpoints/posts/reactions/delete.ts
@@ -14,9 +14,9 @@ import Post from '../../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Fetch unreactee
const post = await Post.findOne({
@@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// if already unreacted
const exist = await Reaction.findOne({
- post_id: post._id,
- user_id: user._id,
- deleted_at: { $exists: false }
+ postId: post._id,
+ userId: user._id,
+ deletedAt: { $exists: false }
});
if (exist === null) {
@@ -43,7 +43,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
_id: exist._id
}, {
$set: {
- deleted_at: new Date()
+ deletedAt: new Date()
}
});
diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts
index 613c4fa24c..db021505fc 100644
--- a/src/api/endpoints/posts/replies.ts
+++ b/src/api/endpoints/posts/replies.ts
@@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
@@ -39,7 +39,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Issue query
const replies = await Post
- .find({ reply_id: post._id }, {
+ .find({ replyId: post._id }, {
limit: limit,
skip: offset,
sort: {
diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts
index 89ab0e3d55..c1645117f0 100644
--- a/src/api/endpoints/posts/reposts.ts
+++ b/src/api/endpoints/posts/reposts.ts
@@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
@@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
_id: -1
};
const query = {
- repost_id: post._id
+ repostId: post._id
} as any;
if (sinceId) {
sort._id = 1;
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index a36d1178a5..e7906c95c8 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [text, textError] = $(params.text).optional.string().$;
if (textError) return rej('invalid text param');
- // Get 'include_user_ids' parameter
- const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
- if (includeUserIdsErr) return rej('invalid include_user_ids param');
+ // Get 'include_userIds' parameter
+ const [includeUserIds = [], includeUserIdsErr] = $(params.include_userIds).optional.array('id').$;
+ if (includeUserIdsErr) return rej('invalid include_userIds param');
- // Get 'exclude_user_ids' parameter
- const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$;
- if (excludeUserIdsErr) return rej('invalid exclude_user_ids param');
+ // Get 'exclude_userIds' parameter
+ const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_userIds).optional.array('id').$;
+ if (excludeUserIdsErr) return rej('invalid exclude_userIds param');
// Get 'include_user_usernames' parameter
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
@@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
if (includeUserUsernames != null) {
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
const _user = await User.findOne({
- username_lower: username.toLowerCase()
+ usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
@@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
if (excludeUserUsernames != null) {
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
const _user = await User.findOne({
- username_lower: username.toLowerCase()
+ usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
@@ -143,13 +143,13 @@ async function search(
if (includeUserIds && includeUserIds.length != 0) {
push({
- user_id: {
+ userId: {
$in: includeUserIds
}
});
} else if (excludeUserIds && excludeUserIds.length != 0) {
push({
- user_id: {
+ userId: {
$nin: excludeUserIds
}
});
@@ -158,7 +158,7 @@ async function search(
if (following != null && me != null) {
const ids = await getFriends(me._id, false);
push({
- user_id: following ? {
+ userId: following ? {
$in: ids
} : {
$nin: ids.concat(me._id)
@@ -168,45 +168,45 @@ async function search(
if (me != null) {
const mutes = await Mute.find({
- muter_id: me._id,
- deleted_at: { $exists: false }
+ muterId: me._id,
+ deletedAt: { $exists: false }
});
- const mutedUserIds = mutes.map(m => m.mutee_id);
+ const mutedUserIds = mutes.map(m => m.muteeId);
switch (mute) {
case 'mute_all':
push({
- user_id: {
+ userId: {
$nin: mutedUserIds
},
- '_reply.user_id': {
+ '_reply.userId': {
$nin: mutedUserIds
},
- '_repost.user_id': {
+ '_repost.userId': {
$nin: mutedUserIds
}
});
break;
case 'mute_related':
push({
- '_reply.user_id': {
+ '_reply.userId': {
$nin: mutedUserIds
},
- '_repost.user_id': {
+ '_repost.userId': {
$nin: mutedUserIds
}
});
break;
case 'mute_direct':
push({
- user_id: {
+ userId: {
$nin: mutedUserIds
}
});
break;
case 'direct_only':
push({
- user_id: {
+ userId: {
$in: mutedUserIds
}
});
@@ -214,11 +214,11 @@ async function search(
case 'related_only':
push({
$or: [{
- '_reply.user_id': {
+ '_reply.userId': {
$in: mutedUserIds
}
}, {
- '_repost.user_id': {
+ '_repost.userId': {
$in: mutedUserIds
}
}]
@@ -227,15 +227,15 @@ async function search(
case 'all_only':
push({
$or: [{
- user_id: {
+ userId: {
$in: mutedUserIds
}
}, {
- '_reply.user_id': {
+ '_reply.userId': {
$in: mutedUserIds
}
}, {
- '_repost.user_id': {
+ '_repost.userId': {
$in: mutedUserIds
}
}]
@@ -247,7 +247,7 @@ async function search(
if (reply != null) {
if (reply) {
push({
- reply_id: {
+ replyId: {
$exists: true,
$ne: null
}
@@ -255,11 +255,11 @@ async function search(
} else {
push({
$or: [{
- reply_id: {
+ replyId: {
$exists: false
}
}, {
- reply_id: null
+ replyId: null
}]
});
}
@@ -268,7 +268,7 @@ async function search(
if (repost != null) {
if (repost) {
push({
- repost_id: {
+ repostId: {
$exists: true,
$ne: null
}
@@ -276,11 +276,11 @@ async function search(
} else {
push({
$or: [{
- repost_id: {
+ repostId: {
$exists: false
}
}, {
- repost_id: null
+ repostId: null
}]
});
}
@@ -289,7 +289,7 @@ async function search(
if (media != null) {
if (media) {
push({
- media_ids: {
+ mediaIds: {
$exists: true,
$ne: null
}
@@ -297,11 +297,11 @@ async function search(
} else {
push({
$or: [{
- media_ids: {
+ mediaIds: {
$exists: false
}
}, {
- media_ids: null
+ mediaIds: null
}]
});
}
@@ -330,7 +330,7 @@ async function search(
if (sinceDate) {
push({
- created_at: {
+ createdAt: {
$gt: new Date(sinceDate)
}
});
@@ -338,7 +338,7 @@ async function search(
if (untilDate) {
push({
- created_at: {
+ createdAt: {
$lt: new Date(untilDate)
}
});
diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts
index 3839490597..bb4bcdb790 100644
--- a/src/api/endpoints/posts/show.ts
+++ b/src/api/endpoints/posts/show.ts
@@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get post
const post = await Post.findOne({
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index c41cfdb8bd..c7cb8032e3 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -49,17 +49,17 @@ module.exports = async (params, user, app) => {
// Watchしているチャンネルを取得
watchingChannelIds: ChannelWatching.find({
- user_id: user._id,
+ userId: user._id,
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
- }).then(watches => watches.map(w => w.channel_id)),
+ deletedAt: { $exists: false }
+ }).then(watches => watches.map(w => w.channelId)),
// ミュートしているユーザーを取得
mutedUserIds: Mute.find({
- muter_id: user._id,
+ muterId: user._id,
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
- }).then(ms => ms.map(m => m.mutee_id))
+ deletedAt: { $exists: false }
+ }).then(ms => ms.map(m => m.muteeId))
});
//#region Construct query
@@ -70,31 +70,31 @@ module.exports = async (params, user, app) => {
const query = {
$or: [{
// フォローしている人のタイムラインへの投稿
- user_id: {
+ userId: {
$in: followingIds
},
// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
$or: [{
- channel_id: {
+ channelId: {
$exists: false
}
}, {
- channel_id: null
+ channelId: null
}]
}, {
// Watchしているチャンネルへの投稿
- channel_id: {
+ channelId: {
$in: watchingChannelIds
}
}],
// mute
- user_id: {
+ userId: {
$nin: mutedUserIds
},
- '_reply.user_id': {
+ '_reply.userId': {
$nin: mutedUserIds
},
- '_repost.user_id': {
+ '_repost.userId': {
$nin: mutedUserIds
},
} as any;
@@ -110,11 +110,11 @@ module.exports = async (params, user, app) => {
};
} else if (sinceDate) {
sort._id = 1;
- query.created_at = {
+ query.createdAt = {
$gt: new Date(sinceDate)
};
} else if (untilDate) {
- query.created_at = {
+ query.createdAt = {
$lt: new Date(untilDate)
};
}
diff --git a/src/api/endpoints/posts/trend.ts b/src/api/endpoints/posts/trend.ts
index caded92bf5..3f92f06167 100644
--- a/src/api/endpoints/posts/trend.ts
+++ b/src/api/endpoints/posts/trend.ts
@@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
if (pollErr) return rej('invalid poll param');
const query = {
- created_at: {
+ createdAt: {
$gte: new Date(Date.now() - ms('1days'))
},
repost_count: {
@@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} as any;
if (reply != undefined) {
- query.reply_id = reply ? { $exists: true, $ne: null } : null;
+ query.replyId = reply ? { $exists: true, $ne: null } : null;
}
if (repost != undefined) {
- query.repost_id = repost ? { $exists: true, $ne: null } : null;
+ query.repostId = repost ? { $exists: true, $ne: null } : null;
}
if (media != undefined) {
- query.media_ids = media ? { $exists: true, $ne: null } : null;
+ query.mediaIds = media ? { $exists: true, $ne: null } : null;
}
if (poll != undefined) {