|  |  | @ -38180,15 +38180,35 @@ axolotlInternal.RecipientRecord = function() { | 
			
		
	
		
		
			
				
					
					|  |  |  |     window.textsecure = window.textsecure || {}; |  |  |  |     window.textsecure = window.textsecure || {}; | 
			
		
	
		
		
			
				
					
					|  |  |  |     window.textsecure.storage = window.textsecure.storage || {}; |  |  |  |     window.textsecure.storage = window.textsecure.storage || {}; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // create a random group id that we haven't seen before.
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     function generateNewGroupId() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         var groupId = getString(textsecure.crypto.getRandomBytes(16)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (group === undefined) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 return groupId; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 console.warn('group id collision'); // probably a bad sign.
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 return generateNewGroupId(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         }); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     window.textsecure.storage.groups = { |  |  |  |     window.textsecure.storage.groups = { | 
			
		
	
		
		
			
				
					
					|  |  |  |         createNewGroup: function(numbers, groupId) { |  |  |  |         createNewGroup: function(numbers, groupId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             var groupId = groupId; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 if (groupId !== undefined && textsecure.storage.get("group" + groupId) !== undefined) |  |  |  |             return new Promise(function(resolve) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     throw new Error("Tried to recreate group"); |  |  |  |                 if (groupId !== undefined) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |                     resolve(textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 while (groupId === undefined || textsecure.storage.get("group" + groupId) !== undefined) |  |  |  |                         if (group !== undefined) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     groupId = getString(textsecure.crypto.getRandomBytes(16)); |  |  |  |                             throw new Error("Tried to recreate group"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |                         } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     })); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     resolve(generateNewGroupId().then(function(newGroupId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         groupId = newGroupId; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     })); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             }).then(function() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var me = textsecure.storage.user.getNumber(); |  |  |  |                 var me = textsecure.storage.user.getNumber(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var haveMe = false; |  |  |  |                 var haveMe = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var finalNumbers = []; |  |  |  |                 var finalNumbers = []; | 
			
		
	
	
		
		
			
				
					|  |  | @ -38209,25 +38229,23 @@ axolotlInternal.RecipientRecord = function() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 for (var i in finalNumbers) |  |  |  |                 for (var i in finalNumbers) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     groupObject.numberRegistrationIds[finalNumbers[i]] = {}; |  |  |  |                     groupObject.numberRegistrationIds[finalNumbers[i]] = {}; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 textsecure.storage.put("group" + groupId, groupObject); |  |  |  |                 return textsecure.storage.axolotl.putGroup(groupId, groupObject).then(function() { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |                     return {id: groupId, numbers: finalNumbers}; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 return {id: groupId, numbers: finalNumbers}; |  |  |  |                 }); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |             }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         getNumbers: function(groupId) { |  |  |  |         getNumbers: function(groupId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var group = textsecure.storage.get("group" + groupId); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (group === undefined) |  |  |  |                 if (group === undefined) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return undefined; |  |  |  |                     return undefined; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return group.numbers; |  |  |  |                 return group.numbers; | 
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |             }); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         removeNumber: function(groupId, number) { |  |  |  |         removeNumber: function(groupId, number) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var group = textsecure.storage.get("group" + groupId); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (group === undefined) |  |  |  |                 if (group === undefined) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return undefined; |  |  |  |                     return undefined; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -38239,16 +38257,17 @@ axolotlInternal.RecipientRecord = function() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (i > -1) { |  |  |  |                 if (i > -1) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     group.numbers.slice(i, 1); |  |  |  |                     group.numbers.slice(i, 1); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     delete group.numberRegistrationIds[number]; |  |  |  |                     delete group.numberRegistrationIds[number]; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     textsecure.storage.put("group" + groupId, group); |  |  |  |                     return textsecure.storage.axolotl.putGroup(groupId, group).then(function() { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         return group.numbers; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     }); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return group.numbers; |  |  |  |                 return group.numbers; | 
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |             }); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         addNumbers: function(groupId, numbers) { |  |  |  |         addNumbers: function(groupId, numbers) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var group = textsecure.storage.get("group" + groupId); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (group === undefined) |  |  |  |                 if (group === undefined) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return undefined; |  |  |  |                     return undefined; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -38262,30 +38281,27 @@ axolotlInternal.RecipientRecord = function() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 textsecure.storage.put("group" + groupId, group); |  |  |  |                 return textsecure.storage.axolotl.putGroup(groupId, group).then(function() { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 return group.numbers; |  |  |  |                     return group.numbers; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |                 }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             }); | 
			
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         deleteGroup: function(groupId) { |  |  |  |         deleteGroup: function(groupId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.removeGroup(groupId); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 textsecure.storage.remove("group" + groupId); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         getGroup: function(groupId) { |  |  |  |         getGroup: function(groupId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var group = textsecure.storage.get("group" + groupId); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (group === undefined) |  |  |  |                 if (group === undefined) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return undefined; |  |  |  |                     return undefined; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return { id: groupId, numbers: group.numbers }; //TODO: avatar/name tracking
 |  |  |  |                 return { id: groupId, numbers: group.numbers }; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |             }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         needUpdateByDeviceRegistrationId: function(groupId, number, encodedNumber, registrationId) { |  |  |  |         needUpdateByDeviceRegistrationId: function(groupId, number, encodedNumber, registrationId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return Promise.resolve(function() { |  |  |  |             return textsecure.storage.axolotl.getGroup(groupId).then(function(group) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 var group = textsecure.storage.get("group" + groupId); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (group === undefined) |  |  |  |                 if (group === undefined) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     throw new Error("Unknown group for device registration id"); |  |  |  |                     throw new Error("Unknown group for device registration id"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -38297,9 +38313,10 @@ axolotlInternal.RecipientRecord = function() { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 var needUpdate = group.numberRegistrationIds[number][encodedNumber] !== undefined; |  |  |  |                 var needUpdate = group.numberRegistrationIds[number][encodedNumber] !== undefined; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 group.numberRegistrationIds[number][encodedNumber] = registrationId; |  |  |  |                 group.numberRegistrationIds[number][encodedNumber] = registrationId; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 textsecure.storage.put("group" + groupId, group); |  |  |  |                 return textsecure.storage.axolotl.putGroup(groupId, group).then(function() { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 return needUpdate; |  |  |  |                     return needUpdate; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             }()); |  |  |  |                 }); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             }); | 
			
		
	
		
		
			
				
					
					|  |  |  |         }, |  |  |  |         }, | 
			
		
	
		
		
			
				
					
					|  |  |  |     }; |  |  |  |     }; | 
			
		
	
		
		
			
				
					
					|  |  |  | })(); |  |  |  | })(); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |