@ -151,7 +151,7 @@ import kotlin.math.sqrt
class ConversationActivityV2 : PassphraseRequiredActionBarActivity ( ) , InputBarDelegate ,
class ConversationActivityV2 : PassphraseRequiredActionBarActivity ( ) , InputBarDelegate ,
InputBarRecordingViewDelegate , AttachmentManager . AttachmentListener , ActivityDispatcher ,
InputBarRecordingViewDelegate , AttachmentManager . AttachmentListener , ActivityDispatcher ,
ConversationActionModeCallbackDelegate , VisibleMessageContentViewDelegate , RecipientModifiedListener ,
ConversationActionModeCallbackDelegate , VisibleMessageContentViewDelegate , RecipientModifiedListener ,
SearchBottomBar . EventListener , VoiceMessageViewDelegate {
SearchBottomBar . EventListener , VoiceMessageViewDelegate , LoaderManager . LoaderCallbacks < Cursor > {
private var binding : ActivityConversationV2Binding ? = null
private var binding : ActivityConversationV2Binding ? = null
private var actionBarBinding : ActivityConversationV2ActionBarBinding ? = null
private var actionBarBinding : ActivityConversationV2ActionBarBinding ? = null
@ -350,17 +350,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
baseDialog . show ( supportFragmentManager , tag )
baseDialog . show ( supportFragmentManager , tag )
}
}
// called from onCreate
private fun setUpRecyclerView ( ) {
binding !! . conversationRecyclerView . adapter = adapter
val reverseLayout = !is IncomingMessageRequestThread ( )
val layoutManager = LinearLayoutManager ( this , LinearLayoutManager . VERTICAL , reverseLayout )
binding !! . conversationRecyclerView . layoutManager = layoutManager
// Workaround for the fact that CursorRecyclerViewAdapter doesn't auto-update automatically (even though it says it will)
LoaderManager . getInstance ( this ) . restartLoader ( 0 , null , object : LoaderManager . LoaderCallbacks < Cursor > {
override fun onCreateLoader ( id : Int , bundle : Bundle ? ) : Loader < Cursor > {
override fun onCreateLoader ( id : Int , bundle : Bundle ? ) : Loader < Cursor > {
return ConversationLoader ( viewModel . threadId , reverseLayout , this @ConversationActivityV2 )
return ConversationLoader ( viewModel . threadId , !is IncomingMessageRequestThread ( ) , this @ConversationActivityV2 )
}
}
override fun onLoadFinished ( loader : Loader < Cursor > , cursor : Cursor ? ) {
override fun onLoadFinished ( loader : Loader < Cursor > , cursor : Cursor ? ) {
@ -377,7 +368,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
override fun onLoaderReset ( cursor : Loader < Cursor > ) {
override fun onLoaderReset ( cursor : Loader < Cursor > ) {
adapter . changeCursor ( null )
adapter . changeCursor ( null )
}
}
} )
// called from onCreate
private fun setUpRecyclerView ( ) {
binding !! . conversationRecyclerView . adapter = adapter
val layoutManager = LinearLayoutManager ( this , LinearLayoutManager . VERTICAL , !is IncomingMessageRequestThread ( ) )
binding !! . conversationRecyclerView . layoutManager = layoutManager
// Workaround for the fact that CursorRecyclerViewAdapter doesn't auto-update automatically (even though it says it will)
LoaderManager . getInstance ( this ) . restartLoader ( 0 , null , this )
binding !! . conversationRecyclerView . addOnScrollListener ( object : RecyclerView . OnScrollListener ( ) {
binding !! . conversationRecyclerView . addOnScrollListener ( object : RecyclerView . OnScrollListener ( ) {
override fun onScrolled ( recyclerView : RecyclerView , dx : Int , dy : Int ) {
override fun onScrolled ( recyclerView : RecyclerView , dx : Int , dy : Int ) {
@ -388,7 +386,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// called from onCreate
// called from onCreate
private fun setUpToolBar ( ) {
private fun setUpToolBar ( ) {
val actionBar = supportActionBar !!
val actionBar = supportActionBar ?: return
actionBarBinding = ActivityConversationV2ActionBarBinding . inflate ( layoutInflater )
actionBarBinding = ActivityConversationV2ActionBarBinding . inflate ( layoutInflater )
actionBar . title = " "
actionBar . title = " "
actionBar . customView = actionBarBinding !! . root
actionBar . customView = actionBarBinding !! . root
@ -581,9 +579,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if ( viewModel . recipient . isContactRecipient ) {
if ( viewModel . recipient . isContactRecipient ) {
binding ?. blockedBanner ?. isVisible = viewModel . recipient . isBlocked
binding ?. blockedBanner ?. isVisible = viewModel . recipient . isBlocked
}
}
invalidateOptionsMenu ( )
updateSubtitle ( )
updateSubtitle ( )
showOrHideInputIfNeeded ( )
showOrHideInputIfNeeded ( )
actionBarBinding ?. profilePictureView ?. update ( recipient )
actionBarBinding ?. profilePictureView ?. update ( recipient )
actionBarBinding ?. conversationTitleView ?. text = recipient . toShortString ( )
}
}
}
}
@ -616,16 +616,16 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
binding ?. messageRequestBar ?. isVisible = false
binding ?. messageRequestBar ?. isVisible = false
binding ?. conversationRecyclerView ?. layoutManager =
binding ?. conversationRecyclerView ?. layoutManager =
LinearLayoutManager ( this , LinearLayoutManager . VERTICAL , true )
LinearLayoutManager ( this , LinearLayoutManager . VERTICAL , true )
adapter . notifyDataSetChanged ( )
viewModel . acceptMessageRequest ( )
viewModel . acceptMessageRequest ( )
LoaderManager . getInstance ( this ) . restartLoader ( 0 , null , this )
lifecycleScope . launch ( Dispatchers . IO ) {
lifecycleScope . launch ( Dispatchers . IO ) {
ConfigurationMessageUtilities . forceSyncConfigurationNowIfNeeded ( this @ConversationActivityV2 )
ConfigurationMessageUtilities . forceSyncConfigurationNowIfNeeded ( this @ConversationActivityV2 )
}
}
}
}
private fun isMessageRequestThread ( ) : Boolean {
private fun isMessageRequestThread ( ) : Boolean {
val hasSent = threadDb . getLastSeenAndHasSent ( viewModel . threadId ) . second ( )
return ! viewModel . recipient . isGroupRecipient && ! viewModel . recipient . isApproved
return ( ! viewModel . recipient . isGroupRecipient && ! hasSent ) ||
( ! viewModel . recipient . isGroupRecipient && hasSent && ! ( viewModel . recipient . hasApprovedMe ( ) || viewModel . hasReceived ( ) ) )
}
}
private fun isOutgoingMessageRequestThread ( ) : Boolean {
private fun isOutgoingMessageRequestThread ( ) : Boolean {
@ -999,9 +999,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
}
override fun sendMessage ( ) {
override fun sendMessage ( ) {
if ( isIncomingMessageRequestThread ( ) ) {
acceptMessageRequest ( )
}
if ( viewModel . recipient . isContactRecipient && viewModel . recipient . isBlocked ) {
if ( viewModel . recipient . isContactRecipient && viewModel . recipient . isBlocked ) {
BlockedDialog ( viewModel . recipient ) . show ( supportFragmentManager , " Blocked Dialog " )
BlockedDialog ( viewModel . recipient ) . show ( supportFragmentManager , " Blocked Dialog " )
return
return
@ -1019,7 +1016,17 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
startActivityForResult ( MediaSendActivity . buildEditorIntent ( this , listOf ( media ) , viewModel . recipient , getMessageBody ( ) ) , PICK _FROM _LIBRARY )
startActivityForResult ( MediaSendActivity . buildEditorIntent ( this , listOf ( media ) , viewModel . recipient , getMessageBody ( ) ) , PICK _FROM _LIBRARY )
}
}
private fun processMessageRequestApproval ( ) {
if ( isIncomingMessageRequestThread ( ) ) {
acceptMessageRequest ( )
} else if ( ! viewModel . recipient . isApproved ) {
// edge case for new outgoing thread on new recipient without sending approval messages
viewModel . setRecipientApproved ( )
}
}
private fun sendTextOnlyMessage ( hasPermissionToSendSeed : Boolean = false ) {
private fun sendTextOnlyMessage ( hasPermissionToSendSeed : Boolean = false ) {
processMessageRequestApproval ( )
val text = getMessageBody ( )
val text = getMessageBody ( )
val userPublicKey = textSecurePreferences . getLocalNumber ( )
val userPublicKey = textSecurePreferences . getLocalNumber ( )
val isNoteToSelf = ( viewModel . recipient . isContactRecipient && viewModel . recipient . address . toString ( ) == userPublicKey )
val isNoteToSelf = ( viewModel . recipient . isContactRecipient && viewModel . recipient . address . toString ( ) == userPublicKey )
@ -1049,6 +1056,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
}
private fun sendAttachments ( attachments : List < Attachment > , body : String ? , quotedMessage : MessageRecord ? = null , linkPreview : LinkPreview ? = null ) {
private fun sendAttachments ( attachments : List < Attachment > , body : String ? , quotedMessage : MessageRecord ? = null , linkPreview : LinkPreview ? = null ) {
processMessageRequestApproval ( )
// Create the message
// Create the message
val message = VisibleMessage ( )
val message = VisibleMessage ( )
message . sentTimestamp = System . currentTimeMillis ( )
message . sentTimestamp = System . currentTimeMillis ( )