diff --git a/app/src/main/java/tech/bigfig/roma/components/conversation/ConversationsRepository.kt b/app/src/main/java/tech/bigfig/roma/components/conversation/ConversationsRepository.kt index 893300adaf..acd9351f4d 100644 --- a/app/src/main/java/tech/bigfig/roma/components/conversation/ConversationsRepository.kt +++ b/app/src/main/java/tech/bigfig/roma/components/conversation/ConversationsRepository.kt @@ -40,28 +40,33 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi, val conversations = HashMap() val conversationsRecentFirst = HashMap() var lastFetchedId = "" + val conversationList = ArrayList() - for (status in body?.reversed()!!) { - if (lastFetchedId.isBlank()) lastFetchedId = status.id - status.pleroma?.conversation_id?.let { id -> conversations[id] = status } - } + body?.let { + for (status in body.reversed()) { + if (lastFetchedId.isBlank()) lastFetchedId = status.id + status.pleroma?.conversation_id?.let { id -> conversations[id] = status } + } - for (entry in conversations.entries) { - entry.let { entry.value.createdAt.let { it1 -> conversationsRecentFirst.put(it1, entry.value) } } - } + for (entry in conversations.entries) { + entry.let { entry.value.createdAt.let { it1 -> conversationsRecentFirst.put(it1, entry.value) } } + } - val conversationList = ArrayList() + for (entry in conversationsRecentFirst.toSortedMap(reverseOrder())) { - for (entry in conversationsRecentFirst.toSortedMap(reverseOrder())) { + entry.value.pleroma?.conversation_id.let { - val convoToAdd = Conversation( - id = entry.value.pleroma?.conversation_id!!, - accounts = getAccountObjects(mastodonApi, entry.value.mentions), - lastStatus = entry.value, - unread = false - ) + entry.value.pleroma?.conversation_id?.let { it1 -> - conversationList.add(convoToAdd) + conversationList.add(Conversation( + id = it1, + accounts = getAccountObjects(mastodonApi, entry.value.mentions), + lastStatus = entry.value, + unread = false) + ) + } + } + } } return ConversationHolder(lastFetchedId, conversationList)