Throttle the refreshing of device mappings to once every minute

pull/613/head
Beaudan Brown 5 years ago
parent 030264c689
commit 24a687c106

@ -367,8 +367,6 @@
await window.Signal.Data.saveMessage(this.attributes, { await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message, Message: Whisper.Message,
}); });
const pubKey = this.get('conversationId');
await libloki.storage.saveAllPairingAuthorisationsFor(pubKey);
conversation.onAcceptFriendRequest(); conversation.onAcceptFriendRequest();
}, },
async declineFriendRequest() { async declineFriendRequest() {

@ -5,6 +5,9 @@
(function() { (function() {
window.libloki = window.libloki || {}; window.libloki = window.libloki || {};
const timers = {};
const REFRESH_DELAY = 60 * 1000;
async function getPreKeyBundleForContact(pubKey) { async function getPreKeyBundleForContact(pubKey) {
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
const identityKey = myKeyPair.pubKey; const identityKey = myKeyPair.pubKey;
@ -149,6 +152,12 @@
// if the device is a secondary device, // if the device is a secondary device,
// fetch the device mappings for its primary device // fetch the device mappings for its primary device
async function saveAllPairingAuthorisationsFor(pubKey) { async function saveAllPairingAuthorisationsFor(pubKey) {
// Will be false if there is no timer
const cacheValid = timers[pubKey] > Date.now();
if (cacheValid) {
return;
}
timers[pubKey] = Date.now() + REFRESH_DELAY;
const authorisations = await getPrimaryDeviceMapping(pubKey); const authorisations = await getPrimaryDeviceMapping(pubKey);
await Promise.all( await Promise.all(
authorisations.map(authorisation => authorisations.map(authorisation =>
@ -199,6 +208,7 @@
// Transforms signatures from base64 to ArrayBuffer! // Transforms signatures from base64 to ArrayBuffer!
async function getAuthorisationForSecondaryPubKey(secondaryPubKey) { async function getAuthorisationForSecondaryPubKey(secondaryPubKey) {
await saveAllPairingAuthorisationsFor(secondaryPubKey);
const authorisation = await window.Signal.Data.getAuthorisationForSecondaryPubKey( const authorisation = await window.Signal.Data.getAuthorisationForSecondaryPubKey(
secondaryPubKey secondaryPubKey
); );

Loading…
Cancel
Save