diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesChangeStatus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesChangeStatus.kt index 9f2bda53..abe3cb8c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesChangeStatus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesChangeStatus.kt @@ -4,13 +4,15 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api +import org.greenrobot.eventbus.EventBus import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi +import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_SENT -import pl.szczodrzynski.edziennik.data.db.full.MessageFull 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 VulcanApiMessagesChangeStatus( override val data: DataVulcan, @@ -22,40 +24,42 @@ class VulcanApiMessagesChangeStatus( } init { - data.profile?.also { profile -> - apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS, parameters = mapOf( - "WiadomoscId" to messageObject.id, - "FolderWiadomosci" to "Odebrane", - "Status" to "Widoczna", - "LoginId" to data.studentLoginId, - "IdUczen" to data.studentId - )) { _, _ -> + apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS, parameters = mapOf( + "WiadomoscId" to messageObject.id, + "FolderWiadomosci" to "Odebrane", + "Status" to "Widoczna", + "LoginId" to data.studentLoginId, + "IdUczen" to data.studentId + )) { _, _ -> - if (!messageObject.seen) { - data.setSeenMetadataList.add(Metadata( - profileId, - Metadata.TYPE_MESSAGE, - messageObject.id, - true, - true, - messageObject.addedDate - )) - } + if (!messageObject.seen) { + data.setSeenMetadataList.add(Metadata( + profileId, + Metadata.TYPE_MESSAGE, + messageObject.id, + true, + true, + messageObject.addedDate + )) - if (messageObject.type != TYPE_SENT) { - val messageRecipientObject = MessageRecipient( - profileId, - -1, - -1, - System.currentTimeMillis(), - messageObject.id - ) - - data.messageRecipientList.add(messageRecipientObject) - } - - onSuccess() + messageObject.seen = true } + + if (messageObject.type != TYPE_SENT) { + val messageRecipientObject = MessageRecipient( + profileId, + -1, + -1, + System.currentTimeMillis(), + messageObject.id + ) + + data.messageRecipientList.add(messageRecipientObject) + } + + EventBus.getDefault().postSticky(MessageGetEvent(messageObject)) + + onSuccess() } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesInbox.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesInbox.kt index 49463174..905504a4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesInbox.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesInbox.kt @@ -9,12 +9,8 @@ import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_RECEIVED import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_MESSAGES_INBOX import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi -import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS -import pl.szczodrzynski.edziennik.data.db.entity.Message +import pl.szczodrzynski.edziennik.data.db.entity.* import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED -import pl.szczodrzynski.edziennik.data.db.entity.MessageRecipient -import pl.szczodrzynski.edziennik.data.db.entity.Metadata -import pl.szczodrzynski.edziennik.data.db.entity.Teacher import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.models.Date import kotlin.text.replace @@ -88,7 +84,7 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () -> data.messageIgnoreList.add(messageObject) data.messageRecipientList.add(messageRecipientObject) - data.metadataList.add(Metadata( + data.setSeenMetadataList.add(Metadata( profileId, Metadata.TYPE_MESSAGE, id, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesSent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesSent.kt index 094d3967..4949d867 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesSent.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiMessagesSent.kt @@ -99,7 +99,7 @@ class VulcanApiMessagesSent(override val data: DataVulcan, val onSuccess: () -> ) data.messageIgnoreList.add(messageObject) - data.metadataList.add(Metadata( + data.setSeenMetadataList.add(Metadata( profileId, Metadata.TYPE_MESSAGE, id, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt index eab68d6b..f728c5e8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt @@ -179,6 +179,11 @@ class MessageFragment : Fragment(), CoroutineScope { return } + if(message.type == TYPE_RECEIVED && !message.seen && app.profile.loginStoreType == LoginStore.LOGIN_TYPE_VULCAN) { + EdziennikTask.messageGet(App.profileId, message).enqueue(activity) + return + } + showMessage() }