Skip to content

Commit

Permalink
[lib] mark messages as sent when there is no messageID in Outbound …
Browse files Browse the repository at this point in the history
…messages table

Summary: Handle edge-case when the message was sent, but it wasn't updated in the message store (e.g. app was killed), but was already confirmed by the other peer - and when hitting retry there is no message with given ID in the outbound messages table.

Test Plan: Test case described in summary.

Reviewers: tomek

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13255
  • Loading branch information
xsanm committed Sep 10, 2024
1 parent 9e3f4e9 commit a4a7448
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/tunnelbroker/peer-to-peer-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,22 @@ async function processOutboundP2PMessages(

const { olmAPI, sqliteAPI } = getConfig();
await olmAPI.initializeCryptoAccount();

const sentMessagesMap: { [messageID: string]: boolean } = {};

let messages;
if (messageIDs) {
messages = await sqliteAPI.getOutboundP2PMessagesByID(messageIDs);
if (messageIDs.length !== messages.length) {
const dbMessageIDsSet = new Set<string>(
messages.map(message => message.messageID),
);
for (const messageID of messageIDs) {
if (!dbMessageIDsSet.has(messageID)) {
sentMessagesMap[messageID] = true;
}
}
}
} else {
const allMessages = await sqliteAPI.getAllOutboundP2PMessages();
messages = allMessages.filter(message => message.supportsAutoRetry);
Expand All @@ -95,8 +108,6 @@ async function processOutboundP2PMessages(
}
}

const sentMessagesMap: { [messageID: string]: boolean } = {};

const sendMessageToPeer = async (
message: OutboundP2PMessage,
): Promise<void> => {
Expand Down

0 comments on commit a4a7448

Please sign in to comment.