Add SentMessage mapper

This commit is contained in:
Mikołaj Pich 2019-10-01 01:23:50 +02:00
parent a7f8b4074b
commit 9ecd9d95a6
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
4 changed files with 47 additions and 6 deletions

View file

@ -3,7 +3,6 @@ package io.github.wulkanowy.sdk
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.api.attendance.Absent
import io.github.wulkanowy.api.messages.Folder
import io.github.wulkanowy.api.messages.SentMessage
import io.github.wulkanowy.api.resettableLazy
import io.github.wulkanowy.api.resettableManager
import io.github.wulkanowy.sdk.attendance.mapAttendance
@ -16,14 +15,13 @@ import io.github.wulkanowy.sdk.grades.mapGrades
import io.github.wulkanowy.sdk.grades.mapGradesSummary
import io.github.wulkanowy.sdk.homepage.mapLuckyNumbers
import io.github.wulkanowy.sdk.homework.mapHomework
import io.github.wulkanowy.sdk.messages.mapFromRecipients
import io.github.wulkanowy.sdk.messages.mapRecipients
import io.github.wulkanowy.sdk.messages.mapMessages
import io.github.wulkanowy.sdk.messages.mapReportingUnits
import io.github.wulkanowy.sdk.messages.*
import io.github.wulkanowy.sdk.mobile.mapDevices
import io.github.wulkanowy.sdk.mobile.mapToken
import io.github.wulkanowy.sdk.notes.mapNotes
import io.github.wulkanowy.sdk.pojo.*
import io.github.wulkanowy.sdk.pojo.Message
import io.github.wulkanowy.sdk.pojo.Recipient
import io.github.wulkanowy.sdk.register.mapSemesters
import io.github.wulkanowy.sdk.register.mapStudents
import io.github.wulkanowy.sdk.repository.RegisterRepository
@ -461,7 +459,7 @@ class Sdk {
fun sendMessage(subject: String, content: String, recipients: List<Recipient>): Single<SentMessage> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.sendMessage(subject, content, recipients.mapFromRecipients())
Mode.HYBRID, Mode.SCRAPPER -> scrapper.sendMessage(subject, content, recipients.mapFromRecipients()).map { it.mapSentMessage() }
Mode.API -> TODO()
}
}

View file

@ -0,0 +1,23 @@
package io.github.wulkanowy.sdk.messages
import io.github.wulkanowy.sdk.pojo.Sender
import io.github.wulkanowy.sdk.pojo.SentMessage
import io.github.wulkanowy.api.messages.SentMessage as ScrapperSentMessage
fun ScrapperSentMessage.mapSentMessage(): SentMessage {
return SentMessage(
recipients = recipients.mapRecipients(),
id = id,
content = content,
isWelcomeMessage = isWelcomeMessage,
sender = Sender(
id = sender.id,
role = sender.role,
reportingUnitId = sender.reportingUnitId,
name = sender.name,
loginId = sender.loginId,
hash = sender.hash
),
subject = subject
)
}

View file

@ -0,0 +1,10 @@
package io.github.wulkanowy.sdk.pojo
data class Sender(
val id: String?,
val name: String?,
val loginId: Int?,
val reportingUnitId: Int?,
val role: Int?,
val hash: String?
)

View file

@ -0,0 +1,10 @@
package io.github.wulkanowy.sdk.pojo
data class SentMessage(
val recipients: List<Recipient>,
val subject: String,
val content: String,
val sender: Sender,
val isWelcomeMessage: Boolean,
val id: Int
)