Skip to content

Commit

Permalink
Fix issue of closing Realm in another thread (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 3, 2019
1 parent 5b63856 commit 490ce4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Other changes:
Bugfix 🐛:
- Do not show long click help if only invitation are displayed
- Fix emoji filtering not working
- Fix issue of closing Realm in another thread (#725)

Translations 🗣:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@ internal class DefaultFilterRepository @Inject constructor(private val monarchy:
override suspend fun storeFilter(filterBody: FilterBody, roomEventFilter: RoomEventFilter): Boolean {
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
val filter = FilterEntity.getFilter(realm)
val result = if (filter.filterBodyJson != filterBody.toJSONString()) {
// Filter has changed, store it and reset the filter Id
monarchy.awaitTransaction {
// Filter has changed, or no filter Id yet
filter.filterBodyJson != filterBody.toJSONString()
|| filter.filterId.isBlank()
}.also { hasChanged ->
if (hasChanged) {
// Filter is new or has changed, store it and reset the filter Id.
// This has to be done outside of the Realm.use(), because awaitTransaction change the current thread
monarchy.awaitTransaction { realm ->
// We manage only one filter for now
val filterBodyJson = filterBody.toJSONString()
val roomEventFilterJson = roomEventFilter.toJSONString()

val filterEntity = FilterEntity.getFilter(it)
val filterEntity = FilterEntity.getFilter(realm)

filterEntity.filterBodyJson = filterBodyJson
filterEntity.roomEventFilterJson = roomEventFilterJson
// Reset filterId
filterEntity.filterId = ""
}
true
} else {
filter.filterId.isBlank()
}
result
}
}

Expand Down

0 comments on commit 490ce4b

Please sign in to comment.