Skip to content

Commit

Permalink
fix: init temp writable uri (#2837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Mar 28, 2024
1 parent bee00f0 commit 9f6fd8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import com.wire.android.ui.home.conversations.MessageComposerViewState
import com.wire.android.ui.home.conversations.VisitLinkDialogState
import com.wire.android.ui.home.conversations.model.UIMessage
import com.wire.android.ui.navArgs
import com.wire.android.util.FileManager
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.configuration.FileSharingStatus
import com.wire.kalium.logic.data.asset.KaliumFileSystem
import com.wire.kalium.logic.data.conversation.Conversation.TypingIndicatorMode
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.message.SelfDeletionTimer
Expand Down Expand Up @@ -69,7 +71,9 @@ class MessageComposerViewModel @Inject constructor(
private val observeSelfDeletingMessages: ObserveSelfDeletionTimerSettingsForConversationUseCase,
private val persistNewSelfDeletingStatus: PersistNewSelfDeletionTimerUseCase,
private val sendTypingEvent: SendTypingEventUseCase,
private val saveMessageDraft: SaveMessageDraftUseCase
private val saveMessageDraft: SaveMessageDraftUseCase,
private val fileManager: FileManager,
private val kaliumFileSystem: KaliumFileSystem,
) : SavedStateViewModel(savedStateHandle) {

var messageComposerViewState = mutableStateOf(MessageComposerViewState())
Expand All @@ -93,11 +97,27 @@ class MessageComposerViewModel @Inject constructor(
)

init {
initTempWritableVideoUri()
initTempWritableImageUri()
observeIsTypingAvailable()
observeSelfDeletingMessagesStatus()
setFileSharingStatus()
}

private fun initTempWritableVideoUri() {
viewModelScope.launch {
tempWritableVideoUri =
fileManager.getTempWritableVideoUri(kaliumFileSystem.rootCachePath)
}
}

private fun initTempWritableImageUri() {
viewModelScope.launch {
tempWritableImageUri =
fileManager.getTempWritableImageUri(kaliumFileSystem.rootCachePath)
}
}

private fun observeIsTypingAvailable() = viewModelScope.launch {
observeConversationInteractionAvailability(conversationId).collect { result ->
messageComposerViewState.value = messageComposerViewState.value.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wire.android.ui.home.conversations.composer

import android.net.Uri
import androidx.lifecycle.SavedStateHandle
import com.wire.android.config.TestDispatcherProvider
import com.wire.android.config.mockUri
Expand All @@ -34,6 +35,7 @@ import com.wire.android.ui.home.conversations.model.MessageStatus
import com.wire.android.ui.home.conversations.model.MessageTime
import com.wire.android.ui.home.conversations.model.UIMessage
import com.wire.android.ui.navArgs
import com.wire.android.util.FileManager
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.configuration.FileSharingStatus
import com.wire.kalium.logic.data.conversation.Conversation
Expand Down Expand Up @@ -86,6 +88,8 @@ internal class MessageComposerViewModelArrangement {
coEvery { observeOngoingCallsUseCase() } returns flowOf(listOf())
coEvery { observeEstablishedCallsUseCase() } returns flowOf(listOf())
coEvery { observeSyncState() } returns flowOf(SyncState.Live)
coEvery { fileManager.getTempWritableVideoUri(any(), any()) } returns Uri.parse("video.mp4")
coEvery { fileManager.getTempWritableImageUri(any(), any()) } returns Uri.parse("image.jpg")
}

@MockK
Expand Down Expand Up @@ -130,6 +134,9 @@ internal class MessageComposerViewModelArrangement {
@MockK
lateinit var saveMessageDraftUseCase: SaveMessageDraftUseCase

@MockK
lateinit var fileManager: FileManager

private val fakeKaliumFileSystem = FakeKaliumFileSystem()

private val viewModel by lazy {
Expand All @@ -146,6 +153,8 @@ internal class MessageComposerViewModelArrangement {
persistNewSelfDeletingStatus = persistSelfDeletionStatus,
sendTypingEvent = sendTypingEvent,
saveMessageDraft = saveMessageDraftUseCase,
kaliumFileSystem = fakeKaliumFileSystem,
fileManager = fileManager
)
}

Expand Down

0 comments on commit 9f6fd8f

Please sign in to comment.