@ -46,8 +46,9 @@ object MultiDeviceProtocol {
private fun sendMessagePushToDevice ( context : Context , recipient : Recipient , messageID : Long , messageType : MessageType ) : PushSendJob {
val threadID = DatabaseFactory . getThreadDatabase ( context ) . getThreadIdFor ( recipient )
val threadFRStatus = DatabaseFactory . getLokiThreadDatabase ( context ) . getFriendRequestStatus ( threadID )
val isContactFriend = ( threadFRStatus == LokiThreadFriendRequestStatus . FRIENDS )
val isFRMessage = ( threadFRStatus != LokiThreadFriendRequestStatus . FRIENDS ) // Holds true assuming this method isn't invoked for control messages
val isNoteToSelf = SessionMetaProtocol . shared . isNoteToSelf ( recipient . address . serialize ( ) )
val isContactFriend = ( threadFRStatus == LokiThreadFriendRequestStatus . FRIENDS || isNoteToSelf ) // In the note to self case the device linking request was the FR
val isFRMessage = !is ContactFriend // Holds true assuming this method isn't invoked for control messages
val hasVisibleContent = when ( messageType ) {
MessageType . Text -> DatabaseFactory . getSmsDatabase ( context ) . getMessage ( messageID ) . body . isNotBlank ( )
MessageType . Media -> {
@ -55,9 +56,9 @@ object MultiDeviceProtocol {
outgoingMediaMessage . body . isNotBlank ( ) || outgoingMediaMessage . attachments . isNotEmpty ( )
}
}
if ( isFRMessage && ! hasVisibleContent && BuildConfig . DEBUG ) { throw IllegalStateException ( ) }
if ( isFRMessage && ! hasVisibleContent && BuildConfig . DEBUG ) { throw IllegalStateException ( ) } // Verify the above assumption
val shouldSendAutoGeneratedFR = !is ContactFriend && !is FRMessage
&& ! SessionMetaProtocol . shared . isNoteToSelf ( recipient . address . serialize ( ) ) && ! recipient . address . isGroup // Group threads work through session requests
&& !is NoteToSelf && ! recipient . address . isGroup // Group threads work through session requests
&& hasVisibleContent
if ( ! shouldSendAutoGeneratedFR ) {
when ( messageType ) {
@ -178,6 +179,8 @@ object MultiDeviceProtocol {
}
val isValid = isValidDeviceLinkMessage ( context , deviceLink )
if ( !is Valid ) { return }
// The line below isn't actually necessary because this is called after PushDecryptJob
// calls handlePreKeyBundleMessageIfNeeded, but it also doesn't hurt.
SessionManagementProtocol . handlePreKeyBundleMessageIfNeeded ( context , content )
linkingSession . processLinkingRequest ( deviceLink )
}