Split get message details and get message replay details
This commit is contained in:
parent
9176c250ca
commit
b210dcac04
11 changed files with 102 additions and 27 deletions
|
@ -20,7 +20,8 @@ import io.github.wulkanowy.sdk.scrapper.homework.Homework
|
|||
import io.github.wulkanowy.sdk.scrapper.login.LoginHelper
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Folder
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Mailbox
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Message
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageReplayDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageMeta
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Recipient
|
||||
import io.github.wulkanowy.sdk.scrapper.mobile.Device
|
||||
|
@ -346,9 +347,9 @@ class Scrapper {
|
|||
|
||||
suspend fun getDeletedMessages(mailboxKey: String? = null, lastMessageKey: Int = 0, pageSize: Int = 50): List<MessageMeta> = messages.getDeletedMessages(mailboxKey, lastMessageKey, pageSize)
|
||||
|
||||
suspend fun getMessageRecipients(globalKey: String): List<Recipient> = messages.getMessageRecipients(globalKey)
|
||||
suspend fun getMessageReplayDetails(globalKey: String): MessageReplayDetails = messages.getMessageReplayDetails(globalKey)
|
||||
|
||||
suspend fun getMessageDetails(globalKey: String): Message = messages.getMessageDetails(globalKey)
|
||||
suspend fun getMessageDetails(globalKey: String): MessageDetails = messages.getMessageDetails(globalKey)
|
||||
|
||||
suspend fun sendMessage(subject: String, content: String, recipients: List<String>, senderMailboxId: String) = messages.sendMessage(subject, content, recipients, senderMailboxId)
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.messages
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.adapter.CustomDateAdapter
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Serializable
|
||||
data class MessageDetails(
|
||||
|
||||
@SerialName("apiGlobalKey")
|
||||
val apiGlobalKey: String,
|
||||
|
||||
@SerialName("data")
|
||||
@Serializable(with = CustomDateAdapter::class)
|
||||
val date: LocalDateTime,
|
||||
|
||||
@SerialName("nadawca")
|
||||
val sender: String,
|
||||
|
||||
@SerialName("odbiorcy")
|
||||
val recipients: List<String>,
|
||||
|
||||
@SerialName("temat")
|
||||
val subject: String,
|
||||
|
||||
@SerialName("tresc")
|
||||
val content: String,
|
||||
|
||||
@SerialName("odczytana")
|
||||
val isRead: Boolean,
|
||||
|
||||
@SerialName("zalaczniki")
|
||||
val attachments: List<MessageAttachment>,
|
||||
|
||||
@SerialName("id")
|
||||
val id: Int,
|
||||
)
|
|
@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
|
|||
import java.time.LocalDateTime
|
||||
|
||||
@Serializable
|
||||
data class Message(
|
||||
data class MessageReplayDetails(
|
||||
|
||||
@SerialName("apiGlobalKey")
|
||||
val apiGlobalKey: String,
|
|
@ -1,8 +1,9 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.repository
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Mailbox
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Message
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageMeta
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageReplayDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Recipient
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.SendMessageRequest
|
||||
import io.github.wulkanowy.sdk.scrapper.normalizeRecipients
|
||||
|
@ -57,14 +58,12 @@ class MessagesRepository(private val api: MessagesService) {
|
|||
.toList()
|
||||
}
|
||||
|
||||
suspend fun getMessageRecipients(globalKey: String): List<Recipient> {
|
||||
return api.getMessageDetails(globalKey).recipients
|
||||
suspend fun getMessageReplayDetails(globalKey: String): MessageReplayDetails {
|
||||
return api.getMessageReplayDetails(globalKey)
|
||||
}
|
||||
|
||||
suspend fun getMessageDetails(globalKey: String): Message {
|
||||
return api.getMessageDetails(globalKey).let {
|
||||
it.copy(recipients = it.recipients.normalizeRecipients())
|
||||
}
|
||||
suspend fun getMessageDetails(globalKey: String): MessageDetails {
|
||||
return api.getMessageDetails(globalKey)
|
||||
}
|
||||
|
||||
suspend fun sendMessage(subject: String, content: String, recipients: List<String>, senderMailboxId: String) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.service
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Mailbox
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Message
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageReplayDetails
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageMeta
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Recipient
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.SendMessageRequest
|
||||
|
@ -57,8 +58,11 @@ interface MessagesService {
|
|||
@Query("pageSize") pageSize: Int = 50,
|
||||
): List<MessageMeta>
|
||||
|
||||
@GET("api/WiadomoscSzczegoly")
|
||||
suspend fun getMessageDetails(@Query("apiGlobalKey") globalKey: String): MessageDetails
|
||||
|
||||
@GET("api/WiadomoscOdpowiedzPrzekaz")
|
||||
suspend fun getMessageDetails(@Query("apiGlobalKey") globalKey: String): Message
|
||||
suspend fun getMessageReplayDetails(@Query("apiGlobalKey") globalKey: String): MessageReplayDetails
|
||||
|
||||
@POST("api/WiadomoscNowa")
|
||||
suspend fun sendMessage(@Body sendMessageRequest: SendMessageRequest)
|
||||
|
|
|
@ -338,8 +338,8 @@ class ScrapperRemoteTest : BaseTest() {
|
|||
val trash = runBlocking { api.getDeletedMessages() }
|
||||
assertEquals(8, trash.size)
|
||||
|
||||
val mRecipients = runBlocking { api.getMessageRecipients("uuidv4") }
|
||||
assertEquals(1, mRecipients.size)
|
||||
val replayDetails = runBlocking { api.getMessageReplayDetails("uuidv4") }
|
||||
assertEquals(1, replayDetails.recipients.size)
|
||||
|
||||
val details = runBlocking { api.getMessageDetails("asdf") }
|
||||
assertEquals(27214, details.id)
|
||||
|
|
|
@ -181,7 +181,7 @@ class MessagesTest : BaseLocalTest() {
|
|||
start(3000)
|
||||
}
|
||||
|
||||
val res = api.getMessageDetails("uuidv4")
|
||||
val res = api.getMessageReplayDetails("uuidv4")
|
||||
assertEquals(125, res.content.length)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ import io.github.wulkanowy.sdk.pojo.LuckyNumber
|
|||
import io.github.wulkanowy.sdk.pojo.Mailbox
|
||||
import io.github.wulkanowy.sdk.pojo.Message
|
||||
import io.github.wulkanowy.sdk.pojo.MessageDetails
|
||||
import io.github.wulkanowy.sdk.pojo.MessageReplayDetails
|
||||
import io.github.wulkanowy.sdk.pojo.Note
|
||||
import io.github.wulkanowy.sdk.pojo.Recipient
|
||||
import io.github.wulkanowy.sdk.pojo.School
|
||||
|
@ -516,18 +517,18 @@ class Sdk {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getMessageRecipients(messageId: String): List<Recipient> = withContext(Dispatchers.IO) {
|
||||
suspend fun getMessageReplayDetails(messageKey: String): MessageReplayDetails = withContext(Dispatchers.IO) {
|
||||
when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageRecipients(messageId).mapRecipients()
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageReplayDetails(messageKey).mapScrapperMessage()
|
||||
Mode.API -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getMessageDetails(messageId: String): MessageDetails = withContext(Dispatchers.IO) {
|
||||
suspend fun getMessageDetails(messageKey: String): MessageDetails = withContext(Dispatchers.IO) {
|
||||
when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageDetails(messageId).mapScrapperMessage()
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageDetails(messageKey).mapScrapperMessage()
|
||||
Mode.API -> {
|
||||
mobile.changeMessageStatus(messageId, "", "Widoczna")
|
||||
mobile.changeMessageStatus(messageKey, "", "Widoczna")
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@ import io.github.wulkanowy.sdk.pojo.Folder
|
|||
import io.github.wulkanowy.sdk.pojo.Message
|
||||
import io.github.wulkanowy.sdk.pojo.MessageAttachment
|
||||
import io.github.wulkanowy.sdk.pojo.MessageDetails
|
||||
import io.github.wulkanowy.sdk.pojo.MessageReplayDetails
|
||||
import io.github.wulkanowy.sdk.toLocalDateTime
|
||||
import java.time.ZoneId
|
||||
import io.github.wulkanowy.sdk.mobile.messages.Message as ApiMessage
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.Message as ScrapperMessage
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageReplayDetails as ScrapperReplayDetailsMessage
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageDetails as ScrapperDetailsMessage
|
||||
import io.github.wulkanowy.sdk.scrapper.messages.MessageMeta as ScrapperMessageMeta
|
||||
|
||||
@JvmName("mapApiMessages")
|
||||
|
@ -50,7 +52,23 @@ fun List<ScrapperMessageMeta>.mapMessages(zoneId: ZoneId, folderId: Folder) = ma
|
|||
)
|
||||
}
|
||||
|
||||
fun ScrapperMessage.mapScrapperMessage() = MessageDetails(
|
||||
fun ScrapperDetailsMessage.mapScrapperMessage() = MessageDetails(
|
||||
content = content,
|
||||
apiGlobalKey = apiGlobalKey,
|
||||
date = date,
|
||||
sender = sender,
|
||||
recipients = recipients,
|
||||
subject = subject,
|
||||
id = id,
|
||||
attachments = attachments.map {
|
||||
MessageAttachment(
|
||||
url = it.url,
|
||||
filename = it.filename
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
fun ScrapperReplayDetailsMessage.mapScrapperMessage() = MessageReplayDetails(
|
||||
content = content,
|
||||
apiGlobalKey = apiGlobalKey,
|
||||
date = date,
|
||||
|
|
|
@ -7,10 +7,8 @@ data class MessageDetails(
|
|||
val attachments: List<MessageAttachment>,
|
||||
val apiGlobalKey: String,
|
||||
val date: LocalDateTime,
|
||||
val mailboxId: String,
|
||||
val senderMailboxId: String,
|
||||
val senderMailboxName: String,
|
||||
val recipients: List<Recipient>,
|
||||
val sender: String,
|
||||
val recipients: List<String>,
|
||||
val subject: String,
|
||||
val id: Int,
|
||||
)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.github.wulkanowy.sdk.pojo
|
||||
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class MessageReplayDetails(
|
||||
val content: String,
|
||||
val attachments: List<MessageAttachment>,
|
||||
val apiGlobalKey: String,
|
||||
val date: LocalDateTime,
|
||||
val mailboxId: String,
|
||||
val senderMailboxId: String,
|
||||
val senderMailboxName: String,
|
||||
val recipients: List<Recipient>,
|
||||
val subject: String,
|
||||
val id: Int,
|
||||
)
|
Loading…
Reference in a new issue