salix/back/models/chat.js

25 lines
785 B
JavaScript
Raw 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 08:18:21 +00:00
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;
});
};