Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianJaeger committed Oct 4, 2024
1 parent e91d6f4 commit 7e7048e
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringSetPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext

private val KEY_DISMISSED_MESSAGE_IDS = stringSetPreferencesKey("isDataSharingEnabled")

internal class OnLaunchDataStore(context: Context) {

private val dataStore: DataStore<Preferences> = context.onLaunchDataStore

suspend fun getDismissedMessageIds(): Set<Int> = withContext(Dispatchers.IO) {
dataStore.data.first().let {
it[KEY_DISMISSED_MESSAGE_IDS]?.map(String::toInt)?.toSet() ?: emptySet()
}
suspend fun getDismissedMessageIds(): Set<Int> = dataStore.data.first().let {
it[KEY_DISMISSED_MESSAGE_IDS]?.map(String::toInt)?.toSet() ?: emptySet()
}

suspend fun addDismissedMessageId(messageId: Int) = withContext(Dispatchers.IO) {
dataStore.edit {
it[KEY_DISMISSED_MESSAGE_IDS] =
(it[KEY_DISMISSED_MESSAGE_IDS] ?: emptySet()) + messageId.toString()
}
suspend fun addDismissedMessageId(messageId: Int) = dataStore.edit {
it[KEY_DISMISSED_MESSAGE_IDS] =
(it[KEY_DISMISSED_MESSAGE_IDS] ?: emptySet()) + messageId.toString()
}
}

Expand Down

0 comments on commit 7e7048e

Please sign in to comment.