Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 433fad76 authored by Hunter Kehoe's avatar Hunter Kehoe
Browse files

remove attachment download limit if userAction

parent fcce44be
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -82,11 +82,7 @@ class DownloadAttachmentWorker(private val context: Context, params: WorkerParam
                Log.d(TAG, "Starting download to content URI: $uri")
                var bytesCopied: Long = 0
                val outFile = resolver.openOutputStream(uri) ?: throw Exception("Cannot open output stream")
                val downloadLimit = if (repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_NEVER && repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_ALWAYS) {
                    repository.getAutoDownloadMaxSize()
                } else {
                    null
                }
                val downloadLimit = getDownloadLimit(userAction)
                outFile.use { fileOut ->
                    val fileIn = response.body!!.byteStream()
                    val buffer = ByteArray(BUFFER_SIZE)
@@ -192,6 +188,14 @@ class DownloadAttachmentWorker(private val context: Context, params: WorkerParam
        }
    }

    private fun getDownloadLimit(userAction: Boolean): Long? {
        return if (userAction || repository.getAutoDownloadMaxSize() == Repository.AUTO_DOWNLOAD_ALWAYS) {
            null
        } else {
            repository.getAutoDownloadMaxSize()
        }
    }

    private fun createUri(notification: Notification): Uri {
        val attachmentDir = File(context.cacheDir, ATTACHMENT_CACHE_DIR)
        if (!attachmentDir.exists() && !attachmentDir.mkdirs()) {