From fcaf563eb19bd6c5e4448aae4e09a749d745e2fa Mon Sep 17 00:00:00 2001 From: droid Date: Thu, 14 Nov 2024 16:29:54 +0100 Subject: [PATCH] fix: crash when trying to get first topic in list --- .../presentation/threads/DiscussionAddThreadViewModel.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/discussion/src/main/java/org/openedx/discussion/presentation/threads/DiscussionAddThreadViewModel.kt b/discussion/src/main/java/org/openedx/discussion/presentation/threads/DiscussionAddThreadViewModel.kt index 3ff75bd9b..d17837747 100644 --- a/discussion/src/main/java/org/openedx/discussion/presentation/threads/DiscussionAddThreadViewModel.kt +++ b/discussion/src/main/java/org/openedx/discussion/presentation/threads/DiscussionAddThreadViewModel.kt @@ -65,9 +65,8 @@ class DiscussionAddThreadViewModel( } fun getHandledTopicById(topicId: String): Pair { - return getHandledTopics().find{ - it.second == topicId - } ?: getHandledTopics()[0] + val topics = getHandledTopics() + return topics.find { it.second == topicId } ?: topics.firstOrNull() ?: Pair("", "") } fun sendThreadAdded() { @@ -76,4 +75,4 @@ class DiscussionAddThreadViewModel( } } -} \ No newline at end of file +}