Add realName to Recipient

This commit is contained in:
Mikołaj Pich 2019-02-22 23:12:15 +01:00
parent 18d8e68001
commit 46f09bdf34
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
3 changed files with 9 additions and 4 deletions

View file

@ -8,7 +8,7 @@ data class Recipient(
val id: String,
@SerializedName("Nazwa")
val name: String,
val realName: String,
@SerializedName("IdLogin")
val loginId: Int,
@ -21,4 +21,8 @@ data class Recipient(
@SerializedName("Hash")
val hash: String
)
) {
@Transient
var name: String = ""
}

View file

@ -33,7 +33,7 @@ class MessagesRepository(private val api: MessagesService) {
// invalid unit id produced error
if (unit == 0) return@flatMap Single.just(emptyList<Recipient>())
api.getRecipients(unit, role).map { it.data }.map { list ->
list.map { it.copy(name = it.name.normalizeRecipient()) }.apply {
list.map { it.copy().apply { name = it.realName.normalizeRecipient() } }.apply {
recipients = this
}
}
@ -112,7 +112,7 @@ class MessagesRepository(private val api: MessagesService) {
recipients.filter { recipient ->
origin == recipient.name
}.ifEmpty {
listOf(Recipient("0", origin, 0, 0, 2, "unknown"))
listOf(Recipient("0", "", 0, 0, 2, "unknown").apply { name = origin })
}
}.flatten()
}

View file

@ -27,6 +27,7 @@ class MessagesTest : BaseLocalTest() {
recipients[0].run {
assertEquals("18rPracownik", id)
assertEquals("Tracz Janusz", name)
assertEquals("Tracz Janusz [TJ] - pracownik (Fake123456)", realName)
assertEquals(18, loginId)
assertEquals(6, reportingUnitId)
assertEquals(2, role)