mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Merge pull request #667 from vector-im/feature/realm_cleanup
Import change form https://github.com/matrix-org/matrix-android-sdk/pull/505
This commit is contained in:
commit
fb3e953e28
3 changed files with 9 additions and 14 deletions
|
@ -41,8 +41,7 @@ fun <T> doWithRealm(realmConfiguration: RealmConfiguration, action: (Realm) -> T
|
|||
*/
|
||||
fun <T : RealmObject> doRealmQueryAndCopy(realmConfiguration: RealmConfiguration, action: (Realm) -> T?): T? {
|
||||
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||
val result = action.invoke(realm)
|
||||
result?.let { realm.copyFromRealm(it) }
|
||||
action.invoke(realm)?.let { realm.copyFromRealm(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,8 +50,7 @@ fun <T : RealmObject> doRealmQueryAndCopy(realmConfiguration: RealmConfiguration
|
|||
*/
|
||||
fun <T : RealmObject> doRealmQueryAndCopyList(realmConfiguration: RealmConfiguration, action: (Realm) -> Iterable<T>): Iterable<T> {
|
||||
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||
val result = action.invoke(realm)
|
||||
realm.copyFromRealm(result)
|
||||
action.invoke(realm).let { realm.copyFromRealm(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
realmLocker = Realm.getInstance(realmConfiguration)
|
||||
|
||||
// Ensure CryptoMetadataEntity is inserted in DB
|
||||
doWithRealm(realmConfiguration) { realm ->
|
||||
doRealmTransaction(realmConfiguration) { realm ->
|
||||
var currentMetadata = realm.where<CryptoMetadataEntity>().findFirst()
|
||||
|
||||
var deleteAll = false
|
||||
|
@ -109,15 +109,13 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
}
|
||||
|
||||
if (currentMetadata == null) {
|
||||
realm.executeTransaction {
|
||||
if (deleteAll) {
|
||||
it.deleteAll()
|
||||
}
|
||||
if (deleteAll) {
|
||||
realm.deleteAll()
|
||||
}
|
||||
|
||||
// Metadata not found, or database cleaned, create it
|
||||
it.createObject(CryptoMetadataEntity::class.java, credentials.userId).apply {
|
||||
deviceId = credentials.deviceId
|
||||
}
|
||||
// Metadata not found, or database cleaned, create it
|
||||
realm.createObject(CryptoMetadataEntity::class.java, credentials.userId).apply {
|
||||
deviceId = credentials.deviceId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ object CommandParser {
|
|||
return ParsedCommand.ErrorEmptySlashCommand
|
||||
}
|
||||
|
||||
|
||||
return when (val slashCommand = messageParts.first()) {
|
||||
Command.CHANGE_DISPLAY_NAME.command -> {
|
||||
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()
|
||||
|
|
Loading…
Reference in a new issue