forked from github/szkolny
[API/Idziennik] Add getting message.
This commit is contained in:
parent
35d88f8c78
commit
a626427788
@ -69,6 +69,7 @@ const val IDZIENNIK_WEB_NOTICES = "mod_panelRodzica/uwagi/WS_uwagiUcznia.asmx/po
|
|||||||
const val IDZIENNIK_WEB_ATTENDANCE = "mod_panelRodzica/obecnosci/WS_obecnosciUcznia.asmx/pobierzObecnosciUcznia"
|
const val IDZIENNIK_WEB_ATTENDANCE = "mod_panelRodzica/obecnosci/WS_obecnosciUcznia.asmx/pobierzObecnosciUcznia"
|
||||||
const val IDZIENNIK_WEB_ANNOUNCEMENTS = "mod_panelRodzica/tabOgl/WS_tablicaOgloszen.asmx/GetOgloszenia"
|
const val IDZIENNIK_WEB_ANNOUNCEMENTS = "mod_panelRodzica/tabOgl/WS_tablicaOgloszen.asmx/GetOgloszenia"
|
||||||
const val IDZIENNIK_WEB_MESSAGES_LIST = "mod_komunikator/WS_wiadomosci.asmx/PobierzListeWiadomosci"
|
const val IDZIENNIK_WEB_MESSAGES_LIST = "mod_komunikator/WS_wiadomosci.asmx/PobierzListeWiadomosci"
|
||||||
|
const val IDZIENNIK_WEB_GET_MESSAGE = "mod_komunikator/WS_wiadomosci.asmx/PobierzWiadomosc"
|
||||||
|
|
||||||
val IDZIENNIK_API_USER_AGENT = SYSTEM_USER_AGENT
|
val IDZIENNIK_API_USER_AGENT = SYSTEM_USER_AGENT
|
||||||
const val IDZIENNIK_API_URL = "https://iuczniowie.progman.pl/idziennik/api"
|
const val IDZIENNIK_API_URL = "https://iuczniowie.progman.pl/idziennik/api"
|
||||||
|
@ -14,7 +14,7 @@ import pl.szczodrzynski.edziennik.get
|
|||||||
|
|
||||||
class EdudziennikWebGetAnnouncement(
|
class EdudziennikWebGetAnnouncement(
|
||||||
override val data: DataEdudziennik,
|
override val data: DataEdudziennik,
|
||||||
announcement: AnnouncementFull,
|
private val announcement: AnnouncementFull,
|
||||||
val onSuccess: () -> Unit
|
val onSuccess: () -> Unit
|
||||||
) : EdudziennikWeb(data) {
|
) : EdudziennikWeb(data) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -8,8 +8,10 @@ import com.google.gson.JsonObject
|
|||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.data.api.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
import pl.szczodrzynski.edziennik.data.api.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikData
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikData
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebGetMessage
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.firstlogin.IdziennikFirstLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.firstlogin.IdziennikFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLogin
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLoginWeb
|
||||||
import pl.szczodrzynski.edziennik.data.api.idziennikLoginMethods
|
import pl.szczodrzynski.edziennik.data.api.idziennikLoginMethods
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
@ -65,7 +67,11 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getMessage(message: MessageFull) {
|
override fun getMessage(message: MessageFull) {
|
||||||
|
IdziennikLoginWeb(data) {
|
||||||
|
IdziennikWebGetMessage(data, message) {
|
||||||
|
completed()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun markAllAnnouncementsAsRead() {
|
override fun markAllAnnouncementsAsRead() {
|
||||||
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-28
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_MESSAGE
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_RECEIVED
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipientFull
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class IdziennikWebGetMessage(
|
||||||
|
override val data: DataIdziennik,
|
||||||
|
private val message: MessageFull,
|
||||||
|
val onSuccess: () -> Unit
|
||||||
|
) : IdziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "IdziennikWebGetMessage"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.profile?.also { profile ->
|
||||||
|
val metaPattern = "\\[META:([A-z0-9]+);([0-9-]+)]".toRegex()
|
||||||
|
val meta = metaPattern.find(message.body!!)
|
||||||
|
val messageIdString = meta?.get(1) ?: ""
|
||||||
|
|
||||||
|
webApiGet(TAG, IDZIENNIK_WEB_GET_MESSAGE, parameters = mapOf(
|
||||||
|
"idWiadomosci" to messageIdString,
|
||||||
|
"typWiadomosci" to if (message.type == TYPE_SENT) 1 else 0
|
||||||
|
)) { json ->
|
||||||
|
json.getJsonObject("d")?.getJsonObject("Wiadomosc")?.also {
|
||||||
|
val id = it.getLong("_recordId")
|
||||||
|
message.body = message.body?.replace(metaPattern, "[META:$messageIdString;$id]")
|
||||||
|
|
||||||
|
message.clearAttachments()
|
||||||
|
it.getJsonArray("ListaZal")?.asJsonObjectList()?.forEach { attachment ->
|
||||||
|
message.addAttachment(
|
||||||
|
attachment.getLong("Id") ?: return@forEach,
|
||||||
|
attachment.getString("Nazwa") ?: return@forEach,
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
message.recipients?.clear()
|
||||||
|
when (message.type) {
|
||||||
|
TYPE_RECEIVED -> {
|
||||||
|
val recipientObject = MessageRecipientFull(profileId, -1, message.id)
|
||||||
|
|
||||||
|
val readDateString = it.getString("DataOdczytania")
|
||||||
|
recipientObject.readDate = if (readDateString.isNullOrBlank()) System.currentTimeMillis()
|
||||||
|
else Date.fromIso(readDateString)
|
||||||
|
|
||||||
|
recipientObject.fullName = profile.accountNameLong ?: profile.studentNameLong
|
||||||
|
|
||||||
|
data.messageRecipientList.add(recipientObject)
|
||||||
|
message.addRecipient(recipientObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPE_SENT -> {
|
||||||
|
it.getJsonArray("ListaOdbiorcow")?.asJsonObjectList()?.forEach { recipient ->
|
||||||
|
val recipientName = recipient.getString("NazwaOdbiorcy") ?: return@forEach
|
||||||
|
val teacher = data.getTeacherByLastFirst(recipientName)
|
||||||
|
|
||||||
|
val recipientObject = MessageRecipientFull(profileId, teacher.id, message.id)
|
||||||
|
|
||||||
|
recipientObject.readDate = recipient.getLong("Status") ?: return@forEach
|
||||||
|
recipientObject.fullName = teacher.fullName
|
||||||
|
|
||||||
|
data.messageRecipientList.add(recipientObject)
|
||||||
|
message.addRecipient(recipientObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!message.seen) {
|
||||||
|
message.seen = true
|
||||||
|
|
||||||
|
data.setSeenMetadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_MESSAGE,
|
||||||
|
message.id,
|
||||||
|
message.seen,
|
||||||
|
message.notified,
|
||||||
|
message.addedDate
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||||
|
|
||||||
|
data.messageList.add(message)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: onSuccess() }
|
||||||
|
}
|
@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
|||||||
|
|
||||||
class LibrusApiAnnouncementMarkAsRead(
|
class LibrusApiAnnouncementMarkAsRead(
|
||||||
override val data: DataLibrus,
|
override val data: DataLibrus,
|
||||||
announcement: AnnouncementFull,
|
private val announcement: AnnouncementFull,
|
||||||
val onSuccess: () -> Unit
|
val onSuccess: () -> Unit
|
||||||
) : LibrusApi(data) {
|
) : LibrusApi(data) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -28,18 +28,16 @@ import kotlinx.coroutines.*
|
|||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.MainActivity
|
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_FINISHED
|
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_FINISHED
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_PROGRESS
|
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_PROGRESS
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.task.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.task.EdziennikTask
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_IUCZNIOWIE
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.MessageFragmentBinding
|
import pl.szczodrzynski.edziennik.databinding.MessageFragmentBinding
|
||||||
import pl.szczodrzynski.edziennik.onClick
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Anim
|
import pl.szczodrzynski.edziennik.utils.Anim
|
||||||
import pl.szczodrzynski.edziennik.utils.Themes
|
import pl.szczodrzynski.edziennik.utils.Themes
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
@ -136,15 +134,19 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var readByAll = true
|
if (app.profile.loginStoreType == LOGIN_TYPE_IUCZNIOWIE) {
|
||||||
message.recipients?.forEach { recipient ->
|
val meta = "\\[META:([A-z0-9]+);([0-9-]+)]".toRegex().find(message.body!!)
|
||||||
if (recipient.id == -1L)
|
val messageIdBefore = meta?.get(2)?.toLong() ?: -1
|
||||||
recipient.fullName = app.profile.accountNameLong ?: app.profile.studentNameLong
|
|
||||||
if (message.type == TYPE_SENT && recipient.readDate < 1)
|
if (messageIdBefore == -1L) {
|
||||||
readByAll = false
|
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if a sent msg is not read by everyone, download it again to check the read status
|
// if a sent msg is not read by everyone, download it again to check the read status
|
||||||
if (!readByAll) {
|
if (!checkRecipients()) {
|
||||||
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -152,6 +154,16 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
showMessage()
|
showMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkRecipients(): Boolean {
|
||||||
|
message.recipients?.forEach { recipient ->
|
||||||
|
if (recipient.id == -1L)
|
||||||
|
recipient.fullName = app.profile.accountNameLong ?: app.profile.studentNameLong
|
||||||
|
if (message.type == TYPE_SENT && recipient.readDate < 1)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
private fun showMessage() {
|
private fun showMessage() {
|
||||||
b.body.text = MessagesUtils.htmlToSpannable(message.body ?: "")
|
b.body.text = MessagesUtils.htmlToSpannable(message.body ?: "")
|
||||||
b.date.text = getString(R.string.messages_date_time_format, Date.fromMillis(message.addedDate).formattedStringShort, Time.fromMillis(message.addedDate).stringHM)
|
b.date.text = getString(R.string.messages_date_time_format, Date.fromMillis(message.addedDate).formattedStringShort, Time.fromMillis(message.addedDate).stringHM)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user