Realm-kotlin: implements equals where needed as objects are frozen now

This commit is contained in:
ganfra 2022-10-20 11:57:13 +02:00
parent ca4ed5c822
commit 7527693a05
5 changed files with 49 additions and 8 deletions

View File

@ -50,6 +50,20 @@ internal class ChunkEntity : RealmObject {
// If true, then this chunk was previously a last forward chunk
fun hasBeenALastForwardChunk() = nextToken == null && !isLastForward
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ChunkEntity
if (chunkId != other.chunkId) return false
return true
}
override fun hashCode(): Int {
return chunkId.hashCode()
}
companion object
}

View File

@ -26,5 +26,22 @@ internal class ReadReceiptEntity : RealmObject {
var userId: String = ""
var originServerTs: Double = 0.0
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ReadReceiptEntity
if (primaryKey != other.primaryKey) return false
return true
}
override fun hashCode(): Int {
return primaryKey.hashCode()
}
companion object
}

View File

@ -32,13 +32,27 @@ internal class TimelineEventEntity : RealmObject {
var senderName: String? = null
var isUniqueDisplayName: Boolean = false
var senderAvatar: String? = null
var senderMembershipEventId: String? = null
// ownedByThreadChunk indicates that the current TimelineEventEntity belongs
// to a thread chunk and is a temporarily event.
var ownedByThreadChunk: Boolean = false
var readReceipts: ReadReceiptsSummaryEntity? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as TimelineEventEntity
if (localId != other.localId) return false
return true
}
override fun hashCode(): Int {
return localId.hashCode()
}
companion object
}

View File

@ -115,7 +115,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
}
}
private suspend fun latestSyncedEventId(realm: TypedRealm, roomId: String): String? =
private fun latestSyncedEventId(realm: TypedRealm, roomId: String): String? =
TimelineEventEntity.latestEvent(realm, roomId = roomId, includesSending = false)?.eventId
private suspend fun updateDatabase(roomId: String, markers: Map<String, String>, shouldUpdateRoomSummary: Boolean) {

View File

@ -21,6 +21,7 @@ import io.realm.kotlin.UpdatePolicy
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity
import org.matrix.android.sdk.internal.database.query.createUnmanaged
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.session.sync.RoomSyncEphemeralTemporaryStore
@ -100,12 +101,7 @@ internal class ReadReceiptHandler @Inject constructor(
}
for ((userId, paramsDict) in userIdsDict) {
val ts = paramsDict[TIMESTAMP_KEY] ?: 0.0
val receiptEntity = ReadReceiptEntity().apply {
this.roomId = roomId
this.eventId = eventId
this.userId = userId
this.originServerTs = ts
}
val receiptEntity = ReadReceiptEntity.createUnmanaged(roomId, eventId, userId, ts)
readReceiptsSummary.readReceipts.add(receiptEntity)
}
realm.copyToRealm(readReceiptsSummary, updatePolicy = UpdatePolicy.ALL)