4858-chat_realTime #1313

Merged
vicent merged 11 commits from 4858-chat_realTime into dev 2023-03-24 10:12:25 +00:00
2 changed files with 16 additions and 13 deletions
Showing only changes of commit 44055775cb - Show all commits

View File

@ -30,16 +30,23 @@ module.exports = Self => {
const recipient = to.replace('@', ''); const recipient = to.replace('@', '');
vicent marked this conversation as resolved
Review

ací no has posat transaccio per alguna rao?

ací no has posat transaccio per alguna rao?
Review

Quitada

Quitada
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;
} }

View File

@ -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);
} }
} }
} }