mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Fix issues with read marker and jumpToBottom
This commit is contained in:
parent
ec6d78bf96
commit
37230b0614
3 changed files with 24 additions and 22 deletions
|
@ -20,6 +20,7 @@ import im.vector.matrix.android.api.session.events.model.LocalEcho
|
|||
import im.vector.matrix.android.internal.database.model.ChunkEntity
|
||||
import im.vector.matrix.android.internal.database.model.ReadMarkerEntity
|
||||
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
||||
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
|
||||
import io.realm.Realm
|
||||
|
||||
internal fun isEventRead(monarchy: Monarchy,
|
||||
|
@ -37,15 +38,14 @@ internal fun isEventRead(monarchy: Monarchy,
|
|||
monarchy.doWithRealm { realm ->
|
||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) ?: return@doWithRealm
|
||||
val eventToCheck = liveChunk.timelineEvents.find(eventId)
|
||||
|
||||
isEventRead = if (eventToCheck?.root?.sender == userId) {
|
||||
isEventRead = if (eventToCheck == null || eventToCheck.root?.sender == userId) {
|
||||
true
|
||||
} else {
|
||||
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst()
|
||||
?: return@doWithRealm
|
||||
val readReceiptIndex = liveChunk.timelineEvents.find(readReceipt.eventId)?.displayIndex
|
||||
?: Int.MIN_VALUE
|
||||
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
||||
val eventToCheckIndex = eventToCheck.displayIndex
|
||||
|
||||
eventToCheckIndex <= readReceiptIndex
|
||||
}
|
||||
|
@ -61,13 +61,17 @@ internal fun isReadMarkerMoreRecent(monarchy: Monarchy,
|
|||
return false
|
||||
}
|
||||
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) ?: return false
|
||||
val eventToCheck = liveChunk.timelineEvents.find(eventId)
|
||||
|
||||
val eventToCheck = TimelineEventEntity.where(realm, roomId = roomId, eventId = eventId).findFirst()
|
||||
val eventToCheckChunk = eventToCheck?.chunk?.firstOrNull()
|
||||
val readMarker = ReadMarkerEntity.where(realm, roomId).findFirst() ?: return false
|
||||
val readMarkerIndex = liveChunk.timelineEvents.find(readMarker.eventId)?.displayIndex
|
||||
?: Int.MIN_VALUE
|
||||
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
||||
eventToCheckIndex <= readMarkerIndex
|
||||
val readMarkerEvent = TimelineEventEntity.where(realm, roomId = roomId, eventId = readMarker.eventId).findFirst()
|
||||
val readMarkerChunk = readMarkerEvent?.chunk?.firstOrNull()
|
||||
if (eventToCheckChunk == readMarkerChunk) {
|
||||
val readMarkerIndex = readMarkerEvent?.displayIndex ?: Int.MIN_VALUE
|
||||
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
||||
eventToCheckIndex <= readMarkerIndex
|
||||
} else {
|
||||
eventToCheckChunk?.isLastForward == false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
|
|||
private val roomFullyReadHandler: RoomFullyReadHandler,
|
||||
private val readReceiptHandler: ReadReceiptHandler,
|
||||
@UserId private val userId: String,
|
||||
private val eventBus: EventBus,
|
||||
private val networkConnectivityChecker: NetworkConnectivityChecker
|
||||
private val eventBus: EventBus
|
||||
) : SetReadMarkersTask {
|
||||
|
||||
override suspend fun execute(params: SetReadMarkersTask.Params) {
|
||||
|
@ -93,13 +92,14 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
|
|||
}
|
||||
|
||||
val shouldUpdateRoomSummary = readReceiptEventId != null && readReceiptEventId == latestSyncedEventId
|
||||
updateDatabase(params.roomId, markers, shouldUpdateRoomSummary)
|
||||
if (markers.isEmpty()) {
|
||||
return
|
||||
if (markers.isNotEmpty() || shouldUpdateRoomSummary) {
|
||||
updateDatabase(params.roomId, markers, shouldUpdateRoomSummary)
|
||||
}
|
||||
executeRequest<Unit>(eventBus) {
|
||||
isRetryable = true
|
||||
apiCall = roomAPI.sendReadMarker(params.roomId, markers)
|
||||
if (markers.isNotEmpty()) {
|
||||
executeRequest<Unit>(eventBus) {
|
||||
isRetryable = true
|
||||
apiCall = roomAPI.sendReadMarker(params.roomId, markers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -309,11 +309,10 @@ class RoomDetailFragment @Inject constructor(
|
|||
|
||||
roomDetailViewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is RoomDetailViewEvents.Failure -> showErrorInSnackbar(it.throwable)
|
||||
is RoomDetailViewEvents.Failure -> showErrorInSnackbar(it.throwable)
|
||||
is RoomDetailViewEvents.OnNewTimelineEvents -> scrollOnNewMessageCallback.addNewTimelineEventIds(it.eventIds)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
|
@ -348,9 +347,8 @@ class RoomDetailFragment @Inject constructor(
|
|||
jumpToBottomView.visibility = View.INVISIBLE
|
||||
if (!roomDetailViewModel.timeline.isLive) {
|
||||
roomDetailViewModel.timeline.restartWithEventId(null)
|
||||
} else {
|
||||
layoutManager.scrollToPosition(0)
|
||||
}
|
||||
layoutManager.scrollToPosition(0)
|
||||
}
|
||||
|
||||
jumpToBottomViewVisibilityManager = JumpToBottomViewVisibilityManager(
|
||||
|
|
Loading…
Reference in a new issue