@ -38140,16 +38140,25 @@ axolotlInternal.RecipientRecord = function() {
delete tempKeys [ encodedNumber ] ;
return Promise . resolve ( ) ;
} ,
needKeysForDevice : function ( encodedNumber ) {
if ( tempKeys [ encodedNumber ] !== undefined ) {
return Promise . resolve ( false ) ;
} else {
return textsecure . protocol _wrapper . hasOpenSession ( encodedNumber ) . then ( function ( result ) {
return ! result ;
getStaleDeviceIdsForNumber : function ( number ) {
return textsecure . storage . axolotl . getDeviceIds ( number ) . then ( function ( deviceIds ) {
if ( deviceIds . length === 0 ) {
return [ 1 ] ;
}
var updateDevices = [ ] ;
return Promise . all ( deviceIds . map ( function ( deviceId ) {
var encodedNumber = number + '.' + deviceId ;
return textsecure . protocol _wrapper . hasOpenSession ( encodedNumber ) . then ( function ( hasSession ) {
if ( ! hasSession && ! tempKeys [ encodedNumber ] ) {
updateDevices . push ( deviceId ) ;
}
} ) ;
} ) ) . then ( function ( ) {
return updateDevices ;
} ) ;
}
} ) ;
} ,
getDeviceObjectsForNumber : function ( number ) {
return textsecure . storage . axolotl . getIdentityKey ( number ) . then ( function ( identityKey ) {
if ( identityKey === undefined ) {
@ -39767,11 +39776,11 @@ OutgoingMessage.prototype = {
return this . server . getKeysForNumber ( number ) . then ( handleResult ) ;
} else {
var promise = Promise . resolve ( ) ;
for ( var i in updateDevices ) {
updateDevices . forEach ( function ( device ) {
promise = promise . then ( function ( ) {
return this . server . getKeysForNumber ( number , up dateD evices[ i ] ) . then ( handleResult ) ;
return this . server . getKeysForNumber ( number , device) . then ( handleResult ) ;
} . bind ( this ) ) ;
}
} . bind ( this ) ) ;
return promise ;
}
@ -39812,33 +39821,12 @@ OutgoingMessage.prototype = {
} ,
sendToNumber : function ( number ) {
return textsecure . storage . devices . getDeviceObjectsForNumber ( number ) . then ( function ( devicesForNumber ) {
return Promise . all ( devicesForNumber . map ( function ( device ) {
return textsecure . storage . devices . needKeysForDevice ( device . encodedNumber ) . then ( function ( result ) {
if ( result ) {
return this . getKeysForNumber ( number ,
[ parseInt ( textsecure . utils . unencodeNumber ( device . encodedNumber ) [ 1 ] ) ]
) . catch ( function ( error ) {
if ( error . name !== 'OutgoingIdentityKeyError' ) {
this . registerError ( number , "Failed to retreive new device keys for " + device . encodedNumber , error ) ;
}
return Promise . reject ( ) ;
} . bind ( this ) ) ;
}
return textsecure . storage . devices . getStaleDeviceIdsForNumber ( number ) . then ( function ( updateDevices ) {
return this . getKeysForNumber ( number , updateDevices )
. then ( this . reloadDevicesAndSend ( number , true ) )
. catch ( function ( error ) {
this . registerError ( number , "Failed to retreive new device keys for number " + number , error ) ;
} . bind ( this ) ) ;
} . bind ( this ) ) ) . then ( function ( ) {
return textsecure . storage . devices . getDeviceObjectsForNumber ( number ) . then ( function ( devicesForNumber ) {
if ( devicesForNumber . length == 0 ) {
return this . getKeysForNumber ( number , [ 1 ] )
. then ( this . reloadDevicesAndSend ( number , true ) )
. catch ( function ( error ) {
this . registerError ( number , "Failed to retreive new device keys for number " + number , error ) ;
} . bind ( this ) ) ;
} else {
return this . doSendMessage ( number , devicesForNumber , true ) ;
}
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,