2018-12-29 14:26:15 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 14:55:45 +02:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import define from '../../../define';
|
2021-11-12 11:47:04 +01:00
|
|
|
import ms from 'ms';
|
2021-08-19 14:55:45 +02:00
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
import { MessagingMessages } from '@/models/index';
|
|
|
|
import { deleteMessage } from '@/services/messages/delete';
|
2018-12-26 17:24:57 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['messaging'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2018-12-26 17:24:57 +01:00
|
|
|
|
2019-04-15 05:10:40 +02:00
|
|
|
kind: 'write:messaging',
|
2018-12-26 17:24:57 +01:00
|
|
|
|
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 300,
|
2021-12-09 15:58:30 +01:00
|
|
|
minInterval: ms('1sec'),
|
2018-12-26 17:24:57 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
params: {
|
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '54b5b326-7925-42cf-8019-130fda8b56af',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2018-12-26 17:24:57 +01:00
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const message = await MessagingMessages.findOne({
|
|
|
|
id: ps.messageId,
|
2021-12-09 15:58:30 +01:00
|
|
|
userId: user.id,
|
2018-12-26 17:24:57 +01:00
|
|
|
});
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (message == null) {
|
2019-02-22 03:46:58 +01:00
|
|
|
throw new ApiError(meta.errors.noSuchMessage);
|
2018-12-26 17:24:57 +01:00
|
|
|
}
|
|
|
|
|
2020-11-01 04:14:42 +01:00
|
|
|
await deleteMessage(message);
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|