@@ -40,28 +40,33 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi,
4040 val conversations = HashMap <String , Status >()
4141 val conversationsRecentFirst = HashMap <Date , Status >()
4242 var lastFetchedId = " "
43+ val conversationList = ArrayList <Conversation >()
4344
44- for (status in body?.reversed()!! ) {
45- if (lastFetchedId.isBlank()) lastFetchedId = status.id
46- status.pleroma?.conversation_id?.let { id -> conversations[id] = status }
47- }
45+ body?.let {
46+ for (status in body.reversed()) {
47+ if (lastFetchedId.isBlank()) lastFetchedId = status.id
48+ status.pleroma?.conversation_id?.let { id -> conversations[id] = status }
49+ }
4850
49- for (entry in conversations.entries) {
50- entry.let { entry.value.createdAt.let { it1 -> conversationsRecentFirst.put(it1, entry.value) } }
51- }
51+ for (entry in conversations.entries) {
52+ entry.let { entry.value.createdAt.let { it1 -> conversationsRecentFirst.put(it1, entry.value) } }
53+ }
5254
53- val conversationList = ArrayList < Conversation >()
55+ for (entry in conversationsRecentFirst.toSortedMap(reverseOrder())) {
5456
55- for (entry in conversationsRecentFirst.toSortedMap(reverseOrder())) {
57+ entry.value.pleroma?.conversation_id. let {
5658
57- val convoToAdd = Conversation (
58- id = entry.value.pleroma?.conversation_id!! ,
59- accounts = getAccountObjects(mastodonApi, entry.value.mentions),
60- lastStatus = entry.value,
61- unread = false
62- )
59+ entry.value.pleroma?.conversation_id?.let { it1 ->
6360
64- conversationList.add(convoToAdd)
61+ conversationList.add(Conversation (
62+ id = it1,
63+ accounts = getAccountObjects(mastodonApi, entry.value.mentions),
64+ lastStatus = entry.value,
65+ unread = false )
66+ )
67+ }
68+ }
69+ }
6570 }
6671
6772 return ConversationHolder (lastFetchedId, conversationList)
0 commit comments