Update setVerified to take an optional key argument

If specified, the existing local key must match the given one or we will not
update the record.

// FREEBIE
This commit is contained in:
lilia 2017-06-16 18:35:25 -07:00 committed by Scott Nonnenberg
parent 33b4d398d6
commit c60919ca0e

View file

@ -503,23 +503,36 @@
});
});
},
setVerified: function(identifier, verifiedStatus) {
setVerified: function(identifier, verifiedStatus, publicKey) {
if (identifier === null || identifier === undefined) {
throw new Error("Tried to set verified for undefined/null key");
}
if (!validateVerifiedStatus(verifiedStatus)) {
throw new Error("Invalid verified status");
}
if (arguments.length > 2 && !(publicKey instanceof ArrayBuffer)) {
throw new Error("Invalid public key");
}
return new Promise(function(resolve, reject) {
var identityRecord = new IdentityRecord({id: identifier});
identityRecord.fetch().always(function() {
identityRecord.save({
verified: verifiedStatus
}).then(function() {
identityRecord.fetch().then(function() {
if (!publicKey || equalArrayBuffers(identityRecord.get('publicKey'), publicKey)) {
identityRecord.set({ verified: verifiedStatus });
if (identityRecord.isValid()) {
identityRecord.save({
}).then(function() {
resolve();
});
} else {
reject(identityRecord.validationError);
}
} else {
console.log("No identity record for specified publicKey");
resolve();
}, function() { // catch
reject(new Error("No identity record for " + identifier));
});
}
}, function() { // catch
reject(new Error("No identity record for " + identifier));
});
});
},