From cd087113e3f76f9c5ee4b11edd8a98a3ed533e21 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 4 Feb 2026 12:27:52 -0500 Subject: [PATCH] Ensure that notification heuristics are calculated in the background. --- .../app/notifications/NotificationsSettingsViewModel.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsViewModel.kt index de58b874fc..37060b27dc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsViewModel.kt @@ -5,9 +5,12 @@ import android.net.Uri import android.os.Build import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch import org.thoughtcrime.securesms.dependencies.AppDependencies import org.thoughtcrime.securesms.keyvalue.SignalStore import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig @@ -28,7 +31,11 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer SignalStore.settings.isMessageVibrateEnabled = NotificationChannels.getInstance().messageVibrate } - store.update { getState(calculateSlowNotifications = true) } + // Calculating slow notification stuff isn't thread-safe, so we do it without to start off so we have most state populated, then fetch it in the background. + store.update { getState(calculateSlowNotifications = false) } + viewModelScope.launch(Dispatchers.IO) { + store.update { getState(calculateSlowNotifications = true) } + } } fun refresh() {