2019-02-05 11:48:08 +09:00
|
|
|
import $ from 'cafy';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { ID } from '../../../../../misc/cafy-id';
|
2018-06-02 00:15:17 +09:00
|
|
|
import acceptFollowRequest from '../../../../../services/following/requests/accept';
|
2018-11-02 13:47:44 +09:00
|
|
|
import define from '../../../define';
|
2019-02-22 11:46:58 +09:00
|
|
|
import { ApiError } from '../../../error';
|
2019-02-22 14:02:56 +09:00
|
|
|
import { getUser } from '../../../common/getters';
|
2018-06-01 21:55:27 +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': 'Accept a follow request.'
|
2018-07-17 04:36:44 +09:00
|
|
|
},
|
|
|
|
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['following', 'account'],
|
|
|
|
|
2020-02-15 21:33:32 +09:00
|
|
|
requireCredential: true as const,
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
kind: 'write:following',
|
2018-11-02 03:32:24 +09:00
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
2018-11-03 22:49:36 +09:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象のユーザーのID',
|
|
|
|
'en-US': 'Target user ID'
|
|
|
|
}
|
2018-11-02 03:32:24 +09:00
|
|
|
}
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
|
|
|
id: '66ce1645-d66c-46bb-8b79-96739af885bd'
|
|
|
|
},
|
2020-12-26 15:31:28 +09:00
|
|
|
noFollowRequest: {
|
|
|
|
message: 'No follow request.',
|
|
|
|
code: 'NO_FOLLOW_REQUEST',
|
|
|
|
id: 'bcde4f8b-0913-4614-8881-614e522fb041'
|
|
|
|
},
|
2018-11-02 03:32:24 +09:00
|
|
|
}
|
2018-07-17 04:36:44 +09:00
|
|
|
};
|
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-06-01 21:55:27 +09:00
|
|
|
// Fetch follower
|
2019-02-22 14:02:56 +09:00
|
|
|
const follower = await getUser(ps.userId).catch(e => {
|
|
|
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
|
|
|
throw e;
|
2018-06-01 21:55:27 +09:00
|
|
|
});
|
|
|
|
|
2020-12-26 15:31:28 +09:00
|
|
|
await acceptFollowRequest(user, follower).catch(e => {
|
|
|
|
if (e.id === '8884c2dd-5795-4ac9-b27e-6a01d38190f9') throw new ApiError(meta.errors.noFollowRequest);
|
|
|
|
throw e;
|
|
|
|
});
|
2018-06-01 21:55:27 +09:00
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
return;
|
|
|
|
});
|