2021-11-12 11:47:04 +01:00
|
|
|
import ms from 'ms';
|
2022-02-27 03:07:39 +01:00
|
|
|
import deleteReaction from '@/services/note/reaction/delete.js';
|
2022-06-14 11:01:23 +02:00
|
|
|
import define from '../../../define.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { getNote } from '../../../common/getters.js';
|
|
|
|
import { ApiError } from '../../../error.js';
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-07-16 21:36:44 +02:00
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['reactions', 'notes'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2018-07-16 21:36:44 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
kind: 'write:reactions',
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2018-12-26 15:05:47 +01:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
2019-03-17 16:03:57 +01:00
|
|
|
max: 60,
|
2021-12-09 15:58:30 +01:00
|
|
|
minInterval: ms('3sec'),
|
2018-12-26 15:05:47 +01:00
|
|
|
},
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
|
|
|
message: 'No such note.',
|
|
|
|
code: 'NO_SUCH_NOTE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '764d9fce-f9f2-4a0e-92b1-6ceac9a7ad37',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
notReacted: {
|
|
|
|
message: 'You are not reacting to that note.',
|
|
|
|
code: 'NOT_REACTED',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '92f4426d-4196-4125-aa5b-02943e2ec8fc',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2018-07-16 21:36:44 +02:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
noteId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['noteId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 06:05:32 +01:00
|
|
|
export default define(meta, paramDef, 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;
|
|
|
|
});
|
|
|
|
});
|