mirror of
https://github.com/aljazceru/meshcore-web.git
synced 2025-12-18 00:24:21 +01:00
mark messages as failed if they timeout
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
|
||||
<!-- state label -->
|
||||
<div class="my-auto">
|
||||
<span v-if="isMessageFailed(message)">Failed</span>
|
||||
<span v-if="isMessageFailed(message)">Failed: {{ message.error }}</span>
|
||||
<span v-else-if="isMessageDelivered(message)">Delivered</span>
|
||||
<span v-else>Sending</span>
|
||||
</div>
|
||||
|
||||
@@ -175,8 +175,13 @@ class Connection {
|
||||
// send message
|
||||
const message = await GlobalState.connection.sendTextMessage(publicKey, text);
|
||||
|
||||
// mark message as failed after estimated timeout
|
||||
setTimeout(async () => {
|
||||
await Database.Message.setMessageFailedByAckCode(message.expectedAckCrc, "timeout");
|
||||
}, message.estTimeout);
|
||||
|
||||
// save to database
|
||||
return await Database.Message.insert({
|
||||
await Database.Message.insert({
|
||||
status: "sending",
|
||||
to: publicKey,
|
||||
from: GlobalState.selfInfo.publicKey,
|
||||
|
||||
@@ -112,7 +112,7 @@ class Message {
|
||||
|
||||
// find one latest message by ack code
|
||||
// this will prevent updating older messages that might have the same ack code
|
||||
const latestMessageByPacketId = database.messages.findOne({
|
||||
const message = database.messages.findOne({
|
||||
selector: {
|
||||
expected_ack_crc: {
|
||||
$eq: ackCode,
|
||||
@@ -126,12 +126,48 @@ class Message {
|
||||
});
|
||||
|
||||
// patch the message state
|
||||
return await latestMessageByPacketId.incrementalPatch({
|
||||
return await message.incrementalPatch({
|
||||
status: "delivered",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// mark a message as failed by its ack code
|
||||
static async setMessageFailedByAckCode(ackCode, reason) {
|
||||
|
||||
// find one latest message by ack code
|
||||
// this will prevent updating older messages that might have the same ack code
|
||||
const message = await database.messages.findOne({
|
||||
selector: {
|
||||
expected_ack_crc: {
|
||||
$eq: ackCode,
|
||||
},
|
||||
},
|
||||
sort: [
|
||||
{
|
||||
timestamp: "desc",
|
||||
},
|
||||
],
|
||||
}).exec();
|
||||
|
||||
// do nothing if message not found
|
||||
if(!message){
|
||||
return;
|
||||
}
|
||||
|
||||
// do nothing if already delivered
|
||||
if(message.status === "delivered"){
|
||||
return;
|
||||
}
|
||||
|
||||
// patch the message state
|
||||
await message.patch({
|
||||
status: "failed",
|
||||
error: reason,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// get all messages
|
||||
static getAllMessages() {
|
||||
return database.messages.find();
|
||||
|
||||
Reference in New Issue
Block a user