Skip to content

Commit

Permalink
Replaced !! operators with lets to prevent NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
noln committed Jul 23, 2019
1 parent 9d7b694 commit b754315
Showing 1 changed file with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,33 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi,
val conversations = HashMap<String, Status>()
val conversationsRecentFirst = HashMap<Date, Status>()
var lastFetchedId = ""
val conversationList = ArrayList<Conversation>()

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<Conversation>()
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)
Expand Down

0 comments on commit b754315

Please sign in to comment.