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
|
@ -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,19 +109,17 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
}
|
||||
|
||||
if (currentMetadata == null) {
|
||||
realm.executeTransaction {
|
||||
if (deleteAll) {
|
||||
it.deleteAll()
|
||||
realm.deleteAll()
|
||||
}
|
||||
|
||||
// Metadata not found, or database cleaned, create it
|
||||
it.createObject(CryptoMetadataEntity::class.java, credentials.userId).apply {
|
||||
realm.createObject(CryptoMetadataEntity::class.java, credentials.userId).apply {
|
||||
deviceId = credentials.deviceId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
olmSessionsToRelease.forEach {
|
||||
|
|
|
@ -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 New Issue