fix: idempotent conv-key upsert + guard tauri-only notification calls
This commit is contained in:
@@ -161,7 +161,10 @@ export async function bootstrapConvKey(
|
||||
});
|
||||
}
|
||||
|
||||
const { error } = await rawFrom(client, 'conversation_keys').insert(rows);
|
||||
const { error } = await rawFrom(client, 'conversation_keys').upsert(rows, {
|
||||
onConflict: 'conversation_id,recipient_device_id,key_version',
|
||||
ignoreDuplicates: true,
|
||||
});
|
||||
if (error) throw error;
|
||||
|
||||
const handle = { conversationId, keyVersion, key: convKey };
|
||||
@@ -262,15 +265,21 @@ export async function shareConvKeyToDevice(
|
||||
recipientPublicKey,
|
||||
own.privateKey,
|
||||
);
|
||||
const { error } = await rawFrom(client, 'conversation_keys').insert({
|
||||
conversation_id: conversationId,
|
||||
recipient_device_id: recipientDeviceId,
|
||||
key_version: version,
|
||||
sender_device_id: own.deviceId,
|
||||
encrypted_key: bytesToPgHex(wrapped.ciphertext),
|
||||
nonce: bytesToPgHex(wrapped.nonce),
|
||||
});
|
||||
if (error && !String(error.message ?? '').includes('duplicate')) throw error;
|
||||
const { error } = await rawFrom(client, 'conversation_keys').upsert(
|
||||
{
|
||||
conversation_id: conversationId,
|
||||
recipient_device_id: recipientDeviceId,
|
||||
key_version: version,
|
||||
sender_device_id: own.deviceId,
|
||||
encrypted_key: bytesToPgHex(wrapped.ciphertext),
|
||||
nonce: bytesToPgHex(wrapped.nonce),
|
||||
},
|
||||
{
|
||||
onConflict: 'conversation_id,recipient_device_id,key_version',
|
||||
ignoreDuplicates: true,
|
||||
},
|
||||
);
|
||||
if (error) throw error;
|
||||
}
|
||||
|
||||
// Re-exports for convenience.
|
||||
|
||||
Reference in New Issue
Block a user