This commit is contained in:
parent
59e91221cb
commit
2edfacb91c
|
@ -27,15 +27,19 @@ module.exports = Self => {
|
|||
Self.sendCheckingPresence = async(ctx, recipientId, message) => {
|
||||
if (!recipientId) return false;
|
||||
const models = Self.app.models;
|
||||
const sender = ctx.req.accessToken.userId;
|
||||
const recipient = recipientId;
|
||||
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const sender = await models.VnUser.findById(userId, {fields: ['id']});
|
||||
const recipient = await models.VnUser.findById(recipientId, null);
|
||||
|
||||
// Prevent sending messages to yourself
|
||||
if (recipientId == sender) return false;
|
||||
if (recipientId == userId) return false;
|
||||
if (!recipient)
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${sender}`);
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
|
||||
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
message = `[Test:Environment to user ${sender}] ` + message;
|
||||
message = `[Test:Environment to user ${userId}] ` + message;
|
||||
|
||||
const chat = await models.Chat.create({
|
||||
senderFk: sender.id,
|
||||
recipient: `@${recipient.name}`,
|
||||
|
|
Loading…
Reference in New Issue