2019-02-05 03:48:08 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-11-02 05:47:44 +01:00
|
|
|
import define from '../../../define';
|
2019-02-01 16:16:27 +01:00
|
|
|
import * as ms from 'ms';
|
2019-01-19 19:07:12 +01:00
|
|
|
import deleteReaction from '../../../../../services/note/reaction/delete';
|
2019-02-22 06:02:56 +01:00
|
|
|
import { getNote } from '../../../common/getters';
|
2019-02-22 03:46:58 +01:00
|
|
|
import { ApiError } from '../../../error';
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-07-16 21:36:44 +02:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-28 23:59:43 +02:00
|
|
|
'ja-JP': '指定した投稿へのリアクションを取り消します。',
|
|
|
|
'en-US': 'Unreact to a note.'
|
2018-07-16 21:36:44 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
2018-11-01 19:32:24 +01:00
|
|
|
kind: 'reaction-write',
|
|
|
|
|
2018-12-26 15:05:47 +01:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 5,
|
|
|
|
minInterval: ms('3sec')
|
|
|
|
},
|
|
|
|
|
2018-11-01 19:32:24 +01:00
|
|
|
params: {
|
|
|
|
noteId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
2018-11-03 14:49:36 +01:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象の投稿のID',
|
|
|
|
'en-US': 'Target note ID'
|
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
},
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
|
|
|
message: 'No such note.',
|
|
|
|
code: 'NO_SUCH_NOTE',
|
|
|
|
id: '764d9fce-f9f2-4a0e-92b1-6ceac9a7ad37'
|
|
|
|
},
|
|
|
|
|
|
|
|
notReacted: {
|
|
|
|
message: 'You are not reacting to that note.',
|
|
|
|
code: 'NOT_REACTED',
|
|
|
|
id: '92f4426d-4196-4125-aa5b-02943e2ec8fc'
|
|
|
|
},
|
2018-11-01 19:32:24 +01:00
|
|
|
}
|
2018-07-16 21:36:44 +02:00
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
2019-02-22 06:02:56 +01:00
|
|
|
const note = await getNote(ps.noteId).catch(e => {
|
2019-02-22 03:46:58 +01:00
|
|
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
await deleteReaction(user, note).catch(e => {
|
|
|
|
if (e.id === '60527ec9-b4cb-4a88-a6bd-32d3ad26817d') throw new ApiError(meta.errors.notReacted);
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
});
|