fix: not use variables and direct send in send
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-02-06 10:11:41 +01:00
parent 7ad9e2cb5a
commit 44055775cb
2 changed files with 16 additions and 13 deletions

View File

@ -30,16 +30,23 @@ module.exports = Self => {
const recipient = to.replace('@', '');
if (sender.name != recipient) {
await models.Chat.create({
const chat = await models.Chat.create({
senderFk: sender.id,
recipient: to,
dated: Date.vnNew(),
checkUserStatus: 0,
message: message,
status: 'pending',
status: 'sending',
attempts: 0
});
try {
await Self.sendMessage(chat.senderFk, chat.recipient, chat.message);
await updateChat(chat, 'sent');
} catch (error) {
await updateChat(chat, 'error', error);
}
return true;
}

View File

@ -15,22 +15,18 @@ module.exports = Self => {
Self.sendQueued = async() => {
const models = Self.app.models;
const maxAttempts = 3;
const sentStatus = 'sent';
const sendingStatus = 'sending';
const errorStatus = 'error';
const chats = await models.Chat.find({
where: {
status: {
neq: {
and: [
sentStatus,
sendingStatus
'sent',
'sending'
]
}
},
attempts: {lt: maxAttempts}
attempts: {lt: 3}
}
});
@ -38,16 +34,16 @@ module.exports = Self => {
if (chat.checkUserStatus) {
try {
await Self.sendCheckingUserStatus(chat);
await updateChat(chat, sentStatus);
await updateChat(chat, 'sent');
} catch (error) {
await updateChat(chat, errorStatus, error);
await updateChat(chat, 'error', error);
}
} else {
try {
await Self.sendMessage(chat.senderFk, chat.recipient, chat.message);
await updateChat(chat, sentStatus);
await updateChat(chat, 'sent');
} catch (error) {
await updateChat(chat, errorStatus, error);
await updateChat(chat, 'error', error);
}
}
}