Skip to content

Commit

Permalink
Merge pull request #4439 from nextcloud/bugfix/noid/fixNpeInRestoreMe…
Browse files Browse the repository at this point in the history
…ssageQueue

fix NPE in restoreMessageQueue
  • Loading branch information
sowjanyakch authored Nov 14, 2024
2 parents 20ee92e + f144b64 commit 9257d41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 13 additions & 4 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,11 @@ class ChatActivity :
setContentView(binding.root)
setupSystemColors()

messageInputFragment = MessageInputFragment()

conversationUser = currentUserProvider.currentUser.blockingGet()

handleIntent(intent)

messageInputFragment = getMessageInputFragment()

chatViewModel = ViewModelProvider(this, viewModelFactory)[ChatViewModel::class.java]

messageInputViewModel = ViewModelProvider(this, viewModelFactory)[MessageInputViewModel::class.java]
Expand Down Expand Up @@ -457,6 +456,15 @@ class ChatActivity :
}
}

private fun getMessageInputFragment(): MessageInputFragment {
val internalId = conversationUser!!.id.toString() + "@" + roomToken
return MessageInputFragment().apply {
arguments = Bundle().apply {
putString(CONVERSATION_INTERNAL_ID, internalId)
}
}
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val extras: Bundle? = intent.extras
Expand Down Expand Up @@ -990,7 +998,7 @@ class ChatActivity :
} else {
supportFragmentManager.commit {
setReorderingAllowed(true)
replace(R.id.fragment_container_activity_chat, MessageInputFragment())
replace(R.id.fragment_container_activity_chat, getMessageInputFragment())
}
}
}
Expand Down Expand Up @@ -3786,5 +3794,6 @@ class ChatActivity :
private const val RESUME_AUDIO_TAG = "RESUME_AUDIO_TAG"
private const val DELAY_TO_SHOW_PROGRESS_BAR = 1000L
private const val FIVE_MINUTES_IN_SECONDS: Long = 300
const val CONVERSATION_INTERNAL_ID = "CONVERSATION_INTERNAL_ID"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class MessageInputFragment : Fragment() {
lateinit var networkMonitor: NetworkMonitor

lateinit var binding: FragmentMessageInputBinding
private lateinit var conversationInternalId: String
private var typedWhileTypingTimerIsRunning: Boolean = false
private var typingTimer: CountDownTimer? = null
private lateinit var chatActivity: ChatActivity
Expand All @@ -122,6 +123,10 @@ class MessageInputFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedApplication!!.componentApplication.inject(this)
conversationInternalId = arguments?.getString(ChatActivity.CONVERSATION_INTERNAL_ID).orEmpty()
if (conversationInternalId.isEmpty()) {
Log.e(TAG, "internalId for conversation passed to MessageInputFragment is empty")
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand All @@ -143,7 +148,7 @@ class MessageInputFragment : Fragment() {

override fun onResume() {
super.onResume()
chatActivity.messageInputViewModel.restoreMessageQueue(chatActivity.currentConversation!!.internalId)
chatActivity.messageInputViewModel.restoreMessageQueue(conversationInternalId)
}

override fun onDestroyView() {
Expand Down Expand Up @@ -728,9 +733,8 @@ class MessageInputFragment : Fragment() {
}
}

private fun isTypingStatusEnabled(): Boolean {
return !CapabilitiesUtil.isTypingStatusPrivate(chatActivity.conversationUser!!)
}
private fun isTypingStatusEnabled(): Boolean =
!CapabilitiesUtil.isTypingStatusPrivate(chatActivity.conversationUser!!)

private fun uploadFile(fileUri: String, isVoiceMessage: Boolean, caption: String = "", token: String = "") {
var metaData = ""
Expand Down

0 comments on commit 9257d41

Please sign in to comment.