2022-02-27 04:07:39 +02:00
|
|
|
import define from '../../../define.js';
|
2021-11-12 12:47:04 +02:00
|
|
|
import ms from 'ms';
|
2022-02-27 04:07:39 +02:00
|
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
import { MessagingMessages } from '@/models/index.js';
|
|
|
|
import { deleteMessage } from '@/services/messages/delete.js';
|
2018-12-26 18:24:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['messaging'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: true,
|
2018-12-26 18:24:57 +02:00
|
|
|
|
2019-04-15 06:10:40 +03:00
|
|
|
kind: 'write:messaging',
|
2018-12-26 18:24:57 +02:00
|
|
|
|
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 300,
|
2021-12-09 16:58:30 +02:00
|
|
|
minInterval: ms('1sec'),
|
2018-12-26 18:24:57 +02:00
|
|
|
},
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '54b5b326-7925-42cf-8019-130fda8b56af',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2018-12-26 18:24:57 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
messageId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['messageId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 07:05:32 +02:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-04-07 15:50:36 +03:00
|
|
|
const message = await MessagingMessages.findOne({
|
|
|
|
id: ps.messageId,
|
2021-12-09 16:58:30 +02:00
|
|
|
userId: user.id,
|
2018-12-26 18:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-04-07 15:50:36 +03:00
|
|
|
if (message == null) {
|
2019-02-22 04:46:58 +02:00
|
|
|
throw new ApiError(meta.errors.noSuchMessage);
|
2018-12-26 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2020-11-01 05:14:42 +02:00
|
|
|
await deleteMessage(message);
|
2019-02-22 04:46:58 +02:00
|
|
|
});
|