Group API

This commit is contained in:
Matt Corallo
2014-06-03 21:09:04 -04:00
parent c953c6c16d
commit b1ec02fa92
2 changed files with 155 additions and 54 deletions

View File

@@ -412,10 +412,41 @@ window.textsecure.storage = function() {
self.groups = function() {
var self = {};
//TODO
self.createNewGroup = function(numbers, groupId) {
if (groupId === undefined) {
while (textsecure.storage.getEncrypted("group" + groupId) !== undefined)
groupId = new Uint32Array(textsecure.crypto.getRandomBytes(4))[0];
}
textsecure.storage.putEncrypted("group" + groupId, {numbers: numbers});
return groupId;
}
self.getNumbers = function(groupId) {
return [];
var group = textsecure.storage.getEncrypted("group" + groupId);
if (group === undefined)
return undefined;
return group.numbers;
}
self.addNumber = function(groupId, number) {
var group = textsecure.storage.getEncrypted("group" + groupId);
if (group === undefined)
return undefined;
for (i in group.numbers)
if (group.numbers[i] == number)
return group.numbers;
group.numbers.push(number);
textsecure.storage.putEncrypted("group" + groupId, group);
return group.numbers;
}
self.deleteGroup = function(groupId) {
textsecure.storage.removeEncrypted("group" + groupId);
}
return self;