2021-08-19 21:55:45 +09:00
|
|
|
import cancelFollowRequest from '@/services/following/requests/cancel';
|
|
|
|
|
import define from '../../../define';
|
|
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
|
import { getUser } from '../../../common/getters';
|
|
|
|
|
import { Users } from '@/models/index';
|
2022-02-04 02:06:24 +09:00
|
|
|
import { IdentifiableError } from '@/misc/identifiable-error';
|
2018-06-02 00:51:20 +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: '4e68c551-fc4c-4e46-bb41-7d4a37bf9dab',
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
followRequestNotFound: {
|
|
|
|
|
message: 'Follow request not found.',
|
|
|
|
|
code: 'FOLLOW_REQUEST_NOT_FOUND',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '089b125b-d338-482a-9a09-e2622ac9f8d4',
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
|
optional: false, nullable: false,
|
|
|
|
|
ref: 'UserLite',
|
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-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
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-02 12:58:56 +09:00
|
|
|
// Fetch followee
|
2019-02-22 14:02:56 +09:00
|
|
|
const followee = await getUser(ps.userId).catch(e => {
|
|
|
|
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
|
|
|
|
throw e;
|
2018-06-02 00:51:20 +09:00
|
|
|
});
|
|
|
|
|
|
2018-08-23 14:56:39 +09:00
|
|
|
try {
|
|
|
|
|
await cancelFollowRequest(followee, user);
|
|
|
|
|
} catch (e) {
|
2022-02-04 02:06:24 +09:00
|
|
|
if (e instanceof IdentifiableError) {
|
|
|
|
|
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound);
|
|
|
|
|
}
|
2019-02-22 11:46:58 +09:00
|
|
|
throw e;
|
2018-08-23 14:56:39 +09:00
|
|
|
}
|
2018-06-02 00:51:20 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
return await Users.pack(followee.id, user);
|
2019-02-22 11:46:58 +09:00
|
|
|
});
|