summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/create.ts40
-rw-r--r--src/server/api/endpoints/notes/global-timeline.ts82
-rw-r--r--src/server/api/endpoints/notes/hybrid-timeline.ts26
-rw-r--r--src/server/api/endpoints/notes/local-timeline.ts96
-rw-r--r--src/server/api/endpoints/notes/reactions/create.ts4
-rw-r--r--src/server/api/endpoints/notes/search_by_tag.ts207
-rw-r--r--src/server/api/endpoints/notes/timeline.ts23
-rw-r--r--src/server/api/endpoints/notes/trend.ts2
-rw-r--r--src/server/api/endpoints/notes/user-list-timeline.ts20
9 files changed, 297 insertions, 203 deletions
diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts
index 04f5f7562e..96745132a3 100644
--- a/src/server/api/endpoints/notes/create.ts
+++ b/src/server/api/endpoints/notes/create.ts
@@ -71,9 +71,15 @@ export const meta = {
ref: 'geo'
}),
+ fileIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({
+ desc: {
+ 'ja-JP': '添付するファイル'
+ }
+ }),
+
mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({
desc: {
- 'ja-JP': '添付するメディア'
+ 'ja-JP': '添付するファイル (このパラメータは廃止予定です。代わりに fileIds を使ってください。)'
}
}),
@@ -124,26 +130,16 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
}
let files: IDriveFile[] = [];
- if (ps.mediaIds !== undefined) {
- // Fetch files
- // forEach だと途中でエラーなどがあっても return できないので
- // 敢えて for を使っています。
- for (const mediaId of ps.mediaIds) {
- // Fetch file
- // SELECT _id
- const entity = await DriveFile.findOne({
- _id: mediaId,
+ const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null;
+ if (fileIds != null) {
+ files = await Promise.all(fileIds.map(fileId => {
+ return DriveFile.findOne({
+ _id: fileId,
'metadata.userId': user._id
});
+ }));
- if (entity === null) {
- return rej('file not found');
- } else {
- files.push(entity);
- }
- }
- } else {
- files = null;
+ files = files.filter(file => file != null);
}
let renote: INote = null;
@@ -155,7 +151,7 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
if (renote == null) {
return rej('renoteee is not found');
- } else if (renote.renoteId && !renote.text && !renote.mediaIds) {
+ } else if (renote.renoteId && !renote.text && !renote.fileIds) {
return rej('cannot renote to renote');
}
}
@@ -176,7 +172,7 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
}
// 返信対象が引用でないRenoteだったらエラー
- if (reply.renoteId && !reply.text && !reply.mediaIds) {
+ if (reply.renoteId && !reply.text && !reply.fileIds) {
return rej('cannot reply to renote');
}
}
@@ -191,13 +187,13 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
if ((ps.text === undefined || ps.text === null) && files === null && renote === null && ps.poll === undefined) {
- return rej('text, mediaIds, renoteId or poll is required');
+ return rej('text, fileIds, renoteId or poll is required');
}
// 投稿を作成
const note = await create(user, {
createdAt: new Date(),
- media: files,
+ files: files,
poll: ps.poll,
text: ps.text,
reply,
diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts
index 8f7233e308..5d93cd78ec 100644
--- a/src/server/api/endpoints/notes/global-timeline.ts
+++ b/src/server/api/endpoints/notes/global-timeline.ts
@@ -3,40 +3,50 @@ import Note from '../../../../models/note';
import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
+import { countIf } from '../../../../prelude/array';
-/**
- * Get timeline of global
- */
-export default async (params: any, user: ILocalUser) => {
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) throw 'invalid limit param';
+export const meta = {
+ desc: {
+ 'ja-JP': 'グローバルタイムラインを取得します。'
+ },
+
+ params: {
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か'
+ }
+ }),
+
+ mediaOnly: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
+ }
+ }),
+
+ limit: $.num.optional.range(1, 100).note({
+ default: 10
+ }),
+
+ sinceId: $.type(ID).optional.note({}),
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) throw 'invalid sinceId param';
+ untilId: $.type(ID).optional.note({}),
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) throw 'invalid untilId param';
+ sinceDate: $.num.optional.note({}),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ untilDate: $.num.optional.note({}),
+ }
+};
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+export default async (params: any, user: ILocalUser) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
- // Get 'mediaOnly' parameter
- const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
- if (mediaOnlyErr) throw 'invalid mediaOnly param';
-
// ミュートしているユーザーを取得
const mutedUserIds = user ? (await Mute.find({
muterId: user._id
@@ -68,27 +78,29 @@ export default async (params: any, user: ILocalUser) => {
};
}
- if (mediaOnly) {
- query.mediaIds = { $exists: true, $ne: [] };
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
+ if (withFiles) {
+ query.fileIds = { $exists: true, $ne: [] };
}
- if (sinceId) {
+ if (ps.sinceId) {
sort._id = 1;
query._id = {
- $gt: sinceId
+ $gt: ps.sinceId
};
- } else if (untilId) {
+ } else if (ps.untilId) {
query._id = {
- $lt: untilId
+ $lt: ps.untilId
};
- } else if (sinceDate) {
+ } else if (ps.sinceDate) {
sort._id = 1;
query.createdAt = {
- $gt: new Date(sinceDate)
+ $gt: new Date(ps.sinceDate)
};
- } else if (untilDate) {
+ } else if (ps.untilDate) {
query.createdAt = {
- $lt: new Date(untilDate)
+ $lt: new Date(ps.untilDate)
};
}
//#endregion
@@ -96,7 +108,7 @@ export default async (params: any, user: ILocalUser) => {
// Issue query
const timeline = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});
diff --git a/src/server/api/endpoints/notes/hybrid-timeline.ts b/src/server/api/endpoints/notes/hybrid-timeline.ts
index 2dbb1190c1..5e39d8c78a 100644
--- a/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -5,10 +5,9 @@ import { getFriends } from '../../common/get-friends';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
import getParams from '../../get-params';
+import { countIf } from '../../../../prelude/array';
export const meta = {
- name: 'notes/hybrid-timeline',
-
desc: {
'ja-JP': 'ハイブリッドタイムラインを取得します。'
},
@@ -66,23 +65,26 @@ export const meta = {
}
}),
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
+ }
+ }),
+
mediaOnly: $.bool.optional.note({
desc: {
- 'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します'
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
}
}),
}
};
-/**
- * Get hybrid timeline of myself
- */
export default async (params: any, user: ILocalUser) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
+ if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
@@ -164,7 +166,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -180,7 +182,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -196,16 +198,16 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
});
}
- if (ps.mediaOnly) {
+ if (ps.withFiles || ps.mediaOnly) {
query.$and.push({
- mediaIds: { $exists: true, $ne: [] }
+ fileIds: { $exists: true, $ne: [] }
});
}
diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts
index bbcc6303ca..ff10e6fbaa 100644
--- a/src/server/api/endpoints/notes/local-timeline.ts
+++ b/src/server/api/endpoints/notes/local-timeline.ts
@@ -3,40 +3,56 @@ import Note from '../../../../models/note';
import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
+import { countIf } from '../../../../prelude/array';
-/**
- * Get timeline of local
- */
-export default async (params: any, user: ILocalUser) => {
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) throw 'invalid limit param';
+export const meta = {
+ desc: {
+ 'ja-JP': 'ローカルタイムラインを取得します。'
+ },
+
+ params: {
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か'
+ }
+ }),
+
+ mediaOnly: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
+ }
+ }),
+
+ fileType: $.arr($.str).optional.note({
+ desc: {
+ 'ja-JP': '指定された種類のファイルが添付された投稿のみを取得します'
+ }
+ }),
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) throw 'invalid sinceId param';
+ limit: $.num.optional.range(1, 100).note({
+ default: 10
+ }),
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) throw 'invalid untilId param';
+ sinceId: $.type(ID).optional.note({}),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ untilId: $.type(ID).optional.note({}),
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+ sinceDate: $.num.optional.note({}),
+
+ untilDate: $.num.optional.note({}),
+ }
+};
+
+export default async (params: any, user: ILocalUser) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
- // Get 'mediaOnly' parameter
- const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
- if (mediaOnlyErr) throw 'invalid mediaOnly param';
-
// ミュートしているユーザーを取得
const mutedUserIds = user ? (await Mute.find({
muterId: user._id
@@ -69,27 +85,37 @@ export default async (params: any, user: ILocalUser) => {
};
}
- if (mediaOnly) {
- query.mediaIds = { $exists: true, $ne: [] };
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
+ if (withFiles) {
+ query.fileIds = { $exists: true, $ne: [] };
+ }
+
+ if (ps.fileType) {
+ query.fileIds = { $exists: true, $ne: [] };
+
+ query['_files.contentType'] = {
+ $in: ps.fileType
+ };
}
- if (sinceId) {
+ if (ps.sinceId) {
sort._id = 1;
query._id = {
- $gt: sinceId
+ $gt: ps.sinceId
};
- } else if (untilId) {
+ } else if (ps.untilId) {
query._id = {
- $lt: untilId
+ $lt: ps.untilId
};
- } else if (sinceDate) {
+ } else if (ps.sinceDate) {
sort._id = 1;
query.createdAt = {
- $gt: new Date(sinceDate)
+ $gt: new Date(ps.sinceDate)
};
- } else if (untilDate) {
+ } else if (ps.untilDate) {
query.createdAt = {
- $lt: new Date(untilDate)
+ $lt: new Date(ps.untilDate)
};
}
//#endregion
@@ -97,7 +123,7 @@ export default async (params: any, user: ILocalUser) => {
// Issue query
const timeline = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});
diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts
index 0781db16c5..ec68f065d8 100644
--- a/src/server/api/endpoints/notes/reactions/create.ts
+++ b/src/server/api/endpoints/notes/reactions/create.ts
@@ -43,6 +43,10 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
return rej('note not found');
}
+ if (note.deletedAt != null) {
+ return rej('this not is already deleted');
+ }
+
try {
await create(user, note, ps.reaction);
} catch (e) {
diff --git a/src/server/api/endpoints/notes/search_by_tag.ts b/src/server/api/endpoints/notes/search_by_tag.ts
index e092275fe8..11bfe34724 100644
--- a/src/server/api/endpoints/notes/search_by_tag.ts
+++ b/src/server/api/endpoints/notes/search_by_tag.ts
@@ -4,119 +4,154 @@ import User, { ILocalUser } from '../../../../models/user';
import Mute from '../../../../models/mute';
import { getFriendIds } from '../../common/get-friends';
import { pack } from '../../../../models/note';
+import getParams from '../../get-params';
+import { erase } from '../../../../prelude/array';
-/**
- * Search notes by tag
- */
-export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
- // Get 'tag' parameter
- const [tag, tagError] = $.str.get(params.tag);
- if (tagError) return rej('invalid tag param');
+export const meta = {
+ desc: {
+ 'ja-JP': '指定されたタグが付けられた投稿を取得します。'
+ },
+
+ params: {
+ tag: $.str.note({
+ desc: {
+ 'ja-JP': 'タグ'
+ }
+ }),
+
+ includeUserIds: $.arr($.type(ID)).optional.note({
+ default: []
+ }),
+
+ excludeUserIds: $.arr($.type(ID)).optional.note({
+ default: []
+ }),
+
+ includeUserUsernames: $.arr($.str).optional.note({
+ default: []
+ }),
+
+ excludeUserUsernames: $.arr($.str).optional.note({
+ default: []
+ }),
+
+ following: $.bool.optional.nullable.note({
+ default: null
+ }),
+
+ mute: $.str.optional.note({
+ default: 'mute_all'
+ }),
- // Get 'includeUserIds' parameter
- const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional.get(params.includeUserIds);
- if (includeUserIdsErr) return rej('invalid includeUserIds param');
+ reply: $.bool.optional.nullable.note({
+ default: null,
- // Get 'excludeUserIds' parameter
- const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional.get(params.excludeUserIds);
- if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
+ desc: {
+ 'ja-JP': '返信に限定するか否か'
+ }
+ }),
- // Get 'includeUserUsernames' parameter
- const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional.get(params.includeUserUsernames);
- if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
+ renote: $.bool.optional.nullable.note({
+ default: null,
- // Get 'excludeUserUsernames' parameter
- const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional.get(params.excludeUserUsernames);
- if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
+ desc: {
+ 'ja-JP': 'Renoteに限定するか否か'
+ }
+ }),
- // Get 'following' parameter
- const [following = null, followingErr] = $.bool.optional.nullable.get(params.following);
- if (followingErr) return rej('invalid following param');
+ withFiles: $.bool.optional.nullable.note({
+ default: null,
- // Get 'mute' parameter
- const [mute = 'mute_all', muteErr] = $.str.optional.get(params.mute);
- if (muteErr) return rej('invalid mute param');
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か'
+ }
+ }),
- // Get 'reply' parameter
- const [reply = null, replyErr] = $.bool.optional.nullable.get(params.reply);
- if (replyErr) return rej('invalid reply param');
+ media: $.bool.optional.nullable.note({
+ default: null,
- // Get 'renote' parameter
- const [renote = null, renoteErr] = $.bool.optional.nullable.get(params.renote);
- if (renoteErr) return rej('invalid renote param');
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
+ }
+ }),
- // Get 'media' parameter
- const [media = null, mediaErr] = $.bool.optional.nullable.get(params.media);
- if (mediaErr) return rej('invalid media param');
+ poll: $.bool.optional.nullable.note({
+ default: null,
- // Get 'poll' parameter
- const [poll = null, pollErr] = $.bool.optional.nullable.get(params.poll);
- if (pollErr) return rej('invalid poll param');
+ desc: {
+ 'ja-JP': 'アンケートが添付された投稿に限定するか否か'
+ }
+ }),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ sinceDate: $.num.optional.note({
+ }),
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+ untilDate: $.num.optional.note({
+ }),
- // Get 'offset' parameter
- const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
- if (offsetErr) return rej('invalid offset param');
+ offset: $.num.optional.min(0).note({
+ default: 0
+ }),
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
- if (limitErr) return rej('invalid limit param');
+ limit: $.num.optional.range(1, 30).note({
+ default: 10
+ }),
+ }
+};
+
+export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
- if (includeUserUsernames != null) {
- const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
+ if (ps.includeUserUsernames != null) {
+ const ids = erase(null, await Promise.all(ps.includeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
- }))).filter(id => id != null);
+ })));
- ids.forEach(id => includeUserIds.push(id));
+ ids.forEach(id => ps.includeUserIds.push(id));
}
- if (excludeUserUsernames != null) {
- const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
+ if (ps.excludeUserUsernames != null) {
+ const ids = erase(null, await Promise.all(ps.excludeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
- }))).filter(id => id != null);
+ })));
- ids.forEach(id => excludeUserIds.push(id));
+ ids.forEach(id => ps.excludeUserIds.push(id));
}
- let q: any = {
+ const q: any = {
$and: [{
- tagsLower: tag.toLowerCase()
- }]
+ tagsLower: ps.tag.toLowerCase()
+ }],
+ deletedAt: { $exists: false }
};
const push = (x: any) => q.$and.push(x);
- if (includeUserIds && includeUserIds.length != 0) {
+ if (ps.includeUserIds && ps.includeUserIds.length != 0) {
push({
userId: {
- $in: includeUserIds
+ $in: ps.includeUserIds
}
});
- } else if (excludeUserIds && excludeUserIds.length != 0) {
+ } else if (ps.excludeUserIds && ps.excludeUserIds.length != 0) {
push({
userId: {
- $nin: excludeUserIds
+ $nin: ps.excludeUserIds
}
});
}
- if (following != null && me != null) {
+ if (ps.following != null && me != null) {
const ids = await getFriendIds(me._id, false);
push({
- userId: following ? {
+ userId: ps.following ? {
$in: ids
} : {
$nin: ids.concat(me._id)
@@ -131,7 +166,7 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
});
const mutedUserIds = mutes.map(m => m.muteeId);
- switch (mute) {
+ switch (ps.mute) {
case 'mute_all':
push({
userId: {
@@ -202,8 +237,8 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}
}
- if (reply != null) {
- if (reply) {
+ if (ps.reply != null) {
+ if (ps.reply) {
push({
replyId: {
$exists: true,
@@ -223,8 +258,8 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}
}
- if (renote != null) {
- if (renote) {
+ if (ps.renote != null) {
+ if (ps.renote) {
push({
renoteId: {
$exists: true,
@@ -244,10 +279,12 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}
}
- if (media != null) {
- if (media) {
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.media;
+
+ if (withFiles != null) {
+ if (withFiles) {
push({
- mediaIds: {
+ fileIds: {
$exists: true,
$ne: null
}
@@ -255,18 +292,18 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
} else {
push({
$or: [{
- mediaIds: {
+ fileIds: {
$exists: false
}
}, {
- mediaIds: null
+ fileIds: null
}]
});
}
}
- if (poll != null) {
- if (poll) {
+ if (ps.poll != null) {
+ if (ps.poll) {
push({
poll: {
$exists: true,
@@ -286,24 +323,24 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}
}
- if (sinceDate) {
+ if (ps.sinceDate) {
push({
createdAt: {
- $gt: new Date(sinceDate)
+ $gt: new Date(ps.sinceDate)
}
});
}
- if (untilDate) {
+ if (ps.untilDate) {
push({
createdAt: {
- $lt: new Date(untilDate)
+ $lt: new Date(ps.untilDate)
}
});
}
if (q.$and.length == 0) {
- q = {};
+ delete q.$and;
}
// Search notes
@@ -312,8 +349,8 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
sort: {
_id: -1
},
- limit: limit,
- skip: offset
+ limit: ps.limit,
+ skip: ps.offset
});
// Serialize
diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts
index 099bf2010b..5f3844987c 100644
--- a/src/server/api/endpoints/notes/timeline.ts
+++ b/src/server/api/endpoints/notes/timeline.ts
@@ -5,6 +5,7 @@ import { getFriends } from '../../common/get-friends';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
import getParams from '../../get-params';
+import { countIf } from '../../../../prelude/array';
export const meta = {
desc: {
@@ -67,9 +68,15 @@ export const meta = {
}
}),
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
+ }
+ }),
+
mediaOnly: $.bool.optional.note({
desc: {
- 'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します'
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
}
}),
}
@@ -80,7 +87,7 @@ export default async (params: any, user: ILocalUser) => {
if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
+ if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
@@ -154,7 +161,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -170,7 +177,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -186,16 +193,18 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
});
}
- if (ps.mediaOnly) {
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
+ if (withFiles) {
query.$and.push({
- mediaIds: { $exists: true, $ne: [] }
+ fileIds: { $exists: true, $ne: [] }
});
}
diff --git a/src/server/api/endpoints/notes/trend.ts b/src/server/api/endpoints/notes/trend.ts
index 7a0a098f28..9f55ed3243 100644
--- a/src/server/api/endpoints/notes/trend.ts
+++ b/src/server/api/endpoints/notes/trend.ts
@@ -52,7 +52,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}
if (media != undefined) {
- query.mediaIds = media ? { $exists: true, $ne: null } : null;
+ query.fileIds = media ? { $exists: true, $ne: null } : null;
}
if (poll != undefined) {
diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts
index a7b43014ed..61192d7d3e 100644
--- a/src/server/api/endpoints/notes/user-list-timeline.ts
+++ b/src/server/api/endpoints/notes/user-list-timeline.ts
@@ -73,9 +73,15 @@ export const meta = {
}
}),
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
+ }
+ }),
+
mediaOnly: $.bool.optional.note({
desc: {
- 'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します'
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
}
}),
}
@@ -160,7 +166,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -176,7 +182,7 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
@@ -192,16 +198,18 @@ export default async (params: any, user: ILocalUser) => {
}, {
text: { $ne: null }
}, {
- mediaIds: { $ne: [] }
+ fileIds: { $ne: [] }
}, {
poll: { $ne: null }
}]
});
}
- if (ps.mediaOnly) {
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
+ if (withFiles) {
query.$and.push({
- mediaIds: { $exists: true, $ne: [] }
+ fileIds: { $exists: true, $ne: [] }
});
}