2021-08-19 21:55:45 +09:00
|
|
|
import acceptFollowRequest from '@/services/following/requests/accept';
|
|
|
|
|
import define from '../../../define';
|
|
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
|
import { getUser } from '../../../common/getters';
|
2018-06-01 21:55:27 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['following', 'account'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
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
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
errors: {
|
|
|
|
|
noSuchUser: {
|
|
|
|
|
message: 'No such user.',
|
|
|
|
|
code: 'NO_SUCH_USER',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '66ce1645-d66c-46bb-8b79-96739af885bd',
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
2020-12-26 15:31:28 +09:00
|
|
|
noFollowRequest: {
|
|
|
|
|
message: 'No follow request.',
|
|
|
|
|
code: 'NO_FOLLOW_REQUEST',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: 'bcde4f8b-0913-4614-8881-614e522fb041',
|
2020-12-26 15:31:28 +09:00
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2022-02-19 14:05:32 +09:00
|
|
|
const paramDef = {
|
|
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
|
|
|
},
|
|
|
|
|
required: ['userId'],
|
|
|
|
|
} as const;
|
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, 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;
|
|
|
|
|
});
|