add missing hooks

isekai-main
Barış Soner Uşaklı 2 years ago
parent 78aa904e97
commit e68f7c2064

@ -46,6 +46,8 @@ MessageObject:
type: string
editedISO:
type: string
mid:
type: number
messageId:
type: number
fromUser:

@ -69,6 +69,8 @@ get:
description: An ISO 8601 formatted date string (complementing `timestamp`)
editedISO:
type: string
mid:
type: number
messageId:
type: number
fromUser:

@ -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];
};

@ -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 } });
}
}
};

@ -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) => {

Loading…
Cancel
Save