Ensure that notification heuristics are calculated in the background.

This commit is contained in:
Greyson Parrelli
2026-02-04 12:27:52 -05:00
parent 36b6122b0f
commit cd087113e3

View File

@@ -5,9 +5,12 @@ import android.net.Uri
import android.os.Build import android.os.Build
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.thoughtcrime.securesms.dependencies.AppDependencies import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.keyvalue.SignalStore import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig
@@ -28,7 +31,11 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
SignalStore.settings.isMessageVibrateEnabled = NotificationChannels.getInstance().messageVibrate 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() { fun refresh() {