@ -991,33 +991,24 @@ MessageReceiver.prototype.extend({
content . dataMessage . body ,
content . dataMessage . body ,
content . preKeyBundleMessage ,
content . preKeyBundleMessage ,
) ;
) ;
}
} else {
const keyExchangeComplete = conversation . isKeyExchangeCompleted ( ) ;
// Exit early since the friend request reply will be a regular empty message
return ;
// Check here if we received preKeys from the other user
}
// We are certain that other user accepted the friend request IF:
// - The message has a preKeyBundleMessage
// Check if our friend request got accepted
// - We have an outgoing friend request that is pending
if ( content . preKeyBundleMessage ) {
// The second check is crucial because it makes sure we don't save the preKeys of the incoming friend request (which is saved only when we press accept)
// By default we don't want to save the preKey
if ( ! keyExchangeComplete && content . preKeyBundleMessage ) {
let savePreKey = false ;
// Check for any outgoing friend requests
// The conversation
let conversation = null ;
try {
conversation = ConversationController . get ( envelope . source ) ;
// We only want to save the preKey if we have a outgoing friend request which is pending
const pending = await conversation . getPendingFriendRequests ( 'outgoing' ) ;
const pending = await conversation . getPendingFriendRequests ( 'outgoing' ) ;
const successful = pending . filter ( p => ! p . hasErrors ( ) ) ;
const successful = pending . filter ( p => ! p . hasErrors ( ) ) ;
// Save the key only if we have an outgoing friend request
// Save the key only if we have an outgoing friend request
savePreKey = ( successful . length > 0 ) ;
const savePreKey = ( successful . length > 0 ) ;
} catch ( e ) { }
// Save the pre key if we have a conversation
// Save the pre key
if ( savePreKey && conversation ) {
if ( savePreKey ) {
await this . handlePreKeyBundleMessage (
await this . handlePreKeyBundleMessage (
envelope . source ,
envelope . source ,
this . decodePreKeyBundleMessage ( content . preKeyBundleMessage ) ,
this . decodePreKeyBundleMessage ( content . preKeyBundleMessage ) ,
@ -1025,10 +1016,13 @@ MessageReceiver.prototype.extend({
// Update the conversation
// Update the conversation
await conversation . onFriendRequestAccepted ( ) ;
await conversation . onFriendRequestAccepted ( ) ;
}
}
}
// Exit early since the friend request reply will be a regular empty message
return ;
return ;
}
}
}
if ( content . syncMessage ) {
if ( content . syncMessage ) {
return this . handleSyncMessage ( envelope , content . syncMessage ) ;
return this . handleSyncMessage ( envelope , content . syncMessage ) ;