-
Notifications
You must be signed in to change notification settings - Fork 859
Storing and tracking the onboarding messaging use case #5009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
84e23e1
515c8ce
6c1cbcc
0a7c421
c4ac039
f44ccd7
b91b9cb
73b80b1
bc37391
cbdeb54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,48 +14,46 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.features.onboarding.store | ||
| package im.vector.app.features.session | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.core.DataStore | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.datastore.preferences.core.edit | ||
| import androidx.datastore.preferences.core.stringPreferencesKey | ||
| import androidx.datastore.preferences.preferencesDataStore | ||
| import im.vector.app.core.extensions.removeKeysWithPrefix | ||
| import im.vector.app.features.onboarding.FtueUseCase | ||
| import kotlinx.coroutines.flow.first | ||
|
|
||
| private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "vector_onboarding") | ||
|
|
||
| /** | ||
| * Local storage for: | ||
| * - messaging use case (Enum/String) | ||
| */ | ||
| class OnboardingStore constructor( | ||
| class VectorSessionStore constructor( | ||
| private val context: Context, | ||
| private val myUserId: String | ||
| myUserId: String | ||
| ) { | ||
|
|
||
| private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "vector_session_store_$myUserId") | ||
| private val useCaseKey = stringPreferencesKey("use_case") | ||
|
|
||
| suspend fun readUseCase() = context.dataStore.data.first().let { preferences -> | ||
| preferences[myUserId.toUseCaseKey()]?.let { FtueUseCase.from(it) } | ||
| preferences[useCaseKey]?.let { FtueUseCase.from(it) } | ||
| } | ||
|
|
||
| suspend fun setUseCase(useCase: FtueUseCase) { | ||
| context.dataStore.edit { settings -> | ||
| settings[myUserId.toUseCaseKey()] = useCase.persistableValue | ||
| settings[useCaseKey] = useCase.persistableValue | ||
| } | ||
| } | ||
|
|
||
| suspend fun resetUseCase() { | ||
| context.dataStore.edit { settings -> | ||
| settings.remove(myUserId.toUseCaseKey()) | ||
| settings.remove(useCaseKey) | ||
| } | ||
| } | ||
|
|
||
| suspend fun clear() { | ||
| context.dataStore.removeKeysWithPrefix(myUserId) | ||
| context.dataStore.edit { settings -> settings.clear() } | ||
| } | ||
|
|
||
| private fun String.toUseCaseKey() = stringPreferencesKey("$this-use_case") | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class could be simplified with: class OnboardingStore(
private val context: Context,
myUserId: String
) {
private val useCasePreferences = stringPreferencesKey("$myUserId-use_case")
suspend fun readUseCase() = context.dataStore.data.first().let { preferences ->
preferences[useCasePreferences]?.let { FtueUseCase.from(it) }
}
suspend fun setUseCase(useCase: FtueUseCase) {
context.dataStore.edit { settings ->
settings[useCasePreferences] = useCase.persistableValue
}
}
suspend fun resetUseCase() {
context.dataStore.edit { settings ->
settings.remove(useCasePreferences)
}
}
suspend fun clear() {
resetUseCase()
}
}and I am also wondering if we could make it more generic, so its goal will be to store any data app side related to the session. I have in mind the storage of a client secret for matrix-org/sygnal#70. The class name could be something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good to me 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. went with |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if directly using the
userIdmay lead to some trouble: special chars - low risk, length - higher risk. Maybe using a hash of it would be better.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good point, I keep forgetting that user-id is actually a matrix id rather than a uuid, will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. "Matrix Id" is not really a specific concept, but it is sometimes used for user ids. https://spec.matrix.org/v1.1/appendices/#identifier-grammar is an interesting reading on the subject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cbdeb54