mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[API/Vulcan] Fix sending messages. (#64)
* Fix sending message * Add checking for address name/hash when sending message. Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
This commit is contained in:
parent
680a5dfea3
commit
cf4906f2f4
@ -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
|
||||
|
@ -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)) {
|
||||
|
@ -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 {
|
||||
|
@ -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(
|
||||
|
@ -165,6 +165,7 @@
|
||||
<string name="error_363" translatable="false">ERROR_VULCAN_HEBE_CERTIFICATE_GONE</string>
|
||||
<string name="error_364" translatable="false">ERROR_VULCAN_HEBE_SERVER_ERROR</string>
|
||||
<string name="error_365" translatable="false">ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND</string>
|
||||
<string name="error_366" translatable="false">ERROR_VULCAN_HEBE_MISSING_SENDER_ENTRY</string>
|
||||
<string name="error_390" translatable="false">ERROR_VULCAN_API_DEPRECATED</string>
|
||||
|
||||
<string name="error_501" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN</string>
|
||||
@ -363,6 +364,7 @@
|
||||
<string name="error_363_reason">VULCAN®: urządzenie usunięte. Zaloguj się ponownie do dziennika.</string>
|
||||
<string name="error_364_reason">VULCAN®: błąd serwera. Dziennik może być przeciążony.</string>
|
||||
<string name="error_365_reason">VULCAN®: nie znaleziono bytu</string>
|
||||
<string name="error_366_reason">Błąd wysyłania wiadomości - brak informacji o nadawcy.</string>
|
||||
<string name="error_390_reason">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.</string>
|
||||
|
||||
<string name="error_501_reason">Błędny email lub hasło</string>
|
||||
|
Loading…
Reference in New Issue
Block a user