diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt index bccaa1f9..845cf83f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt @@ -252,10 +252,10 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) { .enqueue() } - fun sandboxGetFile(tag: String, action: String, targetFile: File, onSuccess: (file: File) -> Unit, + fun sandboxGetFile(tag: String, url: String, targetFile: File, onSuccess: (file: File) -> Unit, onProgress: (written: Long, total: Long) -> Unit) { - d(tag, "Request: Librus/Messages - $LIBRUS_SANDBOX_URL$action") + d(tag, "Request: Librus/Messages - $url") val callback = object : FileCallbackHandler(targetFile) { override fun onSuccess(file: File?, response: Response?) { @@ -291,7 +291,7 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) { } Request.builder() - .url("$LIBRUS_SANDBOX_URL$action") + .url("$url") .userAgent(SYNERGIA_USER_AGENT) .post() .callback(callback) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetAttachment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetAttachment.kt index f7234891..38475c1f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetAttachment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetAttachment.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.* import org.greenrobot.eventbus.EventBus import pl.szczodrzynski.edziennik.data.api.ERROR_FILE_DOWNLOAD import pl.szczodrzynski.edziennik.data.api.EXCEPTION_LIBRUS_MESSAGES_REQUEST +import pl.szczodrzynski.edziennik.data.api.LIBRUS_SANDBOX_URL import pl.szczodrzynski.edziennik.data.api.Regexes import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages @@ -53,11 +54,10 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus, val attachmentKey = keyMatcher[1] getAttachmentCheckKey(attachmentKey) { - downloadAttachment(attachmentKey) + downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey") } } else { - data.error(ApiError(TAG, ERROR_FILE_DOWNLOAD) - .withApiResponse(doc.toString())) + downloadAttachment(downloadLink) } } } @@ -91,10 +91,10 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus, } } - private fun downloadAttachment(attachmentKey: String) { + private fun downloadAttachment(url: String) { val targetFile = File(Utils.getStorageDir(), attachmentName) - sandboxGetFile(TAG, "CSDownload&singleUseKey=$attachmentKey", targetFile, { file -> + sandboxGetFile(TAG, url, targetFile, { file -> val event = AttachmentGetEvent( profileId, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetList.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetList.kt index f4aa2b3a..5574970f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetList.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusMessagesGetList.kt @@ -109,6 +109,11 @@ class LibrusMessagesGetList(override val data: DataLibrus, id ) + element.select("isAnyFileAttached")?.text()?.let { + if (it == "1") + messageObject.overrideHasAttachments = true + } + data.messageIgnoreList.add(messageObject) data.messageRecipientList.add(messageRecipientObject) data.setSeenMetadataList.add(Metadata(