forked from github/szkolny
[APIv2/Vulcan] Add getting sent messages
This commit is contained in:
parent
385fe21d16
commit
23d55ec571
@ -68,6 +68,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||||
VulcanApiMessagesInbox(data) { onSuccess() }
|
VulcanApiMessagesInbox(data) { onSuccess() }
|
||||||
}
|
}
|
||||||
|
ENDPOINT_VULCAN_API_MESSAGES_SENT -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||||
|
VulcanApiMessagesSent(data) { onSuccess() }
|
||||||
|
}
|
||||||
else -> onSuccess()
|
else -> onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_MESSAGES_INB
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_RECEIVED
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
@ -20,7 +21,8 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () ->
|
|||||||
const val TAG = "VulcanApiMessagesInbox"
|
const val TAG = "VulcanApiMessagesInbox"
|
||||||
}
|
}
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
init {
|
||||||
|
data.profile?.also { profile ->
|
||||||
|
|
||||||
val startDate: String = when (profile.empty) {
|
val startDate: String = when (profile.empty) {
|
||||||
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
||||||
@ -43,15 +45,17 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () ->
|
|||||||
val senderId = data.teacherList
|
val senderId = data.teacherList
|
||||||
.singleOrNull { it.loginId == senderLoginId }?.id ?: return@forEach
|
.singleOrNull { it.loginId == senderLoginId }?.id ?: return@forEach
|
||||||
|
|
||||||
val addedDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 }
|
||||||
val readDate = message.getLong("DataPrzeczytaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
?: -1
|
||||||
|
val readDate = message.getLong("DataPrzeczytaniaUnixEpoch")?.let { it * 1000 }
|
||||||
|
?: -1
|
||||||
|
|
||||||
val messageObject = Message(
|
val messageObject = Message(
|
||||||
profileId,
|
profileId,
|
||||||
id,
|
id,
|
||||||
subject,
|
subject,
|
||||||
body,
|
body,
|
||||||
Message.TYPE_RECEIVED,
|
TYPE_RECEIVED,
|
||||||
senderId,
|
senderId,
|
||||||
-1
|
-1
|
||||||
)
|
)
|
||||||
@ -72,12 +76,13 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () ->
|
|||||||
id,
|
id,
|
||||||
readDate > 0,
|
readDate > 0,
|
||||||
readDate > 0,
|
readDate > 0,
|
||||||
addedDate
|
sentDate
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
} ?: onSuccess()}
|
} ?: onSuccess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-11-5
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_MESSAGES_SENT
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_MESSAGES_SENT
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class VulcanApiMessagesSent(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VulcanApiMessagesSent"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
data.profile?.also { profile ->
|
||||||
|
val startDate: String = when (profile.empty) {
|
||||||
|
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
||||||
|
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||||
|
}
|
||||||
|
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
|
||||||
|
|
||||||
|
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_SENT, parameters = mapOf(
|
||||||
|
"DataPoczatkowa" to startDate,
|
||||||
|
"DataKoncowa" to endDate,
|
||||||
|
"LoginId" to data.studentLoginId,
|
||||||
|
"IdUczen" to data.studentId
|
||||||
|
)) { json, _ ->
|
||||||
|
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { message ->
|
||||||
|
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||||
|
val subject = message.getString("Tytul") ?: ""
|
||||||
|
val body = message.getString("Tresc") ?: ""
|
||||||
|
val readBy = message.getInt("Przeczytane") ?: 0
|
||||||
|
val unreadBy = message.getInt("Nieprzeczytane") ?: 0
|
||||||
|
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
||||||
|
|
||||||
|
val messageObject = Message(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
subject,
|
||||||
|
body,
|
||||||
|
TYPE_SENT,
|
||||||
|
-1,
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
message.getJsonArray("Adresaci")?.asJsonObjectList()
|
||||||
|
?.forEachIndexed { _, recipient ->
|
||||||
|
|
||||||
|
val recipientLoginId = recipient.getString("LoginId")
|
||||||
|
?: return@forEachIndexed
|
||||||
|
val recipientId = data.teacherList.singleOrNull { it.loginId == recipientLoginId }?.id
|
||||||
|
?: return@forEachIndexed
|
||||||
|
|
||||||
|
val readDate: Long = when (readBy) {
|
||||||
|
0 -> 0
|
||||||
|
else -> when (unreadBy) {
|
||||||
|
0 -> 1
|
||||||
|
else -> -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val messageRecipientObject = MessageRecipient(
|
||||||
|
profileId,
|
||||||
|
recipientId,
|
||||||
|
-1,
|
||||||
|
readDate,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
|
||||||
|
data.messageRecipientList.add(messageRecipientObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.messageList.add(messageObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_MESSAGE,
|
||||||
|
id,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
sentDate
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_SENT, 1 * DAY, DRAWER_ITEM_MESSAGES)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,6 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
|||||||
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonArray
|
|
||||||
|
|
||||||
class VulcanApiTemplate(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
class VulcanApiTemplate(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -15,10 +13,12 @@ class VulcanApiTemplate(override val data: DataVulcan, val onSuccess: () -> Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
/* apiGet(TAG, VULCAN_API_ENDPOINT_) { json, _ ->
|
/* data.profile?.also { profile ->
|
||||||
|
apiGet(TAG, VULCAN_API_ENDPOINT_) { json, _ ->
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_VULCAN_API_, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_VULCAN_API_, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
|
}
|
||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user