Do not exclude auto-space-added DMs from orphans in home

Change-Id: I50dae52334d3a2473ff43e398a6448de652afc7f
This commit is contained in:
SpiritCroc 2022-06-16 16:34:17 +02:00
parent 1daf8ac51a
commit 7e6565aefa
5 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,13 @@
package de.spiritcroc.android.sdk.internal.database.migration
import de.spiritcroc.android.sdk.internal.util.database.ScRealmMigrator
import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
internal class MigrateScSessionTo006(realm: DynamicRealm) : ScRealmMigrator(realm, 6) {
override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("RoomSummaryEntity")
?.addField(RoomSummaryEntityFields.IS_ORPHAN_DM, Boolean::class.java)
}
}

View file

@ -21,6 +21,7 @@ import de.spiritcroc.android.sdk.internal.database.migration.MigrateScSessionTo0
import de.spiritcroc.android.sdk.internal.database.migration.MigrateScSessionTo003
import de.spiritcroc.android.sdk.internal.database.migration.MigrateScSessionTo004
import de.spiritcroc.android.sdk.internal.database.migration.MigrateScSessionTo005
import de.spiritcroc.android.sdk.internal.database.migration.MigrateScSessionTo006
import io.realm.DynamicRealm
import io.realm.RealmMigration
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo001
@ -67,7 +68,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
override fun hashCode() = 1000
// SC-specific DB changes on top of Element
private val scSchemaVersion = 5L
private val scSchemaVersion = 6L
private val scSchemaVersionOffset = (1L shl 12)
val schemaVersion = 29L +
@ -114,5 +115,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldScVersion <= 2) MigrateScSessionTo003(realm).perform()
if (oldScVersion <= 3) MigrateScSessionTo004(realm).perform()
if (oldScVersion <= 4) MigrateScSessionTo005(realm).perform()
if (oldScVersion <= 5) MigrateScSessionTo006(realm).perform()
}
}

View file

@ -311,6 +311,11 @@ internal open class RoomSummaryEntity(
if (value != field) field = value
}
/**
* Whether the flattenParentIds thing is only non-empty because of DMs auto-added to spaces
*/
var isOrphanDm: Boolean = false
var groupIds: String? = null
set(value) {
if (value != field) field = value

View file

@ -333,7 +333,7 @@ internal class RoomSummaryDataSource @Inject constructor(
when (queryParams.spaceFilter) {
SpaceFilter.OrphanRooms -> {
// orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
query.beginGroup().isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS).or().equalTo(RoomSummaryEntityFields.IS_ORPHAN_DM, true).endGroup()
}
is SpaceFilter.ActiveSpace -> {
// It's annoying but for now realm java does not support querying in primitive list :/

View file

@ -489,6 +489,7 @@ internal class RoomSummaryUpdater @Inject constructor(
}
}.distinct()
if (flattenRelated.isNotEmpty()) {
dmRoom.isOrphanDm = dmRoom.flattenParentIds.isNullOrEmpty()
// we keep real m.child/m.parent relations and add the one for common memberships
dmRoom.flattenParentIds += "|${flattenRelated.joinToString("|")}|"
}