Resolve conflicts

This commit is contained in:
syuilo
2018-03-29 14:48:47 +09:00
parent 281b388e39
commit bfc193d8cd
308 changed files with 3045 additions and 3200 deletions

View File

@@ -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({

View File

@@ -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

View File

@@ -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,22 +206,22 @@ 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');
}
// 直近の投稿と重複してたらエラー
// TODO: 直近の投稿が一日前くらいなら重複とは見なさない
if (user.latest_post) {
if (user.latestPost) {
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())
text: user.latestPost.text,
reply: user.latestPost.replyId ? user.latestPost.replyId.toString() : null,
repost: user.latestPost.repostId ? user.latestPost.repostId.toString() : null,
mediaIds: (user.latestPost.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
@@ -270,14 +270,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Reponse
res({
created_post: postObj
createdPost: postObj
});
//#region Post processes
User.update({ _id: user._id }, {
$set: {
latest_post: post
latestPost: post
}
});
@@ -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
}
});
@@ -362,68 +362,68 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Increment replies count
Post.update({ _id: reply._id }, {
$inc: {
replies_count: 1
repliesCount: 1
}
});
// 自分自身へのリプライでない限りは通知を作成
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
});
});
});
// この投稿をWatchする
if ((user.account as ILocalAccount).settings.auto_watch !== false) {
if ((user.account as ILocalAccount).settings.autoWatch !== false) {
watch(user._id, reply);
}
// 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
}
@@ -457,7 +457,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Update repostee status
Post.update({ _id: repost._id }, {
$inc: {
repost_count: 1
repostCount: 1
}
});
}
@@ -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;

View File

@@ -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

View File

@@ -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) {
@@ -37,7 +37,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Delete favorite
await Favorite.deleteOne({
await Favorite.remove({
_id: exist._id
});

View File

@@ -23,17 +23,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'until_id' parameter
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
if (untilIdErr) return rej('invalid until_id param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
if (untilIdErr) return rej('invalid untilId param');
// Check if both of since_id and until_id is specified
// Check if both of sinceId and untilId is specified
if (sinceId && untilId) {
return rej('cannot set since_id and until_id');
return rej('cannot set sinceId and untilId');
}
// Construct query
@@ -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
};
}

View File

@@ -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: {

View File

@@ -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,34 +73,34 @@ 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
});
});
});
// この投稿をWatchする
if (user.account.settings.auto_watch !== false) {
if (user.account.settings.autoWatch !== false) {
watch(user._id, post);
}
});

View File

@@ -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,

View File

@@ -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
});
@@ -73,7 +73,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
res();
const inc = {};
inc[`reaction_counts.${reaction}`] = 1;
inc[`reactionCounts.${reaction}`] = 1;
// Increment reactions count
await Post.update({ _id: post._id }, {
@@ -83,40 +83,40 @@ 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
});
});
});
// この投稿をWatchする
if (user.account.settings.auto_watch !== false) {
if (user.account.settings.autoWatch !== false) {
watch(user._id, post);
}
});

View File

@@ -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()
}
});
@@ -51,7 +51,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
res();
const dec = {};
dec[`reaction_counts.${exist.reaction}`] = -1;
dec[`reactionCounts.${exist.reaction}`] = -1;
// Decrement reactions count
Post.update({ _id: post._id }, {

View File

@@ -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: {

View File

@@ -12,25 +12,25 @@ 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).$;
if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'until_id' parameter
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
if (untilIdErr) return rej('invalid until_id param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
if (untilIdErr) return rej('invalid untilId param');
// Check if both of since_id and until_id is specified
// Check if both of sinceId and untilId is specified
if (sinceId && untilId) {
return rej('cannot set since_id and until_id');
return rej('cannot set sinceId and untilId');
}
// Lookup post
@@ -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;

View File

@@ -21,21 +21,21 @@ 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 'includeUserIds' parameter
const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array('id').$;
if (includeUserIdsErr) return rej('invalid includeUserIds 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 'excludeUserIds' parameter
const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array('id').$;
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
// Get 'include_user_usernames' parameter
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
if (includeUserUsernamesErr) return rej('invalid include_user_usernames param');
// Get 'includeUserUsernames' parameter
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array('string').$;
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
// Get 'exclude_user_usernames' parameter
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.exclude_user_usernames).optional.array('string').$;
if (excludeUserUsernamesErr) return rej('invalid exclude_user_usernames param');
// Get 'excludeUserUsernames' parameter
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array('string').$;
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
// Get 'following' parameter
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
@@ -61,13 +61,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().$;
if (pollErr) return rej('invalid poll param');
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'until_date' parameter
const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
if (untilDateErr) throw 'invalid until_date param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
if (untilDateErr) throw 'invalid untilDate param';
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
@@ -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)
}
});

View File

@@ -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({

View File

@@ -22,25 +22,25 @@ module.exports = async (params, user, app) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) throw 'invalid limit param';
// Get 'since_id' parameter
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) throw 'invalid since_id param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'until_id' parameter
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
if (untilIdErr) throw 'invalid until_id param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
if (untilIdErr) throw 'invalid untilId param';
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'until_date' parameter
const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
if (untilDateErr) throw 'invalid until_date param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of since_id, until_id, since_date, until_date specified
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
throw 'only one of since_id, until_id, since_date, until_date can be specified';
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
const { followingIds, watchingChannelIds, mutedUserIds } = await rap({
@@ -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)
};
}

View File

@@ -38,24 +38,24 @@ 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: {
repostCount: {
$gt: 0
}
} 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) {
@@ -68,7 +68,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
limit: limit,
skip: offset,
sort: {
repost_count: -1,
repostCount: -1,
_id: -1
}
});