mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-10 00:50:49 +01:00
Identity - Fix issue with Realm
This commit is contained in:
parent
ab6e7a3b8a
commit
0199cf9a03
@ -43,7 +43,7 @@ internal class DefaultBulkLookupTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: BulkLookupTask.Params): List<FoundThreePid> {
|
override suspend fun execute(params: BulkLookupTask.Params): List<FoundThreePid> {
|
||||||
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
|
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
val entity = identityServiceStore.get()
|
val entity = identityServiceStore.get() ?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
val pepper = entity.hashLookupPepper
|
val pepper = entity.hashLookupPepper
|
||||||
val hashDetailResponse = if (pepper == null) {
|
val hashDetailResponse = if (pepper == null) {
|
||||||
// We need to fetch the hash details first
|
// We need to fetch the hash details first
|
||||||
|
@ -90,7 +90,7 @@ internal class DefaultIdentityService @Inject constructor(
|
|||||||
|
|
||||||
private fun notifyIdentityServerUrlChange(baseUrl: String?) {
|
private fun notifyIdentityServerUrlChange(baseUrl: String?) {
|
||||||
// This is maybe not a real change (local echo of account data we are just setting
|
// This is maybe not a real change (local echo of account data we are just setting
|
||||||
if (identityServiceStore.get().identityServerUrl == baseUrl) {
|
if (identityServiceStore.get()?.identityServerUrl == baseUrl) {
|
||||||
Timber.d("Local echo of identity server url change")
|
Timber.d("Local echo of identity server url change")
|
||||||
} else {
|
} else {
|
||||||
// Url has changed, we have to reset our store, update internal configuration and notify listeners
|
// Url has changed, we have to reset our store, update internal configuration and notify listeners
|
||||||
@ -109,7 +109,7 @@ internal class DefaultIdentityService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getCurrentIdentityServer(): String? {
|
override fun getCurrentIdentityServer(): String? {
|
||||||
return identityServiceStore.get().identityServerUrl
|
return identityServiceStore.get()?.identityServerUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun disconnect() {
|
override fun disconnect() {
|
||||||
@ -176,7 +176,7 @@ internal class DefaultIdentityService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun ensureToken() {
|
private suspend fun ensureToken() {
|
||||||
val entity = identityServiceStore.get()
|
val entity = identityServiceStore.get() ?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
val url = entity.identityServerUrl ?: throw IdentityServiceError.NoIdentityServerConfigured
|
val url = entity.identityServerUrl ?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
|
|
||||||
if (entity.token == null) {
|
if (entity.token == null) {
|
||||||
|
@ -23,5 +23,5 @@ import javax.inject.Inject
|
|||||||
internal class IdentityAccessTokenProvider @Inject constructor(
|
internal class IdentityAccessTokenProvider @Inject constructor(
|
||||||
private val identityServiceStore: IdentityServiceStore
|
private val identityServiceStore: IdentityServiceStore
|
||||||
) : AccessTokenProvider {
|
) : AccessTokenProvider {
|
||||||
override fun getToken() = identityServiceStore.get().token
|
override fun getToken() = identityServiceStore.get()?.token
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,12 @@ import io.realm.kotlin.where
|
|||||||
/**
|
/**
|
||||||
* Only one object can be stored at a time
|
* Only one object can be stored at a time
|
||||||
*/
|
*/
|
||||||
|
internal fun IdentityServerEntity.Companion.get(realm: Realm): IdentityServerEntity? {
|
||||||
|
return realm.where<IdentityServerEntity>().findFirst()
|
||||||
|
}
|
||||||
|
|
||||||
internal fun IdentityServerEntity.Companion.getOrCreate(realm: Realm): IdentityServerEntity {
|
internal fun IdentityServerEntity.Companion.getOrCreate(realm: Realm): IdentityServerEntity {
|
||||||
return realm.where<IdentityServerEntity>().findFirst() ?: realm.createObject()
|
return get(realm) ?: realm.createObject()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun IdentityServerEntity.Companion.setUrl(realm: Realm,
|
internal fun IdentityServerEntity.Companion.setUrl(realm: Realm,
|
||||||
|
@ -20,7 +20,7 @@ import im.vector.matrix.android.internal.session.identity.model.IdentityHashDeta
|
|||||||
|
|
||||||
internal interface IdentityServiceStore {
|
internal interface IdentityServiceStore {
|
||||||
|
|
||||||
fun get(): IdentityServerEntity
|
fun get(): IdentityServerEntity?
|
||||||
|
|
||||||
fun setUrl(url: String?)
|
fun setUrl(url: String?)
|
||||||
|
|
||||||
|
@ -27,27 +27,33 @@ internal class RealmIdentityServerStore @Inject constructor(
|
|||||||
private val realmConfiguration: RealmConfiguration
|
private val realmConfiguration: RealmConfiguration
|
||||||
) : IdentityServiceStore {
|
) : IdentityServiceStore {
|
||||||
|
|
||||||
override fun get(): IdentityServerEntity {
|
override fun get(): IdentityServerEntity? {
|
||||||
return Realm.getInstance(realmConfiguration).use {
|
return Realm.getInstance(realmConfiguration).use {
|
||||||
IdentityServerEntity.getOrCreate(it)
|
IdentityServerEntity.get(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUrl(url: String?) {
|
override fun setUrl(url: String?) {
|
||||||
Realm.getInstance(realmConfiguration).use {
|
Realm.getInstance(realmConfiguration).use {
|
||||||
IdentityServerEntity.setUrl(it, url)
|
it.executeTransaction { realm ->
|
||||||
|
IdentityServerEntity.setUrl(realm, url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setToken(token: String?) {
|
override fun setToken(token: String?) {
|
||||||
Realm.getInstance(realmConfiguration).use {
|
Realm.getInstance(realmConfiguration).use {
|
||||||
IdentityServerEntity.setToken(it, token)
|
it.executeTransaction { realm ->
|
||||||
|
IdentityServerEntity.setToken(realm, token)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setHashDetails(hashDetailResponse: IdentityHashDetailResponse) {
|
override fun setHashDetails(hashDetailResponse: IdentityHashDetailResponse) {
|
||||||
Realm.getInstance(realmConfiguration).use {
|
Realm.getInstance(realmConfiguration).use {
|
||||||
IdentityServerEntity.setHashDetails(it, hashDetailResponse.pepper, hashDetailResponse.algorithms)
|
it.executeTransaction { realm ->
|
||||||
|
IdentityServerEntity.setHashDetails(realm, hashDetailResponse.pepper, hashDetailResponse.algorithms)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user