From 4d4dd3341fe765b4f2b33b3eba11296c8d9fd11f Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 26 May 2017 15:59:27 -0700 Subject: [PATCH] Add isBlocking/isNonBlockingApprovalRequired These analyse the identity key record and user preferences to determine whether a key requires approval for sending. // FREEBIE --- js/signal_protocol_store.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 59881be20..2d1a2b5ba 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -3,6 +3,7 @@ */ ;(function() { 'use strict'; + var TIMESTAMP_THRESHOLD = 5 * 1000; // 5 seconds var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__; var StaticArrayBufferProto = new ArrayBuffer().__proto__; @@ -343,6 +344,16 @@ }); }); }, + isBlockingApprovalRequired: function(identityKey) { + return (!identityKey.get('firstUse') + && storage.get('safety-numbers-approval', true) + && !identityKey.get('blockingApproval')); + }, + isNonBlockingApprovalRequired: function(identityKey) { + return (!identityKey.get('firstUse') + && Date.now() - identityKey.get('timestamp') < TIMESTAMP_THRESHOLD + && !identityKey.get('nonblockingApproval')); + }, removeIdentityKey: function(number) { return new Promise(function(resolve, reject) { var identityKey = new IdentityKey({id: number});