From b892560ab5474ccbf43d6e31f7ce61c612645cb5 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 18 Nov 2024 13:05:06 +0100 Subject: [PATCH] fix: crash when trying to get first topic in list (#407) --- .../presentation/threads/DiscussionAddThreadViewModel.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 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 8a3a2417d..b16b9f300 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() {