2019-02-05 02:48:08 +00:00
|
|
|
import $ from 'cafy';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { ID } from '../../../../../misc/cafy-id';
|
2018-06-01 15:51:20 +00:00
|
|
|
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
2018-11-02 04:47:44 +00:00
|
|
|
import define from '../../../define';
|
2019-02-22 02:46:58 +00:00
|
|
|
import { ApiError } from '../../../error';
|
2019-02-22 05:02:56 +00:00
|
|
|
import { getUser } from '../../../common/getters';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { Users } from '../../../../../models';
|
2018-06-01 15:51:20 +00:00
|
|
|
|
2018-07-16 19:36:44 +00:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-28 21:59:43 +00:00
|
|
|
'ja-JP': '自分が作成した、指定したフォローリクエストをキャンセルします。',
|
|
|
|
'en-US': 'Cancel a follow request.'
|
2018-07-16 19:36:44 +00:00
|
|
|
},
|
|
|
|
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['following', 'account'],
|
|
|
|
|
2020-02-15 12:33:32 +00:00
|
|
|
requireCredential: true as const,
|
2018-07-16 19:36:44 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
kind: 'write:following',
|
2018-11-01 18:32:24 +00:00
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
2018-11-03 13:49:36 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象のユーザーのID',
|
|
|
|
'en-US': 'Target user ID'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
}
|
2019-02-22 02:46:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
|
|
|
id: '4e68c551-fc4c-4e46-bb41-7d4a37bf9dab'
|
|
|
|
},
|
|
|
|
|
|
|
|
followRequestNotFound: {
|
|
|
|
message: 'Follow request not found.',
|
|
|
|
code: 'FOLLOW_REQUEST_NOT_FOUND',
|
|
|
|
id: '089b125b-d338-482a-9a09-e2622ac9f8d4'
|
|
|
|
},
|
2021-03-06 13:34:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'User'
|
2018-11-01 18:32:24 +00:00
|
|
|
}
|
2018-07-16 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-06-02 03:58:56 +00:00
|
|
|
// Fetch followee
|
2019-02-22 05:02:56 +00: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-01 15:51:20 +00:00
|
|
|
});
|
|
|
|
|
2018-08-23 05:56:39 +00:00
|
|
|
try {
|
|
|
|
await cancelFollowRequest(followee, user);
|
|
|
|
} catch (e) {
|
2019-02-22 02:46:58 +00:00
|
|
|
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound);
|
|
|
|
throw e;
|
2018-08-23 05:56:39 +00:00
|
|
|
}
|
2018-06-01 15:51:20 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await Users.pack(followee.id, user);
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|