salix/back/models/chat.js

27 lines
876 B
JavaScript
Raw Permalink Normal View History

module.exports = Self => {
require('../methods/chat/getServiceAuth')(Self);
2020-01-20 06:33:24 +00:00
require('../methods/chat/send')(Self);
require('../methods/chat/sendCheckingPresence')(Self);
2021-02-01 08:29:47 +00:00
require('../methods/chat/notifyIssues')(Self);
2022-06-02 12:55:39 +00:00
require('../methods/chat/sendQueued')(Self);
Self.observe('before save', async function(ctx) {
if (!ctx.isNewInstance) return;
let {message} = ctx.instance;
if (!message) return;
2022-11-25 11:26:58 +00:00
const parts = message.match(/(?<=\[)[a-zA-Z0-9_\-+!@#$%^&*()={};':"\\|,.<>/?\s]*(?=])/g);
2022-11-25 11:12:48 +00:00
if (!parts) return;
const replacedParts = parts.map(part => {
2022-11-25 11:26:58 +00:00
return part.replace(/[!$%^&*()={};':"\\,.<>/?]/g, '');
});
for (const [index, part] of parts.entries())
message = message.replace(part, replacedParts[index]);
ctx.instance.message = message;
});
};