This commit is contained in:
parent
f06fc92ae8
commit
d1f0ae3865
|
@ -38,6 +38,9 @@ module.exports = Self => {
|
|||
if (!recipient)
|
||||
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 ${userId}] ` + message;
|
||||
|
||||
const chat = await models.Chat.create({
|
||||
senderFk: sender.id,
|
||||
recipient: `@${recipient.name}`,
|
||||
|
|
|
@ -19,12 +19,11 @@ module.exports = Self => {
|
|||
const chats = await models.Chat.find({
|
||||
where: {
|
||||
status: {
|
||||
neq: {
|
||||
and: [
|
||||
nin: [
|
||||
'sent',
|
||||
'sending'
|
||||
]
|
||||
}
|
||||
|
||||
},
|
||||
attempts: {lt: 3}
|
||||
}
|
||||
|
@ -34,16 +33,16 @@ module.exports = Self => {
|
|||
if (chat.checkUserStatus) {
|
||||
try {
|
||||
await Self.sendCheckingUserStatus(chat);
|
||||
await updateChat(chat, 'sent');
|
||||
await Self.updateChat(chat, 'sent');
|
||||
} catch (error) {
|
||||
await updateChat(chat, 'error', error);
|
||||
await Self.updateChat(chat, 'error', error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await Self.sendMessage(chat.senderFk, chat.recipient, chat.message);
|
||||
await updateChat(chat, 'sent');
|
||||
await Self.updateChat(chat, 'sent');
|
||||
} catch (error) {
|
||||
await updateChat(chat, 'error', error);
|
||||
await Self.updateChat(chat, 'error', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue