Fix bug in groupId generation

Previously, if calling createNewGroup with an undefined groupId,
no groupId was generated.

This occurred because no entry for "group" + undefined exists in
localStorage, which caused this code to think undefined was a
valid group id.

Fixed by adding `|| groupId == undefined` to the while clause.
Also decoupled the groupId collision check for clarity.
This commit is contained in:
lilia 2014-10-14 15:27:47 -07:00
parent dc41ebf701
commit e89e691957

View file

@ -418,11 +418,13 @@ window.textsecure.storage = function() {
}
self.createNewGroup = function(numbers, groupId) {
if (groupId === undefined) {
while (textsecure.storage.getEncrypted("group" + groupId) !== undefined)
groupId = new Uint32Array(textsecure.crypto.getRandomBytes(4))[0];
} else if (textsecure.storage.getEncrypted("group" + groupId) !== undefined)
if (groupId !== undefined && textsecure.storage.getEncrypted("group" + groupId) !== undefined) {
throw new Error("Tried to recreate group");
}
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined) {
groupId = new Uint32Array(textsecure.crypto.getRandomBytes(4))[0];
}
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
var haveMe = false;