mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
isEventRead() returns true if the event has been sent by the user
This commit is contained in:
parent
3fcfa33364
commit
5a2a9f908a
1 changed files with 10 additions and 4 deletions
|
@ -30,12 +30,18 @@ internal fun isEventRead(monarchy: Monarchy,
|
||||||
var isEventRead = false
|
var isEventRead = false
|
||||||
|
|
||||||
monarchy.doWithRealm { realm ->
|
monarchy.doWithRealm { realm ->
|
||||||
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst() ?: return@doWithRealm
|
|
||||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) ?: return@doWithRealm
|
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) ?: return@doWithRealm
|
||||||
val readReceiptIndex = liveChunk.timelineEvents.find(readReceipt.eventId)?.root?.displayIndex ?: Int.MIN_VALUE
|
val eventToCheck = liveChunk.timelineEvents.find(eventId)?.root
|
||||||
val eventToCheckIndex = liveChunk.timelineEvents.find(eventId)?.root?.displayIndex ?: Int.MAX_VALUE
|
|
||||||
|
|
||||||
isEventRead = eventToCheckIndex <= readReceiptIndex
|
isEventRead = if (eventToCheck?.sender == userId) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst() ?: return@doWithRealm
|
||||||
|
val readReceiptIndex = liveChunk.timelineEvents.find(readReceipt.eventId)?.root?.displayIndex ?: Int.MIN_VALUE
|
||||||
|
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
|
||||||
|
|
||||||
|
eventToCheckIndex <= readReceiptIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return isEventRead
|
return isEventRead
|
||||||
|
|
Loading…
Add table
Reference in a new issue