From cf4906f2f414c885e7a88c91b3012d92a17f1048 Mon Sep 17 00:00:00 2001 From: Czapla <56671347+Antoni-Czaplicki@users.noreply.github.com> Date: Thu, 9 Sep 2021 18:52:04 +0200 Subject: [PATCH] [API/Vulcan] Fix sending messages. (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix sending message * Add checking for address name/hash when sending message. Co-authored-by: Kuba Szczodrzyński --- .../edziennik/data/api/Errors.kt | 1 + .../data/api/edziennik/vulcan/DataVulcan.kt | 10 +++++++++ .../vulcan/data/hebe/VulcanHebeMain.kt | 6 ++++++ .../vulcan/data/hebe/VulcanHebeSendMessage.kt | 21 +++++++++++++++++-- app/src/main/res/values/errors.xml | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt index 5738064c..eefc1d31 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt @@ -195,6 +195,7 @@ const val ERROR_VULCAN_HEBE_FIREBASE_ERROR = 362 const val ERROR_VULCAN_HEBE_CERTIFICATE_GONE = 363 const val ERROR_VULCAN_HEBE_SERVER_ERROR = 364 const val ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND = 365 +const val ERROR_VULCAN_HEBE_MISSING_SENDER_ENTRY = 366 const val ERROR_VULCAN_API_DEPRECATED = 390 const val ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN = 501 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt index 55185745..e3516ad4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/DataVulcan.kt @@ -222,6 +222,16 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app get() { mHebeContext = mHebeContext ?: profile?.getStudentData("hebeContext", null); return mHebeContext } set(value) { profile?.putStudentData("hebeContext", value) ?: return; mHebeContext = value } + private var mSenderAddressHash: String? = null + var senderAddressHash: String? + get() { mSenderAddressHash = mSenderAddressHash ?: profile?.getStudentData("senderAddressHash", null); return mSenderAddressHash } + set(value) { profile?.putStudentData("senderAddressHash", value) ?: return; mSenderAddressHash = value } + + private var mSenderAddressName: String? = null + var senderAddressName: String? + get() { mSenderAddressName = mSenderAddressName ?: profile?.getStudentData("senderAddressName", null); return mSenderAddressName } + set(value) { profile?.putStudentData("senderAddressName", value) ?: return; mSenderAddressName = value } + val apiUrl: String? get() { val url = when (apiToken[symbol]?.substring(0, 3)) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMain.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMain.kt index c017e3c9..5e2d31c0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMain.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMain.kt @@ -97,6 +97,10 @@ class VulcanHebeMain( val studentSemesterId = period.getInt("Id") ?: return@forEach val studentSemesterNumber = period.getInt("Number") ?: return@forEach + val senderEntry = student.getJsonObject("SenderEntry") + val senderAddressName = senderEntry.getString("Address") + val senderAddressHash = senderEntry.getString("AddressHash") + val hebeContext = student.getString("Context") val isParent = login.getString("LoginRole").equals("opiekun", ignoreCase = true) @@ -143,6 +147,8 @@ class VulcanHebeMain( studentData["schoolSymbol"] = schoolSymbol studentData["schoolShort"] = schoolShort studentData["schoolName"] = schoolCode + studentData["senderAddressName"] = senderAddressName + studentData["senderAddressHash"] = senderAddressHash studentData["hebeContext"] = hebeContext } dateSemester1Start?.let { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeSendMessage.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeSendMessage.kt index 8f5f5afa..c6a02ae7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeSendMessage.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeSendMessage.kt @@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe import com.google.gson.JsonObject import org.greenrobot.eventbus.EventBus import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.data.api.ERROR_VULCAN_HEBE_MISSING_SENDER_ENTRY import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_MESSAGES_SEND import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe @@ -27,6 +28,22 @@ class VulcanHebeSendMessage( } init { + if (data.senderAddressName == null || data.senderAddressHash == null) { + VulcanHebeMain(data).getStudents(data.profile, null) { + if (data.senderAddressName == null || data.senderAddressHash == null) { + data.error(TAG, ERROR_VULCAN_HEBE_MISSING_SENDER_ENTRY) + } + else { + sendMessage() + } + } + } + else { + sendMessage() + } + } + + private fun sendMessage() { val recipientsArray = JsonArray() recipients.forEach { teacher -> recipientsArray += JsonObject( @@ -40,10 +57,10 @@ class VulcanHebeSendMessage( val senderName = (profile?.accountName ?: profile?.studentNameLong) ?.swapFirstLastName() ?: "" val sender = JsonObject( - "Address" to senderName, + "Address" to data.senderAddressName, "LoginId" to data.studentLoginId.toString(), "Initials" to senderName.getNameInitials(), - "AddressHash" to senderName.sha1Hex() + "AddressHash" to data.senderAddressHash ) apiPost( diff --git a/app/src/main/res/values/errors.xml b/app/src/main/res/values/errors.xml index d90af9ed..827227c5 100644 --- a/app/src/main/res/values/errors.xml +++ b/app/src/main/res/values/errors.xml @@ -165,6 +165,7 @@ ERROR_VULCAN_HEBE_CERTIFICATE_GONE ERROR_VULCAN_HEBE_SERVER_ERROR ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND + ERROR_VULCAN_HEBE_MISSING_SENDER_ENTRY ERROR_VULCAN_API_DEPRECATED ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN @@ -363,6 +364,7 @@ VULCAN®: urządzenie usunięte. Zaloguj się ponownie do dziennika. VULCAN®: błąd serwera. Dziennik może być przeciążony. VULCAN®: nie znaleziono bytu + Błąd wysyłania wiadomości - brak informacji o nadawcy. W związku z wygaszeniem aplikacji Dzienniczek+ przez firmę Vulcan, należy zalogować się ponownie.\n\nAby móc dalej korzystać z aplikacji Szkolny.eu, otwórz Ustawienia i wybierz opcję Dodaj nowego ucznia.\nNastępnie zaloguj się do dziennika Vulcan zgodnie z instrukcją.\n\nPrzepraszamy za niedogodności. Błędny email lub hasło