1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-23 02:58:30 +09:00
misskey/src/server/api/endpoints/notes/polls/recommendation.ts

72 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-03-25 16:43:55 +09:00
import $ from 'cafy';
2018-03-29 20:32:18 +09:00
import Vote from '../../../../../models/poll-vote';
2018-04-08 02:30:37 +09:00
import Note, { pack } from '../../../../../models/note';
2018-11-02 13:47:44 +09:00
import define from '../../../define';
import Mute from '../../../../../models/mute';
2017-03-25 16:43:55 +09:00
2018-07-17 04:36:44 +09:00
export const meta = {
desc: {
2018-08-29 06:59:43 +09:00
'ja-JP': 'おすすめのアンケート一覧を取得します。',
'en-US': 'Get recommended polls.'
2018-07-17 04:36:44 +09:00
},
requireCredential: true,
2018-11-02 12:49:08 +09:00
params: {
limit: {
validator: $.num.optional.range(1, 100),
default: 10
},
offset: {
validator: $.num.optional.min(0),
default: 0
}
}
2018-07-17 04:36:44 +09:00
};
2018-11-02 13:47:44 +09:00
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
2017-03-25 16:43:55 +09:00
// Get votes
const votes = await Vote.find({
2018-03-29 14:48:47 +09:00
userId: user._id
2017-03-25 16:43:55 +09:00
}, {
fields: {
_id: false,
2018-04-08 02:30:37 +09:00
noteId: true
2017-03-25 16:43:55 +09:00
}
});
2018-04-08 02:30:37 +09:00
const nin = votes && votes.length != 0 ? votes.map(v => v.noteId) : [];
2017-03-25 16:43:55 +09:00
// ミュートしているユーザーを取得
const mutedUserIds = await Mute.find({
muterId: user._id
}).then(ms => ms.map(m => m.muteeId));
2018-04-08 02:30:37 +09:00
const notes = await Note
2017-03-25 16:43:55 +09:00
.find({
2018-12-20 22:56:12 +09:00
'_user.host': null,
2017-03-25 16:43:55 +09:00
_id: {
$nin: nin
},
2018-03-29 14:48:47 +09:00
userId: {
$ne: user._id,
$nin: mutedUserIds
},
2017-03-25 16:43:55 +09:00
poll: {
$exists: true,
$ne: null
}
}, {
2018-11-02 12:49:08 +09:00
limit: ps.limit,
skip: ps.offset,
2017-03-25 16:43:55 +09:00
sort: {
_id: -1
}
});
2018-11-02 12:49:08 +09:00
res(await Promise.all(notes.map(note => pack(note, user, {
detail: true
}))));
2018-11-02 13:47:44 +09:00
}));