summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-16 22:48:57 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-16 22:48:57 +0900
commit32afe77a269f414965373e3c53044c4a94cfeded (patch)
treea0a41922b1f40704c471d0892d403dfcd9f8dbcd /src/server/api/endpoints
parentenable-animations --> reduce-motion (diff)
downloadsharkey-32afe77a269f414965373e3c53044c4a94cfeded.tar.gz
sharkey-32afe77a269f414965373e3c53044c4a94cfeded.tar.bz2
sharkey-32afe77a269f414965373e3c53044c4a94cfeded.zip
自分宛ての投稿をタイムラインで見れるように
Diffstat (limited to 'src/server/api/endpoints')
-rw-r--r--src/server/api/endpoints/notes/mentions.ts59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts
index a7fb14d8a9..3b2e262e4f 100644
--- a/src/server/api/endpoints/notes/mentions.ts
+++ b/src/server/api/endpoints/notes/mentions.ts
@@ -3,6 +3,7 @@ import Note from '../../../../models/note';
import { getFriendIds } from '../../common/get-friends';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
export const meta = {
desc: {
@@ -10,42 +11,48 @@ export const meta = {
'en-US': 'Get mentions of myself.'
},
- requireCredential: true
-};
+ requireCredential: true,
-export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
- // Get 'following' parameter
- const [following = false, followingError] =
- $.bool.optional.get(params.following);
- if (followingError) return rej('invalid following param');
+ params: {
+ following: $.bool.optional.note({
+ default: false
+ }),
+
+ limit: $.num.optional.range(1, 100).note({
+ default: 10
+ }),
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) return rej('invalid limit param');
+ sinceId: $.type(ID).optional.note({
+ }),
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) return rej('invalid sinceId param');
+ untilId: $.type(ID).optional.note({
+ }),
+ }
+};
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) return rej('invalid untilId param');
+export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
// Check if both of sinceId and untilId is specified
- if (sinceId && untilId) {
+ if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId');
}
// Construct query
const query = {
- mentions: user._id
+ $or: [{
+ mentions: user._id
+ }, {
+ visibleUserIds: user._id
+ }]
} as any;
const sort = {
_id: -1
};
- if (following) {
+ if (ps.following) {
const followingIds = await getFriendIds(user._id);
query.userId = {
@@ -53,26 +60,24 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
};
}
- 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
};
}
// Issue query
const mentions = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});
// Serialize
- res(await Promise.all(mentions.map(async mention =>
- await pack(mention, user)
- )));
+ res(await Promise.all(mentions.map(mention => pack(mention, user))));
});