|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const sockets = require('../socket.io');
|
|
|
|
|
const plugins = require('../plugins');
|
|
|
|
|
|
|
|
|
|
module.exports = function (Messaging) {
|
|
|
|
|
Messaging.deleteMessage = async (mid, uid) => await doDeleteRestore(mid, 1, uid);
|
|
|
|
@ -8,7 +9,7 @@ module.exports = function (Messaging) {
|
|
|
|
|
|
|
|
|
|
async function doDeleteRestore(mid, state, uid) {
|
|
|
|
|
const field = state ? 'deleted' : 'restored';
|
|
|
|
|
const { deleted, roomId } = await Messaging.getMessageFields(mid, ['deleted', 'roomId']);
|
|
|
|
|
const { content, deleted, roomId } = await Messaging.getMessageFields(mid, ['deleted', 'roomId', 'content']);
|
|
|
|
|
if (deleted === state) {
|
|
|
|
|
throw new Error(`[[error:chat-${field}-already]]`);
|
|
|
|
|
}
|
|
|
|
@ -17,9 +18,11 @@ module.exports = function (Messaging) {
|
|
|
|
|
const ioRoom = sockets.in(`chat_room_${roomId}`);
|
|
|
|
|
if (state === 1 && ioRoom) {
|
|
|
|
|
ioRoom.emit('event:chats.delete', mid);
|
|
|
|
|
plugins.hooks.fire('action:messaging.delete', { message: { mid, content, deleted: 1, roomId } });
|
|
|
|
|
} else if (state === 0 && ioRoom) {
|
|
|
|
|
const messages = await Messaging.getMessagesData([mid], uid, roomId, true);
|
|
|
|
|
ioRoom.emit('event:chats.restore', messages[0]);
|
|
|
|
|
plugins.hooks.fire('action:messaging.restore', { message: { ...messages[0], content } });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|