mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-27 11:09:18 +03:00
[TMP] More ReadMarker debugging
Change-Id: I1defffc997864db74e15fe6b06645adeed7b67fe
This commit is contained in:
parent
d3c69a71a2
commit
da43865733
3 changed files with 24 additions and 12 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.internal.database.helper
|
package org.matrix.android.sdk.internal.database.helper
|
||||||
|
|
||||||
|
import de.spiritcroc.matrixsdk.util.Dimber
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.Sort
|
import io.realm.Sort
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
|
@ -216,20 +217,20 @@ internal fun ChunkEntity.doesNextChunksVerifyCondition(linkCondition: (ChunkEnti
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity): Boolean {
|
internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity, dimber: Dimber? = null): Boolean {
|
||||||
if (this.isLastForward) return true
|
if (this.isLastForward) return true.also { dimber?.i { "isMoreReacentThan = true (this.isLastForward)" } }
|
||||||
if (chunkToCheck.isLastForward) return false
|
if (chunkToCheck.isLastForward) return false.also { dimber?.i { "isMoreReacentThan = false (ctc.isLastForward)" } }
|
||||||
// Check if the chunk to check is linked to this one
|
// Check if the chunk to check is linked to this one
|
||||||
if (chunkToCheck.doesNextChunksVerifyCondition { it == this }) {
|
if (chunkToCheck.doesNextChunksVerifyCondition { it == this }) {
|
||||||
return true
|
return true.also { dimber?.i { "isMoreReacentThan = true (ctc->this)" } }
|
||||||
}
|
}
|
||||||
if (this.doesNextChunksVerifyCondition { it == chunkToCheck }) {
|
if (this.doesNextChunksVerifyCondition { it == chunkToCheck }) {
|
||||||
return false
|
return false.also { dimber?.i { "isMoreReacentThan = false (this->ctc)" } }
|
||||||
}
|
}
|
||||||
// Otherwise check if this chunk is linked to last forward
|
// Otherwise check if this chunk is linked to last forward
|
||||||
if (this.doesNextChunksVerifyCondition { it.isLastForward }) {
|
if (this.doesNextChunksVerifyCondition { it.isLastForward }) {
|
||||||
return true
|
return true.also { dimber?.i { "isMoreReacentThan = true (this->isLastForward)" } }
|
||||||
}
|
}
|
||||||
// We don't know, so we assume it's false
|
// We don't know, so we assume it's false
|
||||||
return false
|
return false.also { dimber?.i { "isMoreReacentThan = false (fallback)" } }
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.matrix.android.sdk.internal.database.query
|
package org.matrix.android.sdk.internal.database.query
|
||||||
|
|
||||||
|
import de.spiritcroc.matrixsdk.util.Dimber
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
||||||
|
@ -80,9 +81,10 @@ private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, ro
|
||||||
|
|
||||||
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
||||||
roomId: String?,
|
roomId: String?,
|
||||||
eventId: String?): Boolean {
|
eventId: String?,
|
||||||
|
dimber: Dimber? = null): Boolean {
|
||||||
if (roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
|
if (roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
|
||||||
return false
|
return false.also { dimber?.i { "isReadMarkerMoreRecent = false (roomId ${roomId.isNullOrBlank()} || eventId ${eventId.isNullOrBlank()}" } }
|
||||||
}
|
}
|
||||||
return Realm.getInstance(realmConfiguration).use { realm ->
|
return Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
val eventToCheck = TimelineEventEntity.where(realm, roomId = roomId, eventId = eventId).findFirst()
|
val eventToCheck = TimelineEventEntity.where(realm, roomId = roomId, eventId = eventId).findFirst()
|
||||||
|
@ -93,11 +95,13 @@ internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
||||||
if (eventToCheckChunk == readMarkerChunk) {
|
if (eventToCheckChunk == readMarkerChunk) {
|
||||||
val readMarkerIndex = readMarkerEvent?.displayIndex ?: Int.MIN_VALUE
|
val readMarkerIndex = readMarkerEvent?.displayIndex ?: Int.MIN_VALUE
|
||||||
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
||||||
|
dimber?.i { "isReadMarkerMoreRecent = ($eventToCheckIndex <= $readMarkerIndex)" }
|
||||||
eventToCheckIndex <= readMarkerIndex
|
eventToCheckIndex <= readMarkerIndex
|
||||||
} else {
|
} else {
|
||||||
eventToCheckChunk != null && readMarkerChunk?.isMoreRecentThan(eventToCheckChunk) == true
|
dimber?.i { "isReadMarkerMoreRecent = (non-null ${eventToCheckChunk!=null} && ${readMarkerChunk!=null} && ...)" }
|
||||||
|
eventToCheckChunk != null && readMarkerChunk?.isMoreRecentThan(eventToCheckChunk, dimber) == true
|
||||||
}
|
}
|
||||||
}
|
}.also { dimber?.i { "isReadMarkerMoreRecent result $it" } }
|
||||||
}
|
}
|
||||||
internal fun isMarkedUnread(realmConfiguration: RealmConfiguration,
|
internal fun isMarkedUnread(realmConfiguration: RealmConfiguration,
|
||||||
roomId: String?): Boolean {
|
roomId: String?): Boolean {
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package org.matrix.android.sdk.internal.session.room.read
|
package org.matrix.android.sdk.internal.session.room.read
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
|
import de.spiritcroc.matrixsdk.util.DbgUtil
|
||||||
|
import de.spiritcroc.matrixsdk.util.Dimber
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
||||||
|
@ -61,6 +63,8 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver
|
private val globalErrorReceiver: GlobalErrorReceiver
|
||||||
) : SetReadMarkersTask {
|
) : SetReadMarkersTask {
|
||||||
|
|
||||||
|
private val rmDimber = Dimber("ReadMarkerDbg", DbgUtil.DBG_READ_MARKER)
|
||||||
|
|
||||||
override suspend fun execute(params: SetReadMarkersTask.Params) {
|
override suspend fun execute(params: SetReadMarkersTask.Params) {
|
||||||
val markers = mutableMapOf<String, String>()
|
val markers = mutableMapOf<String, String>()
|
||||||
Timber.v("Execute set read marker with params: $params")
|
Timber.v("Execute set read marker with params: $params")
|
||||||
|
@ -75,12 +79,15 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
params.readReceiptEventId
|
params.readReceiptEventId
|
||||||
}
|
}
|
||||||
if (fullyReadEventId != null && !isReadMarkerMoreRecent(monarchy.realmConfiguration, params.roomId, fullyReadEventId)) {
|
if (fullyReadEventId != null && !isReadMarkerMoreRecent(monarchy.realmConfiguration, params.roomId, fullyReadEventId, rmDimber)) {
|
||||||
|
rmDimber.i { "Set to $fullyReadEventId if it's not local..." }
|
||||||
if (LocalEcho.isLocalEchoId(fullyReadEventId)) {
|
if (LocalEcho.isLocalEchoId(fullyReadEventId)) {
|
||||||
Timber.w("Can't set read marker for local event $fullyReadEventId")
|
Timber.w("Can't set read marker for local event $fullyReadEventId")
|
||||||
} else {
|
} else {
|
||||||
markers[READ_MARKER] = fullyReadEventId
|
markers[READ_MARKER] = fullyReadEventId
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rmDimber.i { "Did not set to $fullyReadEventId" }
|
||||||
}
|
}
|
||||||
if (readReceiptEventId != null &&
|
if (readReceiptEventId != null &&
|
||||||
!isEventRead(monarchy.realmConfiguration, userId, params.roomId, readReceiptEventId)) {
|
!isEventRead(monarchy.realmConfiguration, userId, params.roomId, readReceiptEventId)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue