Merge pull request 'feat: sendCheckingPresence debug' (!3349) from sendCheckPresenceDebug into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3349
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Robert Ferrús 2025-01-10 09:13:58 +00:00
commit 26a319832c
1 changed files with 39 additions and 30 deletions

View File

@ -27,17 +27,19 @@ module.exports = Self => {
}); });
Self.sendCheckingPresence = async(ctx, recipientId, message) => { Self.sendCheckingPresence = async(ctx, recipientId, message) => {
if (!recipientId) return false;
const models = Self.app.models;
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
try {
const models = Self.app.models;
const sender = await models.VnUser.findById(userId, {fields: ['id']}); const sender = await models.VnUser.findById(userId, {fields: ['id']});
const error = `Could not send message from user ${userId}`;
if (!recipientId) throw new Error(error);
const recipient = await models.VnUser.findById(recipientId, null); const recipient = await models.VnUser.findById(recipientId, null);
if (!recipient)
throw new Error(error);
// Prevent sending messages to yourself // Prevent sending messages to yourself
if (recipientId == userId) return false; if (recipientId == userId) return false;
if (!recipient)
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
if (!isProduction()) if (!isProduction())
message = `[Test:Environment to user ${userId}] ` + message; message = `[Test:Environment to user ${userId}] ` + message;
@ -60,5 +62,12 @@ module.exports = Self => {
} }
return true; return true;
} catch (e) {
await Self.rawSql(`
INSERT INTO util.debug (variable, value)
VALUES ('sendCheckingPresence_error', ?)
`, [`User: ${userId}, recipient: ${recipientId}, message: ${message}, error: ${e}`]);
throw e;
}
}; };
}; };