2018-12-29 15:26:15 +02:00
|
|
|
import $ from 'cafy';
|
2021-08-19 12:33:41 +03:00
|
|
|
import { ID } from '@/misc/cafy-id.js';
|
|
|
|
import define from '../../../define.js';
|
2019-02-01 17:16:27 +02:00
|
|
|
import * as ms from 'ms';
|
2021-08-19 12:33:41 +03: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'],
|
|
|
|
|
2020-02-15 14:33:32 +02:00
|
|
|
requireCredential: true as const,
|
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,
|
|
|
|
minInterval: ms('1sec')
|
|
|
|
},
|
|
|
|
|
|
|
|
params: {
|
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
}
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
|
|
|
id: '54b5b326-7925-42cf-8019-130fda8b56af'
|
|
|
|
},
|
2018-12-26 18:24:57 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
export default define(meta, async (ps, user) => {
|
2019-04-07 15:50:36 +03:00
|
|
|
const message = await MessagingMessages.findOne({
|
|
|
|
id: ps.messageId,
|
|
|
|
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
|
|
|
});
|