From c7c285a2c183e813a1a883ac8b38259defabcd61 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 12 Mar 2018 19:41:56 +0100 Subject: [PATCH] Improve conversation class * make it serializable * provide either first unread or last message as extract --- .../main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt b/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt index f7a2f24..d341b66 100644 --- a/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt +++ b/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt @@ -816,13 +816,17 @@ class Plaintext private constructor( } } -data class Conversation(val id: UUID, val subject: String, val messages: List) { +data class Conversation(val id: UUID, val subject: String, val messages: List<Plaintext>) : Serializable { val participants = messages .map { it.from } .filter { it.privateKey == null || it.isChan } .distinct() - val extract: String by lazy { messages.lastOrNull()?.text ?: "" } + val extract: String by lazy { + messages.firstOrNull { m -> m.labels.any { l -> l.type==Label.Type.UNREAD } }?.text + ?: messages.lastOrNull()?.text + ?: "" + } fun hasUnread() = messages.any { it.isUnread() } }