diff --git a/WordPress/src/main/java/org/wordpress/android/support/ZendeskUploadHelper.kt b/WordPress/src/main/java/org/wordpress/android/support/ZendeskUploadHelper.kt index d40eec6cd3eb..5e014d2a60f5 100644 --- a/WordPress/src/main/java/org/wordpress/android/support/ZendeskUploadHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/support/ZendeskUploadHelper.kt @@ -24,17 +24,17 @@ class ZendeskUploadHelper @Inject constructor() { context: Context, uri: Uri, callback: ZendeskCallback, - ): zendesk.support.Attachment? { + ) { val uploadProvider = Support.INSTANCE.provider()?.uploadProvider() if (uploadProvider == null) { AppLog.e(T.SUPPORT, "Upload provider is null") - return null + return } val file = uri.fileName(context)?.let { File(it) } if (file == null) { AppLog.e(T.SUPPORT, "Upload file is null") - return null + return } uploadProvider.uploadAttachment( @@ -43,18 +43,20 @@ class ZendeskUploadHelper @Inject constructor() { uri.mimeType(context), callback ) - - return null } suspend fun uploadAttachments( context: Context, scope: CoroutineScope, uris: List, - ): zendesk.support.Attachment? { + ): List { + val attachments = mutableListOf() + val callback = object : ZendeskCallback() { override fun onSuccess(result: UploadResponse) { - // return result.attachment + result.attachment?.let { + attachments.add(it) + } } override fun onError(errorResponse: ErrorResponse?) { @@ -70,6 +72,7 @@ class ZendeskUploadHelper @Inject constructor() { } job.join() } - return null + + return attachments } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormViewModel.kt index 14b5923b9302..4ece58debcbb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/feedbackform/FeedbackFormViewModel.kt @@ -68,19 +68,22 @@ class FeedbackFormViewModel @Inject constructor( // identity if it hasn't been previously set zendeskHelper.createAnonymousIdentityIfNeeded() + val zendeskAttachments = ArrayList() if (_attachments.value.isNotEmpty()) { launch { - zendeskUploadHelper.uploadAttachments( + zendeskAttachments.addAll(zendeskUploadHelper.uploadAttachments( context = context, scope = viewModelScope, uris = _attachments.value.map { it.uri } ) + ) } } _isProgressShowing.value = true createZendeskFeedbackRequest( context = context, + attachmentIds = zendeskAttachments.map { it.id.toString() }, callback = object : ZendeskHelper.CreateRequestCallback() { override fun onSuccess() { _isProgressShowing.value = false @@ -96,6 +99,7 @@ class FeedbackFormViewModel @Inject constructor( private fun createZendeskFeedbackRequest( context: Context, + attachmentIds: List, callback: ZendeskHelper.CreateRequestCallback ) { zendeskHelper.createRequest( @@ -104,9 +108,7 @@ class FeedbackFormViewModel @Inject constructor( selectedSite = selectedSiteRepository.getSelectedSite(), extraTags = listOf("in_app_feedback"), requestDescription = _messageText.value, - attachmentIds = _attachments.value.filter { !it.zendeskId.isNullOrEmpty() }.map { - it.zendeskId!! - }, + attachmentIds = attachmentIds, callback = callback ) }