Add more fields to message details and new message

This commit is contained in:
Mikołaj Pich 2022-08-15 16:27:54 +02:00
parent 1825a9a60d
commit ceafa0f411
7 changed files with 37 additions and 18 deletions

View file

@ -345,11 +345,11 @@ class Scrapper {
suspend fun getDeletedMessages(lastMessageKey: Int = 0, pageSize: Int = 50): List<MessageMeta> = messages.getDeletedMessages(lastMessageKey, pageSize)
suspend fun getMessageRecipients(messageId: Int, loginId: Int = 0): List<Recipient> = messages.getMessageRecipients(messageId, loginId)
suspend fun getMessageRecipients(globalKey: String): List<Recipient> = messages.getMessageRecipients(globalKey)
suspend fun getMessageDetails(globalKey: String): Message = messages.getMessageDetails(globalKey)
suspend fun sendMessage(subject: String, content: String, recipients: List<String>) = messages.sendMessage(subject, content, recipients)
suspend fun sendMessage(subject: String, content: String, recipients: List<String>, senderMailboxId: String) = messages.sendMessage(subject, content, recipients, senderMailboxId)
suspend fun deleteMessages(messagesToDelete: List<String>) = messages.deleteMessages(messagesToDelete)

View file

@ -45,19 +45,19 @@ class MessagesRepository(private val api: MessagesService) {
.toList()
}
suspend fun getMessageRecipients(messageId: Int, loginId: Int): List<Recipient> {
return emptyList()
suspend fun getMessageRecipients(globalKey: String): List<Recipient> {
return api.getMessageDetails(globalKey).recipients
}
suspend fun getMessageDetails(globalKey: String): Message {
return api.getMessageDetails(globalKey)
}
suspend fun sendMessage(subject: String, content: String, recipients: List<String>) {
suspend fun sendMessage(subject: String, content: String, recipients: List<String>, senderMailboxId: String) {
val body = SendMessageRequest(
globalKey = "",
threadGlobalKey = "",
senderMailboxGlobalKey = "",
globalKey = "00000000-0000-0000-0000-000000000000",
threadGlobalKey = "00000000-0000-0000-0000-000000000000",
senderMailboxGlobalKey = senderMailboxId,
recipientsMailboxGlobalKeys = recipients,
subject = subject,
content = content,

View file

@ -36,7 +36,7 @@ interface MessagesService {
@Query("pageSize") pageSize: Int = 50,
): List<MessageMeta>
@POST("api/WiadomoscOdpowiedzPrzekaz")
@GET("api/WiadomoscOdpowiedzPrzekaz")
suspend fun getMessageDetails(@Query("apiGlobalKey") globalKey: String): Message
@POST("api/WiadomoscNowa")

View file

@ -338,7 +338,7 @@ class ScrapperRemoteTest : BaseTest() {
val trash = runBlocking { api.getDeletedMessages() }
assertEquals(8, trash.size)
val mRecipients = runBlocking { api.getMessageRecipients(0) }
val mRecipients = runBlocking { api.getMessageRecipients("uuidv4") }
assertEquals(1, mRecipients.size)
val details = runBlocking { api.getMessageDetails("asdf") }
@ -352,6 +352,7 @@ class ScrapperRemoteTest : BaseTest() {
subject = "Temat wiadomości",
content = "Treść",
recipients = listOf("asdf"),
senderMailboxId = "uuidv4"
)
}
}

View file

@ -516,9 +516,9 @@ class Sdk {
}
}
suspend fun getMessageRecipients(messageId: Int, senderId: Int): List<Recipient> = withContext(Dispatchers.IO) {
suspend fun getMessageRecipients(messageId: String): List<Recipient> = withContext(Dispatchers.IO) {
when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageRecipients(messageId, senderId).mapRecipients()
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageRecipients(messageId).mapRecipients()
Mode.API -> TODO()
}
}
@ -528,14 +528,14 @@ class Sdk {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getMessageDetails(messageId).mapScrapperMessage()
Mode.API -> {
mobile.changeMessageStatus(messageId, "", "Widoczna")
MessageDetails("", emptyList())
TODO()
}
}
}
suspend fun sendMessage(subject: String, content: String, recipients: List<Recipient>) = withContext(Dispatchers.IO) {
suspend fun sendMessage(subject: String, content: String, recipients: List<Recipient>, mailboxId: String) = withContext(Dispatchers.IO) {
when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.sendMessage(subject, content, recipients.map { it.mailboxGlobalKey })
Mode.HYBRID, Mode.SCRAPPER -> scrapper.sendMessage(subject, content, recipients.map { it.mailboxGlobalKey }, mailboxId)
Mode.API -> mobile.sendMessage(subject, content, recipients.mapFromRecipientsToMobile())
}
}

View file

@ -56,17 +56,25 @@ fun List<ScrapperMessageMeta>.mapMessages(zoneId: ZoneId, folderId: Folder) = ma
recipients = emptyList(),
sender = null,
correspondents = it.correspondents,
unread = it.isRead,
unread = !it.isRead,
hasAttachments = it.isAttachments,
)
}
fun ScrapperMessage.mapScrapperMessage() = MessageDetails(
content = content,
apiGlobalKey = apiGlobalKey,
date = date,
mailboxId = mailboxId,
senderMailboxId = senderMailboxId,
senderMailboxName = senderMailboxName,
recipients = recipients.mapRecipients(),
subject = subject,
id = id,
attachments = attachments.map {
MessageAttachment(
url = it.url,
filename = it.filename
)
}
},
)

View file

@ -1,6 +1,16 @@
package io.github.wulkanowy.sdk.pojo
import java.time.LocalDateTime
data class MessageDetails(
val content: String,
val attachments: List<MessageAttachment>
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,
)