Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Deep links over shared files (oCIS) #4302

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -5,7 +5,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -87,6 +87,7 @@ import com.owncloud.android.domain.sharing.shares.usecases.GetShareAsLiveDataUse
import com.owncloud.android.domain.sharing.shares.usecases.GetSharesAsLiveDataUseCase
import com.owncloud.android.domain.sharing.shares.usecases.RefreshSharesFromServerAsyncUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndSharesAndProjectSpacesForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsForAccountAsStreamUseCase
Expand Down Expand Up @@ -208,6 +209,7 @@ val useCaseModule = module {

// Spaces
factoryOf(::GetPersonalAndProjectSpacesForAccountUseCase)
factoryOf(::GetPersonalAndSharesAndProjectSpacesForAccountUseCase)
factoryOf(::GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase)
factoryOf(::GetPersonalSpaceForAccountUseCase)
factoryOf(::GetProjectSpacesWithSpecialsForAccountAsStreamUseCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -29,7 +29,8 @@ import com.owncloud.android.domain.capabilities.usecases.RefreshCapabilitiesFrom
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH
import com.owncloud.android.domain.files.usecases.GetFileByRemotePathUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesForAccountUseCase
import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARES
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndSharesAndProjectSpacesForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.RefreshSpacesFromServerAsyncUseCase
import com.owncloud.android.presentation.authentication.AccountUtils
import com.owncloud.android.usecases.synchronization.SynchronizeFolderUseCase
Expand All @@ -48,7 +49,7 @@ class AccountDiscoveryWorker(
private val refreshCapabilitiesFromServerAsyncUseCase: RefreshCapabilitiesFromServerAsyncUseCase by inject()
private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject()
private val refreshSpacesFromServerAsyncUseCase: RefreshSpacesFromServerAsyncUseCase by inject()
private val getPersonalAndProjectSpacesForAccountUseCase: GetPersonalAndProjectSpacesForAccountUseCase by inject()
private val getPersonalAndSharesAndProjectSpacesForAccountUseCase: GetPersonalAndSharesAndProjectSpacesForAccountUseCase by inject()
private val getFileByRemotePathUseCase: GetFileByRemotePathUseCase by inject()
private val synchronizeFolderUseCase: SynchronizeFolderUseCase by inject()

Expand Down Expand Up @@ -76,7 +77,7 @@ class AccountDiscoveryWorker(

// 2.2 Account does support spaces
refreshSpacesFromServerAsyncUseCase(RefreshSpacesFromServerAsyncUseCase.Params(accountName))
val spaces = getPersonalAndProjectSpacesForAccountUseCase(GetPersonalAndProjectSpacesForAccountUseCase.Params(accountName))
val spaces = getPersonalAndSharesAndProjectSpacesForAccountUseCase(GetPersonalAndSharesAndProjectSpacesForAccountUseCase.Params(accountName))

// First we discover the root of the personal space since it is the first thing seen after login
val personalSpace = spaces.firstOrNull { it.isPersonal }
Expand All @@ -88,7 +89,17 @@ class AccountDiscoveryWorker(
}
}

// Then we discover the root of the rest of spaces
// Then we discover the root of the shares space since it is accessible in just 1 click
val sharesSpace = spaces.firstOrNull { it.id == SPACE_ID_SHARES}
sharesSpace?.let { space ->
val rootFolderForSpace =
getFileByRemotePathUseCase(GetFileByRemotePathUseCase.Params(accountName, ROOT_PATH, space.root.id)).getDataOrNull()
rootFolderForSpace?.let {
discoverRootFolder(it)
}
}

// And then we discover the root of the rest of spaces, which are accessible in 2 clicks
val spacesWithoutPersonal = spaces.filterNot { it.isPersonal }
spacesWithoutPersonal.forEach { space ->
// Create the root file for each space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -31,6 +31,7 @@ interface LocalSpacesDataSource {
fun getSpacesFromEveryAccountAsStream(): Flow<List<OCSpace>>
fun getSpacesByDriveTypeWithSpecialsForAccountAsFlow(accountName: String, filterDriveTypes: Set<String>): Flow<List<OCSpace>>
fun getPersonalAndProjectSpacesForAccount(accountName: String): List<OCSpace>
fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List<OCSpace>
fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace
fun getSpaceByIdForAccount(spaceId: String?, accountName: String): OCSpace?
fun getWebDavUrlForSpace(spaceId: String?, accountName: String): String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -102,6 +102,20 @@ class OCLocalSpacesDataSource(
).map { it.toModel() }
}

override fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List<OCSpace> {
val allSpaces = spacesDao.getSpacesByDriveTypeForAccount(
accountName = accountName,
filterDriveTypes = setOf(DRIVE_TYPE_PERSONAL, DRIVE_TYPE_PROJECT),
).map { it.toModel() }.toMutableList()
spacesDao.getSpaceByIdForAccount(
spaceId = SPACE_ID_SHARES,
accountName = accountName
)?.let {
allSpaces.add(it.toModel())
}
return allSpaces
}

override fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace {
return spacesDao.getSpaceWithSpecialsByIdForAccount(spaceId, accountName).toModel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -48,6 +48,9 @@ class OCSpacesRepository(
override fun getPersonalAndProjectSpacesForAccount(accountName: String) =
localSpacesDataSource.getPersonalAndProjectSpacesForAccount(accountName)

override fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String) =
localSpacesDataSource.getPersonalAndSharesAndProjectSpacesForAccount(accountName)

override fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String) =
localSpacesDataSource.getSpaceWithSpecialsByIdForAccount(spaceId, accountName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -30,6 +30,7 @@ interface SpacesRepository {
fun getSpacesByDriveTypeWithSpecialsForAccountAsFlow(accountName: String, filterDriveTypes: Set<String>): Flow<List<OCSpace>>
fun getPersonalSpaceForAccount(accountName: String): OCSpace?
fun getPersonalAndProjectSpacesForAccount(accountName: String): List<OCSpace>
fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List<OCSpace>
fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace
fun getSpaceByIdForAccount(spaceId: String?, accountName: String): OCSpace?
fun getWebDavUrlForSpace(accountName: String, spaceId: String?): String?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* ownCloud Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.domain.spaces.usecases

import com.owncloud.android.domain.BaseUseCase
import com.owncloud.android.domain.spaces.SpacesRepository
import com.owncloud.android.domain.spaces.model.OCSpace

class GetPersonalAndSharesAndProjectSpacesForAccountUseCase(
private val spacesRepository: SpacesRepository
) : BaseUseCase<List<OCSpace>, GetPersonalAndSharesAndProjectSpacesForAccountUseCase.Params>() {

override fun run(params: Params) = spacesRepository.getPersonalAndSharesAndProjectSpacesForAccount(params.accountName)

data class Params(
val accountName: String
)
}
Loading