2019-02-04 20:48:08 -06:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform } from '../../../../misc/cafy-id';
|
2019-01-19 04:16:48 -06:00
|
|
|
import define from '../../define';
|
|
|
|
import User from '../../../../models/user';
|
|
|
|
import AbuseUserReport from '../../../../models/abuse-user-report';
|
2019-02-04 23:14:23 -06:00
|
|
|
import { publishAdminStream } from '../../../../services/stream';
|
2019-01-19 04:16:48 -06:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定したユーザーを迷惑なユーザーであると報告します。'
|
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象のユーザーのID',
|
|
|
|
'en-US': 'Target user ID'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
comment: {
|
|
|
|
validator: $.str.range(1, 3000),
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '迷惑行為の詳細'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
|
|
|
// Lookup user
|
|
|
|
const user = await User.findOne({
|
|
|
|
_id: ps.userId
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user === null) {
|
|
|
|
return rej('user not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user._id.equals(me._id)) {
|
|
|
|
return rej('cannot report yourself');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.isAdmin) {
|
|
|
|
return rej('cannot report admin');
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:55:02 -06:00
|
|
|
const report = await AbuseUserReport.insert({
|
2019-01-19 04:16:48 -06:00
|
|
|
createdAt: new Date(),
|
|
|
|
userId: user._id,
|
|
|
|
reporterId: me._id,
|
|
|
|
comment: ps.comment
|
|
|
|
});
|
|
|
|
|
2019-01-26 23:55:02 -06:00
|
|
|
// Publish event to moderators
|
|
|
|
setTimeout(async () => {
|
|
|
|
const moderators = await User.find({
|
|
|
|
$or: [{
|
|
|
|
isAdmin: true
|
|
|
|
}, {
|
|
|
|
isModerator: true
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
for (const moderator of moderators) {
|
|
|
|
publishAdminStream(moderator._id, 'newAbuseUserReport', {
|
|
|
|
id: report._id,
|
|
|
|
userId: report.userId,
|
|
|
|
reporterId: report.reporterId,
|
|
|
|
comment: report.comment
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
|
2019-01-19 04:16:48 -06:00
|
|
|
res();
|
|
|
|
}));
|