2121package com.owncloud.android.presentation.sharing
2222
2323import androidx.lifecycle.ViewModel
24+ import com.owncloud.android.domain.exceptions.IncompleteFileDataException
2425import com.owncloud.android.domain.files.model.OCFile
2526import com.owncloud.android.domain.roles.model.OCRole
2627import com.owncloud.android.domain.roles.usecases.GetRolesAsyncUseCase
@@ -32,6 +33,7 @@ import com.owncloud.android.presentation.common.UIResult
3233import com.owncloud.android.providers.CoroutinesDispatcherProvider
3334import kotlinx.coroutines.flow.MutableStateFlow
3435import kotlinx.coroutines.flow.StateFlow
36+ import kotlinx.coroutines.flow.update
3537
3638class GraphShareViewModel (
3739 private val getRolesAsyncUseCase : GetRolesAsyncUseCase ,
@@ -56,15 +58,24 @@ class GraphShareViewModel(
5658 )
5759 }
5860
59- fun getGraphShares () = runUseCaseWithResult(
60- coroutineDispatcher = coroutineDispatcherProvider.io,
61- showLoading = true ,
62- flow = _shares ,
63- useCase = getGraphSharesAsyncUseCase,
64- useCaseParams = GetGraphSharesAsyncUseCase .Params (
65- accountName = accountName,
66- spaceId = file.spaceId.orEmpty(),
67- itemId = file.remoteId.orEmpty()
61+ fun getGraphShares () {
62+ val spaceId = file.spaceId
63+ val itemId = file.remoteId
64+ if (spaceId == null || itemId == null ) {
65+ _shares .update { Event (UIResult .Error (error = IncompleteFileDataException ())) }
66+ return
67+ }
68+
69+ runUseCaseWithResult(
70+ coroutineDispatcher = coroutineDispatcherProvider.io,
71+ showLoading = true ,
72+ flow = _shares ,
73+ useCase = getGraphSharesAsyncUseCase,
74+ useCaseParams = GetGraphSharesAsyncUseCase .Params (
75+ accountName = accountName,
76+ spaceId = spaceId,
77+ itemId = itemId
78+ )
6879 )
69- )
80+ }
7081}
0 commit comments