[API/Librus] Use Synergia message module when messages module login fails.

This commit is contained in:
Kacper Ziubryniewicz 2020-05-10 19:44:44 +02:00
parent 35f4f34342
commit ef1cdd5b20
5 changed files with 24 additions and 12 deletions

View File

@ -277,4 +277,10 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
var timetableNotPublic: Boolean
get() { mTimetableNotPublic = mTimetableNotPublic ?: profile?.getStudentData("timetableNotPublic", false); return mTimetableNotPublic ?: false }
set(value) { profile?.putStudentData("timetableNotPublic", value) ?: return; mTimetableNotPublic = value }
/**
* Set to false when Recaptcha helper doesn't provide a working token.
* When it's set to false uses Synergia for messages.
*/
var messagesLoginSuccessful: Boolean = true
}

View File

@ -9,6 +9,8 @@ import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.data.api.*
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusData
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api.LibrusApiAnnouncementMarkAsRead
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetAttachment
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetMessage
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetRecipientList
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesSendMessage
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.*
@ -86,10 +88,9 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
}
override fun getMessage(message: MessageFull) {
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
LibrusSynergiaGetMessage(data, message) {
completed()
}
login(LOGIN_METHOD_LIBRUS_MESSAGES) {
if (data.messagesLoginSuccessful) LibrusMessagesGetMessage(data, message) { completed() }
else LibrusSynergiaGetMessage(data, message) { completed() }
}
}
@ -121,9 +122,8 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
when (owner) {
is Message -> {
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
LibrusSynergiaGetAttachment(data, owner, attachmentId, attachmentName) {
completed()
}
if (data.messagesLoginSuccessful) LibrusMessagesGetAttachment(data, owner, attachmentId, attachmentName) { completed() }
LibrusSynergiaGetAttachment(data, owner, attachmentId, attachmentName) { completed() }
}
}
is EventFull -> {

View File

@ -216,11 +216,13 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
*/
ENDPOINT_LIBRUS_MESSAGES_RECEIVED -> {
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
if (data.messagesLoginSuccessful) LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
else LibrusSynergiaGetMessages(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
}
ENDPOINT_LIBRUS_MESSAGES_SENT -> {
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
if (data.messagesLoginSuccessful) LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
else LibrusSynergiaGetMessages(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
}
else -> onSuccess(endpointId)

View File

@ -54,7 +54,7 @@ class LibrusSynergiaGetMessages(override val data: DataLibrus,
val sentDate = Date.fromIso(messageElement.child(4).text())
val recipientName = messageElement.child(2).text().split('(')[0].fixName()
val recipientId = getRecipientId(recipientName)
val read = messageElement.child(2).attr("style").isNotEmpty()
val read = messageElement.child(2).attr("style").isNullOrBlank()
val senderId = when (type) {
Message.TYPE_RECEIVED -> recipientId
@ -68,7 +68,7 @@ class LibrusSynergiaGetMessages(override val data: DataLibrus,
val notified = when (type) {
Message.TYPE_SENT -> true
else -> profile?.empty ?: false
else -> read || profile?.empty ?: false
}
val messageObject = Message(

View File

@ -55,7 +55,11 @@ class LibrusLoginMessages(val data: DataLibrus, val onSuccess: () -> Unit) {
}
text?.contains("<message>Niepoprawny login i/lub hasło.</message>") == true -> data.error(TAG, ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN, response, text)
text?.contains("stop.png") == true -> data.error(TAG, ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED, response, text)
text?.contains("eAccessDeny") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)
text?.contains("eAccessDeny") == true -> {
// data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)
data.messagesLoginSuccessful = false
onSuccess()
}
text?.contains("OffLine") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_MAINTENANCE, response, text)
text?.contains("<status>error</status>") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ERROR, response, text)
text?.contains("<type>eVarWhitThisNameNotExists</type>") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)