fix: not use variables and direct send in send
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
7ad9e2cb5a
commit
44055775cb
|
@ -30,16 +30,23 @@ module.exports = Self => {
|
||||||
const recipient = to.replace('@', '');
|
const recipient = to.replace('@', '');
|
||||||
|
|
||||||
if (sender.name != recipient) {
|
if (sender.name != recipient) {
|
||||||
await models.Chat.create({
|
const chat = await models.Chat.create({
|
||||||
senderFk: sender.id,
|
senderFk: sender.id,
|
||||||
recipient: to,
|
recipient: to,
|
||||||
dated: Date.vnNew(),
|
dated: Date.vnNew(),
|
||||||
checkUserStatus: 0,
|
checkUserStatus: 0,
|
||||||
message: message,
|
message: message,
|
||||||
status: 'pending',
|
status: 'sending',
|
||||||
attempts: 0
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,18 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.sendQueued = async() => {
|
Self.sendQueued = async() => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const maxAttempts = 3;
|
|
||||||
const sentStatus = 'sent';
|
|
||||||
const sendingStatus = 'sending';
|
|
||||||
const errorStatus = 'error';
|
|
||||||
|
|
||||||
const chats = await models.Chat.find({
|
const chats = await models.Chat.find({
|
||||||
where: {
|
where: {
|
||||||
status: {
|
status: {
|
||||||
neq: {
|
neq: {
|
||||||
and: [
|
and: [
|
||||||
sentStatus,
|
'sent',
|
||||||
sendingStatus
|
'sending'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attempts: {lt: maxAttempts}
|
attempts: {lt: 3}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -38,16 +34,16 @@ module.exports = Self => {
|
||||||
if (chat.checkUserStatus) {
|
if (chat.checkUserStatus) {
|
||||||
try {
|
try {
|
||||||
await Self.sendCheckingUserStatus(chat);
|
await Self.sendCheckingUserStatus(chat);
|
||||||
await updateChat(chat, sentStatus);
|
await updateChat(chat, 'sent');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await updateChat(chat, errorStatus, error);
|
await updateChat(chat, 'error', error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await Self.sendMessage(chat.senderFk, chat.recipient, chat.message);
|
await Self.sendMessage(chat.senderFk, chat.recipient, chat.message);
|
||||||
await updateChat(chat, sentStatus);
|
await updateChat(chat, 'sent');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await updateChat(chat, errorStatus, error);
|
await updateChat(chat, 'error', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue