[Vulcan/Hebe] Add setting message status as read.

This commit is contained in:
Kuba Szczodrzyński 2021-02-21 22:54:52 +01:00
parent 621a7ac642
commit 6c0ddd3e6d
4 changed files with 69 additions and 4 deletions

View File

@ -135,6 +135,7 @@ const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
const val VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS = "api/mobile/message/status"
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"

View File

@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanData
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiAttachments
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiMessagesChangeStatus
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiSendMessage
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeMessagesChangeStatus
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.firstlogin.VulcanFirstLogin
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLogin
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
@ -98,7 +99,7 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
completed()
return@login
}
VulcanApiMessagesChangeStatus(data, message) {
VulcanHebeMessagesChangeStatus(data, message) {
completed()
}
}

View File

@ -207,8 +207,9 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
}
val envelope = when (T::class.java) {
JsonObject::class.java -> json.getJsonObject("Envelope")
JsonArray::class.java -> json.getJsonArray("Envelope")
JsonObject::class.java -> json.getJsonObject("Envelope") as T
JsonArray::class.java -> json.getJsonArray("Envelope") as T
java.lang.Boolean::class.java -> json.getBoolean("Envelope") as T
else -> {
data.error(ApiError(tag, ERROR_RESPONSE_EMPTY)
.withResponse(response)
@ -219,7 +220,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
}
try {
onSuccess(envelope as T, response)
onSuccess(envelope, response)
} catch (e: Exception) {
data.error(ApiError(tag, EXCEPTION_VULCAN_HEBE_REQUEST)
.withResponse(response)

View File

@ -0,0 +1,62 @@
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
import org.greenrobot.eventbus.EventBus
import pl.szczodrzynski.edziennik.JsonObject
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
import pl.szczodrzynski.edziennik.data.db.entity.Message
import pl.szczodrzynski.edziennik.data.db.entity.MessageRecipient
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
class VulcanHebeMessagesChangeStatus(
override val data: DataVulcan,
private val messageObject: MessageFull,
val onSuccess: () -> Unit
) : VulcanHebe(data, null) {
companion object {
const val TAG = "VulcanHebeMessagesChangeStatus"
}
init {
apiPost(
TAG,
VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS,
payload = JsonObject(
"MessageId" to messageObject.id,
"LoginId" to data.studentLoginId,
"Status" to 1
)
) { _: Boolean, _ ->
if (!messageObject.seen) {
data.setSeenMetadataList.add(
Metadata(
profileId,
Metadata.TYPE_MESSAGE,
messageObject.id,
true,
true
)
)
messageObject.seen = true
}
if (messageObject.type != Message.TYPE_SENT) {
val messageRecipientObject = MessageRecipient(
profileId,
-1,
-1,
System.currentTimeMillis(),
messageObject.id
)
data.messageRecipientList.add(messageRecipientObject)
}
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
onSuccess()
}
}
}