Fully normalize all recipient strings

This commit is contained in:
Mikołaj Pich 2019-03-12 00:31:55 +01:00
parent 3dd096cba6
commit a8d05df1ab
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
2 changed files with 3 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class MessagesRepository(private val api: MessagesService) {
fun getRecipients(unitId: Int, role: Int = 2): Single<List<Recipient>> {
return api.getRecipients(unitId, role).map { it.data }.map { res ->
res.map { it.copy(shortName = it.name.normalizeRecipient().substringBeforeLast(" (")) }
res.map { it.copy(shortName = it.name.normalizeRecipient()) }
}
}
@ -88,7 +88,7 @@ class MessagesRepository(private val api: MessagesService) {
}
private fun String.normalizeRecipient(): String {
return this.substringBeforeLast("-").substringBefore(" [").trim()
return this.substringBeforeLast("-").substringBefore(" [").substringBeforeLast(" (").trim()
}
private fun getDate(date: LocalDateTime?): String {

View file

@ -105,7 +105,7 @@ class MessagesTest : BaseLocalTest() {
server.start(3000)
api.getSentMessages(null, null).blockingGet()[5].run {
assertEquals("Tracz Antoni (TA); Kowalska Joanna", recipient)
assertEquals("Tracz Antoni; Kowalska Joanna", recipient)
}
}