Refresh groups on (probably) new identity key (maybe more often?)

This commit is contained in:
Matt Corallo 2014-06-05 22:26:01 -04:00
parent 0f126fc0f8
commit 12a849957a
2 changed files with 54 additions and 26 deletions

View file

@ -430,6 +430,10 @@ window.textsecure.storage = function() {
textsecure.storage.putEncrypted("groupMembership" + number, membership);
}
self.getGroupListForNumber = function(number) {
return textsecure.storage.getEncrypted("groupMembership" + number, []);
}
self.createNewGroup = function(numbers, groupId) {
if (groupId === undefined) {
while (textsecure.storage.getEncrypted("group" + groupId) !== undefined)
@ -491,22 +495,6 @@ window.textsecure.storage = function() {
return group.numbers;
}
self.addNumber = function(groupId, number) {
var group = textsecure.storage.getEncrypted("group" + groupId);
if (group === undefined)
return undefined;
if (group.numbers.indexOf(number) > -1)
return group.numbers;
number = textsecure.utils.verifyNumber(number);
group.numbers.push(number);
addGroupToNumber(groupId, number);
textsecure.storage.putEncrypted("group" + groupId, group);
return group.numbers;
}
self.addNumbers = function(groupId, numbers) {
var group = textsecure.storage.getEncrypted("group" + groupId);
if (group === undefined)
@ -514,8 +502,10 @@ window.textsecure.storage = function() {
for (i in numbers) {
var number = textsecure.utils.verifyNumber(numbers[i]);
if (group.numbers.indexOf(number) < 0)
if (group.numbers.indexOf(number) < 0) {
group.numbers.push(number);
addGroupToNumber(groupId, number);
}
}
textsecure.storage.putEncrypted("group" + groupId, group);
@ -526,6 +516,14 @@ window.textsecure.storage = function() {
textsecure.storage.removeEncrypted("group" + groupId);
}
self.getGroup = function(groupId) {
var group = textsecure.storage.getEncrypted("group" + groupId);
if (group === undefined)
return undefined;
return { id: groupId, numbers: group.numbers }; //TODO: avatar/name tracking
}
return self;
}();