@@ -122,7 +122,9 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
122122 file = FileUtils .getFileFromUri(context, sourceFileUri)
123123 val remotePath = getRemotePath(currentUser)
124124
125- val useConversationSubfolders = CapabilitiesUtil .hasConversationSubfoldersForAttachments(currentUser.capabilities!! .spreedCapability!! )
125+ val useConversationSubfolders = CapabilitiesUtil .hasConversationSubfoldersForAttachments(
126+ currentUser.capabilities!! .spreedCapability!!
127+ )
126128 initNotificationSetup()
127129 file?.let { isChunkedUploading = it.length() > CHUNK_UPLOAD_THRESHOLD_SIZE }
128130 val uploadSuccess: Boolean = uploadFile(sourceFileUri, metaData, remotePath, useConversationSubfolders)
@@ -145,30 +147,37 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
145147 }
146148 }
147149
148- private fun uploadFile (sourceFileUri : Uri ,
150+ private fun uploadFile (
151+ sourceFileUri : Uri ,
149152 metaData : String? ,
150153 remotePath : String ,
151- useConversationSubfolders : Boolean ): Boolean =
154+ useConversationSubfolders : Boolean
155+ ): Boolean =
152156 if (file == null ) {
153157 false
154- }else if (useConversationSubfolders) {
158+ } else if (useConversationSubfolders) {
155159 uploadUsingConversationSubfolders(sourceFileUri, metaData)
156160 } else if (isChunkedUploading) {
157161 Log .d(TAG , " starting chunked upload because size is " + file!! .length())
158162 initNotificationWithPercentage()
159163 val mimeType = context.contentResolver.getType(sourceFileUri)?.toMediaTypeOrNull()
160- chunkedFileUploader = ChunkedFileUploader (okHttpClient, currentUser, roomToken, metaData, this ,
161- ncApiCoroutines,useConversationSubfolders )
164+ chunkedFileUploader = ChunkedFileUploader (
165+ okHttpClient,
166+ currentUser,
167+ roomToken,
168+ metaData,
169+ this ,
170+ ncApiCoroutines,
171+ useConversationSubfolders
172+ )
162173 chunkedFileUploader!! .upload(file!! , mimeType, remotePath)
163174 } else {
164175 Log .d(TAG , " starting normal upload (not chunked) of $fileName " )
165- FileUploader (okHttpClient, context, currentUser, roomToken, ncApi, file!! )
166- .upload(sourceFileUri, fileName, remotePath, metaData)
167- .blockingFirst()
168-
176+ FileUploader (okHttpClient, context, currentUser, roomToken, ncApi, file!! )
177+ .upload(sourceFileUri, fileName, remotePath, metaData)
178+ .blockingFirst()
169179 }
170180
171-
172181 private fun uploadUsingConversationSubfolders (sourceFileUri : Uri , metaData : String? ): Boolean =
173182 runBlocking {
174183 val credentials = ApiUtils .getCredentials(
@@ -179,14 +188,14 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
179188 val probeResponse = ncApiCoroutines.probeConversationAttachmentFolder(
180189 credentials,
181190 ApiUtils .getUrlForChatAttachmentFolder(ApiUtils .API_V1 , currentUser.baseUrl, roomToken),
182- (listOf (fileName))
191+ (listOf (fileName))
183192 )
184193 val draftFolderPath = probeResponse.ocs?.data?.folder?.trimEnd(' /' )
185194 if (draftFolderPath.isNullOrEmpty()) {
186195 Log .e(TAG , " Draft folder path missing in probe response" )
187196 return @runBlocking false
188197 }
189- val predictedName = resolveFinalFileName(fileName,probeResponse.ocs?.data!! )
198+ val predictedName = resolveFinalFileName(fileName, probeResponse.ocs?.data!! )
190199 val tempRemotePath = " $draftFolderPath /$uploadId -0-$fileName "
191200
192201 val uploadSuccess = if (isChunkedUploading) {
@@ -215,22 +224,17 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
215224 credentials,
216225 ApiUtils .getUrlForChatAttachment(ApiUtils .API_V1 , currentUser.baseUrl, roomToken),
217226 tempRemotePath,
218- uploadId,
227+ uploadId,
219228 predictedName,
220- metaData,
221- )
229+ metaData
230+ )
222231 }
223232 .onFailure { Log .e(TAG , " Failed to finalize uploaded attachment" , it) }
224233 .isSuccess
225234 }
226235
227- private fun resolveFinalFileName (
228- originalName : String ,
229- probeData : ChatProbeAttachmentData
230- ): String {
231- return probeData.renames?.get(originalName) ? : originalName
232- }
233-
236+ private fun resolveFinalFileName (originalName : String , probeData : ChatProbeAttachmentData ): String =
237+ probeData.renames?.get(originalName) ? : originalName
234238
235239 private fun uploadFileToDraftPathUsingWebDav (sourceFileUri : Uri , remotePath : String ): Boolean =
236240 runCatching {
@@ -272,9 +276,6 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
272276 )
273277 .build()
274278
275-
276-
277-
278279 private fun getRemotePath (currentUser : User ): String {
279280 val remotePath = CapabilitiesUtil .getAttachmentFolder(
280281 currentUser.capabilities!! .spreedCapability!!
0 commit comments