2018-12-29 14:26:15 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 11:33:41 +02:00
|
|
|
import { ID } from '@/misc/cafy-id.js';
|
|
|
|
import define from '../../../define.js';
|
2019-02-01 16:16:27 +01:00
|
|
|
import * as ms from 'ms';
|
2021-08-19 11:33:41 +02:00
|
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
import { MessagingMessages } from '@/models/index.js';
|
|
|
|
import { deleteMessage } from '@/services/messages/delete.js';
|
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,
|
|
|
|
minInterval: ms('1sec')
|
|
|
|
},
|
|
|
|
|
|
|
|
params: {
|
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
}
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
|
|
|
id: '54b5b326-7925-42cf-8019-130fda8b56af'
|
|
|
|
},
|
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,
|
|
|
|
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
|
|
|
});
|