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

View file

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

View file

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