salix/back/models/chat.js

25 lines
785 B
JavaScript

module.exports = Self => {
require('../methods/chat/getServiceAuth')(Self);
require('../methods/chat/send')(Self);
require('../methods/chat/sendCheckingPresence')(Self);
require('../methods/chat/notifyIssues')(Self);
require('../methods/chat/sendQueued')(Self);
Self.observe('before save', async function(ctx) {
if (!ctx.isNewInstance) return;
let {message} = ctx.instance;
if (!message) return;
const parts = message.match(/(?<=\[).*(?=])/g);
const replacedParts = parts.map(part => {
return part.replace(/[*()]/g, '');
});
for (const [index, part] of parts.entries())
message = message.replace(part, replacedParts[index]);
ctx.instance.message = message;
});
};