Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.wire.android.di.accountScoped

import com.wire.android.di.CurrentAccount
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.feature.cells.util.FileNameResolver
import com.wire.android.ui.home.conversations.model.messagetypes.multipart.CellAssetRefreshHelper
import com.wire.kalium.cells.CellsScope
import com.wire.kalium.cells.domain.CellUploadManager
Expand Down Expand Up @@ -182,9 +181,6 @@ class CellsModule {
@Provides
fun provideGetOwnersUseCase(cellsScope: CellsScope): GetOwnersUseCase = cellsScope.getOwnersUseCase

@Provides
fun provideFileNameResolver(): FileNameResolver = FileNameResolver()

@Provides
fun provideGetCellNodeUseCase(cellsScope: CellsScope): GetCellFileUseCase = cellsScope.getCellFileUseCase

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class CellViewModel @AssistedInject constructor(
private fun startOpenDownload(cellNode: CellNodeUi.File) {
openFileDownloadController.start(
scope = viewModelScope,
cellNode = cellNode,
cellNode = cellNode.copy(conversationId = cellNode.conversationId ?: navArgs.conversationId),
onOpenFile = ::openLocalFile,
onError = { sendAction(ShowError(it)) },
)
Expand Down Expand Up @@ -441,14 +441,17 @@ class CellViewModel @AssistedInject constructor(
return
}
}

AttachmentFileType.VIDEO -> {
sendAction(OpenVideoViewer(file))
return
}

AttachmentFileType.AUDIO -> {
sendAction(OpenAudioPlayer(file))
return
}

else -> Unit
}
file.contentUrl?.let { url ->
Expand All @@ -471,14 +474,17 @@ class CellViewModel @AssistedInject constructor(
return
}
}

AttachmentFileType.VIDEO -> {
sendAction(OpenVideoViewer(file))
return
}

AttachmentFileType.AUDIO -> {
sendAction(OpenAudioPlayer(file))
return
}

else -> Unit
}
file.localPath?.let { path ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.wire.android.feature.cells.ui

import com.wire.android.feature.cells.ui.model.CellNodeUi
import com.wire.android.feature.cells.util.FileHelper
import com.wire.android.feature.cells.util.FileNameResolver
import com.wire.kalium.cells.domain.usecase.download.DownloadCellFileUseCase
import com.wire.kalium.cells.domain.usecase.offline.OfflineFileInfo
import com.wire.kalium.cells.domain.usecase.offline.SaveOfflineFileUseCase
Expand All @@ -43,7 +42,6 @@ import dev.zacsweers.metro.Inject
class OfflineFileDownloadController @Inject constructor(
private val download: DownloadCellFileUseCase,
private val fileHelper: FileHelper,
private val fileNameResolver: FileNameResolver,
private val saveOfflineFile: SaveOfflineFileUseCase,
private val sharedPathCache: CellFileLocalPathCache,
) {
Expand All @@ -62,7 +60,7 @@ class OfflineFileDownloadController @Inject constructor(
// If the file already exists locally (loaded this session or stored in DB),
// skip the download and just persist the offline metadata.
val existingPath = cellNode.localPath ?: sharedPathCache.getCompletedPath(cellNode.uuid)
if (existingPath != null) {
if (existingPath != null && File(existingPath).exists()) {
saveExistingOfflineFile(scope, cellNode, existingPath, onSuccess, onError)
return
}
Expand All @@ -74,9 +72,9 @@ class OfflineFileDownloadController @Inject constructor(
onError(CellError.OTHER_ERROR)
return
}
val filePath = fileNameResolver
.getUniqueFile(fileHelper.getExternalFilesDir(), nodeName)
.toPath()
val filePath = File(fileHelper.getExternalFilesDir(), cellNode.conversationId ?: cellNode.uuid)
.also { it.mkdirs() }
.let { File(it, nodeName) }
.toOkioPath()

val job = scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.wire.android.feature.cells.ui.OpenFileDownloadController.Companion.SP
import com.wire.android.feature.cells.ui.model.CellNodeUi
import com.wire.android.feature.cells.ui.model.OpenLoadState
import com.wire.android.feature.cells.util.FileHelper
import com.wire.android.feature.cells.util.FileNameResolver
import com.wire.kalium.cells.domain.usecase.download.DownloadCellFileUseCase
import com.wire.kalium.common.functional.Either
import com.wire.kalium.common.functional.onSuccess
Expand Down Expand Up @@ -49,7 +48,6 @@ import java.io.File
class OpenFileDownloadController @Inject constructor(
private val download: DownloadCellFileUseCase,
private val fileHelper: FileHelper,
private val fileNameResolver: FileNameResolver,
private val sharedPathCache: CellFileLocalPathCache,
) {
private data class ActiveDownload(val job: Job, val filePath: Path)
Expand All @@ -68,7 +66,7 @@ class OpenFileDownloadController @Inject constructor(
// (node.localPath) or recorded in this session's completed-paths guard (covers the
// window between download completion and paging source refresh).
val knownPath = cellNode.localPath ?: sharedPathCache.getCompletedPath(cellNode.uuid)
if (knownPath != null) {
if (knownPath != null && File(knownPath).exists()) {
onOpenFile(cellNode.copy(localPath = knownPath))
return
}
Expand All @@ -81,9 +79,9 @@ class OpenFileDownloadController @Inject constructor(
return
}

val filePath = fileNameResolver
.getUniqueFile(fileHelper.getExternalFilesDir(), nodeName)
.toPath()
val filePath = File(fileHelper.getExternalFilesDir(), cellNode.conversationId ?: cellNode.uuid)
.also { it.mkdirs() }
.let { File(it, nodeName) }
.toOkioPath()

val job = scope.launch {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.wire.android.feature.cells.ui.search.SearchNavArgs
import com.wire.android.feature.cells.ui.search.sort.SortCriteriaNavArg
import com.wire.android.feature.cells.ui.search.sort.SortingCriteria
import com.wire.android.feature.cells.util.FileHelper
import com.wire.android.feature.cells.util.FileNameResolver
import com.wire.kalium.cells.domain.model.Node
import com.wire.kalium.cells.domain.usecase.DeleteCellAssetUseCase
import com.wire.kalium.cells.domain.usecase.GetConversationNameUseCase
Expand Down Expand Up @@ -459,9 +458,6 @@ class CellViewModelTest {
@MockK
lateinit var fileHelper: FileHelper

@MockK
lateinit var fileNameResolver: FileNameResolver

val sharedPathCache = CellFileLocalPathCache()

@MockK
Expand Down Expand Up @@ -586,21 +582,18 @@ class CellViewModelTest {
fun arrange(): Pair<Arrangement, CellViewModel> {

every { fileHelper.getExternalFilesDir() } returns File("")
every { fileNameResolver.getUniqueFile(any(), any()) } returns File("")

coEvery { getWireCellsConfig() } returns null

val openFileDownloadController = OpenFileDownloadController(
download = downloadCellFileUseCase,
fileHelper = fileHelper,
fileNameResolver = fileNameResolver,
sharedPathCache = sharedPathCache,
)

val offlineFileDownloadController = OfflineFileDownloadController(
download = downloadCellFileUseCase,
fileHelper = fileHelper,
fileNameResolver = fileNameResolver,
saveOfflineFile = mockk(relaxUnitFun = true),
sharedPathCache = sharedPathCache,
)
Expand Down
Loading
Loading