Skip to content

Commit cd08711

Browse files
Ensure that notification heuristics are calculated in the background.
1 parent 36b6122 commit cd08711

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsViewModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import android.net.Uri
55
import android.os.Build
66
import androidx.lifecycle.ViewModel
77
import androidx.lifecycle.ViewModelProvider
8+
import androidx.lifecycle.viewModelScope
9+
import kotlinx.coroutines.Dispatchers
810
import kotlinx.coroutines.flow.MutableStateFlow
911
import kotlinx.coroutines.flow.StateFlow
1012
import kotlinx.coroutines.flow.update
13+
import kotlinx.coroutines.launch
1114
import org.thoughtcrime.securesms.dependencies.AppDependencies
1215
import org.thoughtcrime.securesms.keyvalue.SignalStore
1316
import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig
@@ -28,7 +31,11 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
2831
SignalStore.settings.isMessageVibrateEnabled = NotificationChannels.getInstance().messageVibrate
2932
}
3033

31-
store.update { getState(calculateSlowNotifications = true) }
34+
// 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.
35+
store.update { getState(calculateSlowNotifications = false) }
36+
viewModelScope.launch(Dispatchers.IO) {
37+
store.update { getState(calculateSlowNotifications = true) }
38+
}
3239
}
3340

3441
fun refresh() {

0 commit comments

Comments
 (0)