mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Use Realm.use { }
This commit is contained in:
parent
e532d97ec1
commit
0c4e0890b1
1 changed files with 21 additions and 24 deletions
|
@ -30,36 +30,33 @@ internal class RealmSessionParamsStore @Inject constructor(private val mapper: S
|
||||||
) : SessionParamsStore {
|
) : SessionParamsStore {
|
||||||
|
|
||||||
override fun getLast(): SessionParams? {
|
override fun getLast(): SessionParams? {
|
||||||
val realm = Realm.getInstance(realmConfiguration)
|
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
val sessionParams = realm
|
realm
|
||||||
.where(SessionParamsEntity::class.java)
|
.where(SessionParamsEntity::class.java)
|
||||||
.findAll()
|
.findAll()
|
||||||
.map { mapper.map(it) }
|
.map { mapper.map(it) }
|
||||||
.lastOrNull()
|
.lastOrNull()
|
||||||
realm.close()
|
}
|
||||||
return sessionParams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(userId: String): SessionParams? {
|
override fun get(userId: String): SessionParams? {
|
||||||
val realm = Realm.getInstance(realmConfiguration)
|
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
val sessionParams = realm
|
realm
|
||||||
.where(SessionParamsEntity::class.java)
|
.where(SessionParamsEntity::class.java)
|
||||||
.equalTo(SessionParamsEntityFields.USER_ID, userId)
|
.equalTo(SessionParamsEntityFields.USER_ID, userId)
|
||||||
.findAll()
|
.findAll()
|
||||||
.map { mapper.map(it) }
|
.map { mapper.map(it) }
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
realm.close()
|
}
|
||||||
return sessionParams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAll(): List<SessionParams> {
|
override fun getAll(): List<SessionParams> {
|
||||||
val realm = Realm.getInstance(realmConfiguration)
|
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
val sessionParams = realm
|
realm
|
||||||
.where(SessionParamsEntity::class.java)
|
.where(SessionParamsEntity::class.java)
|
||||||
.findAll()
|
.findAll()
|
||||||
.mapNotNull { mapper.map(it) }
|
.mapNotNull { mapper.map(it) }
|
||||||
realm.close()
|
}
|
||||||
return sessionParams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun save(sessionParams: SessionParams) {
|
override suspend fun save(sessionParams: SessionParams) {
|
||||||
|
|
Loading…
Reference in a new issue