mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Do not load room members if there is an ongoing request.
This commit is contained in:
parent
80396fcd39
commit
938cd32ddd
4 changed files with 52 additions and 4 deletions
|
@ -21,6 +21,7 @@ import io.realm.RealmMigration
|
||||||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
|
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
|
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields
|
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields
|
||||||
|
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -28,7 +29,7 @@ import javax.inject.Inject
|
||||||
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SESSION_STORE_SCHEMA_VERSION = 6L
|
const val SESSION_STORE_SCHEMA_VERSION = 7L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||||
|
@ -40,6 +41,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
||||||
if (oldVersion <= 3) migrateTo4(realm)
|
if (oldVersion <= 3) migrateTo4(realm)
|
||||||
if (oldVersion <= 4) migrateTo5(realm)
|
if (oldVersion <= 4) migrateTo5(realm)
|
||||||
if (oldVersion <= 5) migrateTo6(realm)
|
if (oldVersion <= 5) migrateTo6(realm)
|
||||||
|
if (oldVersion <= 6) migrateTo7(realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun migrateTo1(realm: DynamicRealm) {
|
private fun migrateTo1(realm: DynamicRealm) {
|
||||||
|
@ -105,4 +107,18 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
||||||
.addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java)
|
.addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java)
|
||||||
.addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java)
|
.addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun migrateTo7(realm: DynamicRealm) {
|
||||||
|
Timber.d("Step 6 -> 7")
|
||||||
|
realm.schema.get("RoomEntity")
|
||||||
|
?.addField("membersLoadStatusStr", String::class.java)
|
||||||
|
?.transform { obj ->
|
||||||
|
if (obj.getBoolean("areAllMembersLoaded")) {
|
||||||
|
obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.LOADED.name)
|
||||||
|
} else {
|
||||||
|
obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.NONE.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?.removeField("areAllMembersLoaded")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import io.realm.annotations.PrimaryKey
|
||||||
internal open class RoomEntity(@PrimaryKey var roomId: String = "",
|
internal open class RoomEntity(@PrimaryKey var roomId: String = "",
|
||||||
var chunks: RealmList<ChunkEntity> = RealmList(),
|
var chunks: RealmList<ChunkEntity> = RealmList(),
|
||||||
var sendingTimelineEvents: RealmList<TimelineEventEntity> = RealmList(),
|
var sendingTimelineEvents: RealmList<TimelineEventEntity> = RealmList(),
|
||||||
var areAllMembersLoaded: Boolean = false
|
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
private var membershipStr: String = Membership.NONE.name
|
private var membershipStr: String = Membership.NONE.name
|
||||||
|
@ -36,5 +35,14 @@ internal open class RoomEntity(@PrimaryKey var roomId: String = "",
|
||||||
membershipStr = value.name
|
membershipStr = value.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var membersLoadStatusStr: String = RoomMembersLoadStatusType.NONE.name
|
||||||
|
var membersLoadStatus: RoomMembersLoadStatusType
|
||||||
|
get() {
|
||||||
|
return RoomMembersLoadStatusType.valueOf(membersLoadStatusStr)
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
membersLoadStatusStr = value.name
|
||||||
|
}
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.database.model;
|
||||||
|
|
||||||
|
public enum RoomMembersLoadStatusType {
|
||||||
|
NONE,
|
||||||
|
LOADING,
|
||||||
|
LOADED
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit> {
|
internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit> {
|
||||||
|
@ -84,14 +85,14 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
|
||||||
}
|
}
|
||||||
roomMemberEventHandler.handle(realm, roomId, roomMemberEvent)
|
roomMemberEventHandler.handle(realm, roomId, roomMemberEvent)
|
||||||
}
|
}
|
||||||
roomEntity.areAllMembersLoaded = true
|
roomEntity.membersLoadStatus = RoomMembersLoadStatusType.LOADED
|
||||||
roomSummaryUpdater.update(realm, roomId, updateMembers = true)
|
roomSummaryUpdater.update(realm, roomId, updateMembers = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun areAllMembersAlreadyLoaded(roomId: String): Boolean {
|
private fun areAllMembersAlreadyLoaded(roomId: String): Boolean {
|
||||||
return Realm.getInstance(monarchy.realmConfiguration).use {
|
return Realm.getInstance(monarchy.realmConfiguration).use {
|
||||||
RoomEntity.where(it, roomId).findFirst()?.areAllMembersLoaded ?: false
|
RoomEntity.where(it, roomId).findFirst()?.membersLoadStatus == RoomMembersLoadStatusType.LOADED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue