diff --git a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt index ea87b25b8a..46ebfbdd25 100644 --- a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt +++ b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt @@ -69,9 +69,7 @@ import com.infomaniak.drive.utils.ApiTestUtils.createFileForTest import com.infomaniak.drive.utils.ApiTestUtils.deleteTestFile import com.infomaniak.drive.utils.ApiTestUtils.getCategory import com.infomaniak.drive.utils.ApiTestUtils.getShareLink -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.drive.utils.Utils.ROOT_ID -import kotlinx.coroutines.runBlocking import org.junit.* import org.junit.runner.RunWith @@ -129,8 +127,7 @@ class ApiRepositoryTest : KDriveTest() { @Test fun getFileActivities() { - val okHttpClientWithTimeout = runBlocking { KDriveHttpClient.getHttpClient(user.id, 30) } - with(getFileActivities(okHttpClientWithTimeout, testFile, 1)) { + with(getFileActivities(testFile, 1, false)) { if (isSuccess()) { assertApiResponse(this) } else { diff --git a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt index 75819719fd..5856ba25ac 100644 --- a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt +++ b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt @@ -22,11 +22,14 @@ import com.google.gson.JsonElement import com.infomaniak.drive.data.models.* import com.infomaniak.drive.data.models.drive.Category import com.infomaniak.drive.data.models.drive.DriveInfo +import com.infomaniak.drive.utils.AccountUtils +import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import com.infomaniak.lib.core.models.User import com.infomaniak.lib.core.networking.HttpClient import com.infomaniak.lib.core.utils.ApiController.ApiMethod.* import com.infomaniak.lib.core.utils.ApiController.callApi +import kotlinx.coroutines.runBlocking import okhttp3.OkHttpClient object ApiRepository { @@ -90,9 +93,15 @@ object ApiRepository { return callApi(url, GET, okHttpClient = okHttpClient) } - fun getFileActivities(okHttpClient: OkHttpClient, file: File, page: Int): ApiResponse> { - val url = "${ApiRoutes.getFileActivities(file)}?${pagination(page)}&depth=children&from_date=${file.responseAt}" + - "&with=file,rights,collaborative_folder,favorite,share_link,mobile,categories" + ACTIONS + fun getFileActivities(file: File, page: Int, forFileList: Boolean): ApiResponse> { + val queries = if (forFileList) { + "&depth=children&from_date=${file.responseAt}&with=file,rights,collaborative_folder,favorite,share_link,mobile,categories" + } else { + "&with=user" + } + val url = "${ApiRoutes.getFileActivities(file)}?${pagination(page)}$queries$ACTIONS" + // Increase timeout for this api call because it can take more than 10s to process data + val okHttpClient = runBlocking { KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) } return callApi(url, GET, okHttpClient = okHttpClient) } diff --git a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt index a8def1d076..a5e1ab339b 100644 --- a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt +++ b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt @@ -748,11 +748,8 @@ object FileController { page: Int, userDrive: UserDrive? = null ): Map { - val okHttpClient = runBlocking { - userDrive?.userId?.let { KDriveHttpClient.getHttpClient(it) } ?: HttpClient.okHttpClient - } val returnResponse = arrayMapOf() - val apiResponse = ApiRepository.getFileActivities(okHttpClient, folder, page) + val apiResponse = ApiRepository.getFileActivities(folder, page, true) if (!apiResponse.isSuccess()) return returnResponse return if (apiResponse.data?.isNotEmpty() == true) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt index e76a13392c..e17fbf92a6 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt @@ -26,8 +26,6 @@ import com.infomaniak.drive.data.models.File import com.infomaniak.drive.data.models.FileActivity import com.infomaniak.drive.data.models.FileComment import com.infomaniak.drive.data.models.Share -import com.infomaniak.drive.utils.AccountUtils -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -46,9 +44,7 @@ class FileDetailsViewModel : ViewModel() { return liveData(Dispatchers.IO + getFileActivitiesJob) { suspend fun recursive(page: Int) { - // Increase timeout for this api call because it can take more than 10s to process data - val okHttpClient = KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) - val apiRepository = ApiRepository.getFileActivities(okHttpClient, file, page) + val apiRepository = ApiRepository.getFileActivities(file, page, false) if (apiRepository.isSuccess()) { when { apiRepository.data?.isNullOrEmpty() == true -> emit(null)