Skip to content

Commit 981ffb3

Browse files
committed
use conversation subfolders
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
1 parent 1f59ffb commit 981ffb3

5 files changed

Lines changed: 32 additions & 37 deletions

File tree

app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ interface NcApiCoroutines {
466466
@DELETE
467467
suspend fun markRoomAsUnread(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
468468

469-
470469
@FormUrlEncoded
471470
@POST
472471
suspend fun probeConversationAttachmentFolder(

app/src/main/java/com/nextcloud/talk/jobs/UploadAndShareFilesWorker.kt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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!!

app/src/main/java/com/nextcloud/talk/models/json/chatpostattachment/ChatPostAttachmentOCS.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package com.nextcloud.talk.models.json.chatpostattachment
1010
import android.os.Parcelable
1111
import com.bluelinelabs.logansquare.annotation.JsonField
1212
import com.bluelinelabs.logansquare.annotation.JsonObject
13-
import com.nextcloud.talk.models.json.chatprobeattachmentfolder.ChatProbeAttachmentData
1413
import kotlinx.parcelize.Parcelize
1514

1615
@Parcelize

app/src/main/java/com/nextcloud/talk/upload/chunked/ChunkedFileUploader.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class ChunkedFileUploader(
7373
@Suppress("Detekt.TooGenericExceptionCaught")
7474
fun upload(localFile: File, mimeType: MediaType?, targetPath: String): Boolean {
7575
try {
76-
7776
if (supportsConversationFolders) {
7877
return uploadToDraftFolder(localFile, mimeType)
7978
}
@@ -131,13 +130,12 @@ class ChunkedFileUploader(
131130
}
132131
}
133132

134-
135133
private fun uploadToDraftFolder(localFile: File, mimeType: MediaType?): Boolean {
136134
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token) ?: return false
137135
val probeResponse = runBlocking {
138136
ncApiCoroutines.probeConversationAttachmentFolder(
139137
credentials,
140-
ApiUtils.getUrlForChatAttachmentFolder(ApiUtils.API_V1,currentUser.baseUrl!!, roomToken),
138+
ApiUtils.getUrlForChatAttachmentFolder(ApiUtils.API_V1, currentUser.baseUrl!!, roomToken),
141139
listOf(localFile.name)
142140
)
143141
}
@@ -150,15 +148,15 @@ class ChunkedFileUploader(
150148
val uploadId = UUID.randomUUID().toString()
151149
val temporaryPath = "/$draftFolderPath/$uploadId-0-${localFile.name}"
152150
uploadFullFile(localFile, mimeType, temporaryPath)
153-
runBlocking {
151+
runBlocking {
154152
ncApiCoroutines.postConversationAttachment(
155153
credentials,
156-
ApiUtils.getUrlForChatAttachment(ApiUtils.API_V1,currentUser.baseUrl!!, roomToken),
157-
temporaryPath,
154+
ApiUtils.getUrlForChatAttachment(ApiUtils.API_V1, currentUser.baseUrl!!, roomToken),
155+
temporaryPath,
158156
uploadId,
159157
renamedFileName,
160158
metaData
161-
)
159+
)
162160
}
163161
return true
164162
}
@@ -196,7 +194,6 @@ class ChunkedFileUploader(
196194
}
197195
}
198196

199-
200197
@Suppress("Detekt.ComplexMethod")
201198
private fun getUploadedChunks(davResource: DavResource, uploadFolderUri: String): MutableList<Chunk> {
202199
val davResponse = DavResponse()

app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ object ApiUtils {
556556
fun getUrlForScheduledMessage(baseUrl: String?, token: String, messageId: String?): String =
557557
getUrlForScheduledMessages(baseUrl, token) + "/$messageId"
558558

559-
560559
fun getUrlForChatAttachment(version: Int, baseUrl: String?, token: String): String =
561560
getUrlForChat(version, baseUrl, token) + "/attachment"
562561

0 commit comments

Comments
 (0)