Add isBlocking/isNonBlockingApprovalRequired

These analyse the identity key record and user preferences to determine whether
a key requires approval for sending.

// FREEBIE
This commit is contained in:
lilia 2017-05-26 15:59:27 -07:00 committed by Scott Nonnenberg
parent 22e907a8d4
commit 4d4dd3341f

View file

@ -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});