Fix crash with null lastStatus in Conversations (#1042)

main
Konrad Pozniak 6 years ago committed by GitHub
parent 26fb9e3ccf
commit fcc20d656c
  1. 2
      app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt
  2. 7
      app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsRepository.kt
  3. 2
      app/src/main/java/com/keylesspalace/tusky/entity/Conversation.kt

@ -182,5 +182,5 @@ fun Conversation.toEntity(accountId: Long) =
id,
accounts.map { it.toEntity() },
unread,
lastStatus.toEntity()
lastStatus!!.toEntity()
)

@ -103,8 +103,9 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi,
}
private fun insertResultIntoDb(accountId: Long, result: List<Conversation>?) {
result?.let { conversations ->
db.conversationDao().insert(conversations.map { it.toEntity(accountId) })
}
result?.filter { it.lastStatus != null }
?.map{ it.toEntity(accountId) }
?.let { db.conversationDao().insert(it) }
}
}

@ -20,6 +20,6 @@ import com.google.gson.annotations.SerializedName
data class Conversation(
val id: String,
val accounts: List<Account>,
@SerializedName("last_status") val lastStatus: Status,
@SerializedName("last_status") val lastStatus: Status?, // should never be null, but apparently its possible https://github.com/tuskyapp/Tusky/issues/1038
val unread: Boolean
)
Loading…
Cancel
Save