Fix crash with null lastStatus in Conversations (#1042)

This commit is contained in:
Konrad Pozniak 2019-02-13 21:14:12 +01:00 committed by GitHub
parent fe1e9f4100
commit fdc66288b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View file

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

View file

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

View file

@ -20,6 +20,6 @@ import com.google.gson.annotations.SerializedName
data class Conversation( data class Conversation(
val id: String, val id: String,
val accounts: List<Account>, 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 val unread: Boolean
) )