Return recipients list instead of recipient name string
This commit is contained in:
parent
dbbe280ccb
commit
698ab58791
3 changed files with 11 additions and 20 deletions
|
@ -36,34 +36,21 @@ class MessagesRepository(private val api: MessagesService) {
|
|||
suspend fun getReceivedMessages(startDate: LocalDateTime?, endDate: LocalDateTime?): List<Message> {
|
||||
return api.getReceived(startDate.getDate(), endDate.getDate()).handleErrors().data.orEmpty()
|
||||
.sortedBy { it.date }
|
||||
.map { message ->
|
||||
message.copy(
|
||||
recipients = message.recipients?.map { it.copy(name = it.name.normalizeRecipient()) }
|
||||
)
|
||||
}
|
||||
.map { it.normalizeRecipients() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
suspend fun getSentMessages(startDate: LocalDateTime?, endDate: LocalDateTime?): List<Message> {
|
||||
return api.getSent(startDate.getDate(), endDate.getDate()).handleErrors().data.orEmpty()
|
||||
.map { message ->
|
||||
message.copy(
|
||||
messageId = message.id,
|
||||
folderId = 2,
|
||||
recipients = message.recipients?.map { it.copy(name = it.name.normalizeRecipient()) }
|
||||
)
|
||||
}
|
||||
.map { it.normalizeRecipients() }
|
||||
.sortedBy { it.date }
|
||||
.toList()
|
||||
}
|
||||
|
||||
suspend fun getDeletedMessages(startDate: LocalDateTime?, endDate: LocalDateTime?): List<Message> {
|
||||
return api.getDeleted(startDate.getDate(), endDate.getDate()).handleErrors().data.orEmpty()
|
||||
.map { message ->
|
||||
message.copy(
|
||||
recipients = message.recipients?.map { it.copy(name = it.name.normalizeRecipient()) }
|
||||
).apply { removed = true }
|
||||
}
|
||||
.map { it.normalizeRecipients() }
|
||||
.map { it.apply { removed = true } }
|
||||
.sortedBy { it.date }
|
||||
.toList()
|
||||
}
|
||||
|
@ -133,6 +120,10 @@ class MessagesRepository(private val api: MessagesService) {
|
|||
return this.substringBeforeLast("-").substringBefore(" [").substringBeforeLast(" (").trim()
|
||||
}
|
||||
|
||||
private fun Message.normalizeRecipients() = copy(
|
||||
recipients = recipients?.map { it.copy(name = it.name.normalizeRecipient()) }
|
||||
)
|
||||
|
||||
private fun LocalDateTime?.getDate(): String {
|
||||
return this?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).orEmpty()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ fun List<ApiMessage>.mapMessages(dictionaries: Dictionaries) = map {
|
|||
sender = it.senderName ?: dictionaries.employees.singleOrNull { employee -> employee.id == it.senderId }?.let { e -> "${e.name} ${e.surname}" },
|
||||
senderId = it.senderId,
|
||||
removed = it.status == "Usunieta",
|
||||
recipient = it.recipients?.joinToString(", ") { recipient -> recipient.name.normalizeRecipient() },
|
||||
recipients = it.recipients?.map { recipient -> recipient.copy(name = recipient.name.normalizeRecipient()) }?.mapFromMobileToRecipients().orEmpty(),
|
||||
readBy = it.read?.toInt(),
|
||||
messageId = it.messageId,
|
||||
folderId = when (it.folder) {
|
||||
|
@ -42,7 +42,7 @@ fun List<ScrapperMessage>.mapMessages() = map {
|
|||
folderId = it.folderId,
|
||||
messageId = it.messageId,
|
||||
readBy = it.readBy,
|
||||
recipient = it.recipients?.joinToString("; ") { it.name },
|
||||
recipients = it.recipients?.mapRecipients().orEmpty(),
|
||||
removed = it.removed,
|
||||
sender = it.sender?.name,
|
||||
senderId = it.sender?.loginId,
|
||||
|
|
|
@ -7,7 +7,7 @@ data class Message(
|
|||
val messageId: Int?,
|
||||
val sender: String?,
|
||||
val senderId: Int?,
|
||||
val recipient: String?,
|
||||
val recipients: List<Recipient>,
|
||||
val subject: String,
|
||||
val content: String?,
|
||||
val date: LocalDateTime?,
|
||||
|
|
Loading…
Reference in a new issue