Skip to content

Commit

Permalink
fix #90 don't dismiss failed message action
Browse files Browse the repository at this point in the history
Signed-off-by: Basler182 <showdialog@web.de>
  • Loading branch information
Basler182 committed Oct 27, 2024
1 parent 0148cf3 commit 0a43a53
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import edu.stanford.spezi.core.logging.speziLogger
import edu.stanford.spezi.core.navigation.Navigator
import edu.stanford.spezi.core.notification.notifier.FirebaseMessage
import edu.stanford.spezi.core.notification.notifier.FirebaseMessage.Companion.FIREBASE_MESSAGE_KEY
import edu.stanford.spezi.core.utils.MessageNotifier
import edu.stanford.spezi.modules.education.EducationNavigationEvent
import edu.stanford.spezi.modules.education.videos.Video
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -45,6 +47,7 @@ class BluetoothViewModel @Inject internal constructor(
private val navigator: Navigator,
private val engageEducationRepository: EngageEducationRepository,
private val healthSummaryService: HealthSummaryService,
private val messageNotifier: MessageNotifier,
@ApplicationContext private val context: Context,
) : ViewModel() {
private val logger by speziLogger()
Expand Down Expand Up @@ -245,7 +248,12 @@ class BluetoothViewModel @Inject internal constructor(

is MessagesAction.VideoSectionAction -> {
viewModelScope.launch {
handleVideoSectionAction(messagesAction)
handleVideoSectionAction(messagesAction).onFailure {
messageNotifier.notify(
message = "Error while handling message action."
)
return@launch // on failure, we don't want to dismiss the message
}
}
}
}
Expand All @@ -254,16 +262,14 @@ class BluetoothViewModel @Inject internal constructor(
}
}

private suspend fun handleVideoSectionAction(messageAction: MessagesAction.VideoSectionAction) {
engageEducationRepository.getVideoBySectionAndVideoId(
private suspend fun handleVideoSectionAction(messageAction: MessagesAction.VideoSectionAction): Result<Video> {
return engageEducationRepository.getVideoBySectionAndVideoId(
messageAction.videoSectionVideo.videoSectionId,
messageAction.videoSectionVideo.videoId
).getOrNull()?.let { video ->
navigator.navigateTo(
EducationNavigationEvent.VideoSectionClicked(
video = video
)
)
).onSuccess { video ->
navigator.navigateTo(EducationNavigationEvent.VideoSectionClicked(video))
}.onFailure {
logger.e(it) { "Error while getting video by section and video id" }
}
}

Expand Down

0 comments on commit 0a43a53

Please sign in to comment.