diff --git a/public/openapi/components/schemas/Chats.yaml b/public/openapi/components/schemas/Chats.yaml index 3af68f754a..fe2ff9f73c 100644 --- a/public/openapi/components/schemas/Chats.yaml +++ b/public/openapi/components/schemas/Chats.yaml @@ -46,6 +46,8 @@ MessageObject: type: string editedISO: type: string + mid: + type: number messageId: type: number fromUser: diff --git a/public/openapi/read/user/userslug/chats/roomid.yaml b/public/openapi/read/user/userslug/chats/roomid.yaml index d3eaee8e67..025499b753 100644 --- a/public/openapi/read/user/userslug/chats/roomid.yaml +++ b/public/openapi/read/user/userslug/chats/roomid.yaml @@ -69,6 +69,8 @@ get: description: An ISO 8601 formatted date string (complementing `timestamp`) editedISO: type: string + mid: + type: number messageId: type: number fromUser: diff --git a/src/messaging/create.js b/src/messaging/create.js index ed6b0b6a33..fe0fbb7de0 100644 --- a/src/messaging/create.js +++ b/src/messaging/create.js @@ -86,9 +86,7 @@ module.exports = function (Messaging) { } messages[0].newSet = isNewSet; - messages[0].mid = mid; // TODO: messageId is a duplicate - messages[0].roomId = roomId; - plugins.hooks.fire('action:messaging.save', { message: messages[0], data: data }); + plugins.hooks.fire('action:messaging.save', { message: message, data: data }); return messages[0]; }; diff --git a/src/messaging/delete.js b/src/messaging/delete.js index 0363481e42..aca7570c34 100644 --- a/src/messaging/delete.js +++ b/src/messaging/delete.js @@ -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 } }); } } }; diff --git a/src/messaging/edit.js b/src/messaging/edit.js index d54b5dc587..bd930f9ae9 100644 --- a/src/messaging/edit.js +++ b/src/messaging/edit.js @@ -31,6 +31,7 @@ module.exports = function (Messaging) { sockets.in(`chat_room_${roomId}`).emit('event:chats.edit', { messages: messages, }); + plugins.hooks.fire('action:messaging.edit', { message: messages[0] }); }; const canEditDelete = async (messageId, uid, type) => {