Create IsUselessResolver object

This commit is contained in:
Benoit Marty 2020-06-03 01:13:02 +02:00
parent 3f1e5b9b1e
commit 9a592e9c7e
3 changed files with 41 additions and 4 deletions

View file

@ -162,6 +162,8 @@ data class Event(
*/
fun isRedactedBySameUser() = senderId == unsignedData?.redactedEvent?.senderId
fun resolvedPrevContent(): Content? = prevContent ?: unsignedData?.prevContent
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

View file

@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.database.mapper
import com.squareup.moshi.JsonDataException
import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.UnsignedData
import im.vector.matrix.android.api.session.room.send.SendState
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
@ -37,9 +36,8 @@ internal object EventMapper {
eventEntity.eventId = event.eventId ?: "$$roomId-${System.currentTimeMillis()}-${event.hashCode()}"
eventEntity.roomId = event.roomId ?: roomId
eventEntity.content = ContentMapper.map(event.content)
val resolvedPrevContent = event.prevContent ?: event.unsignedData?.prevContent
eventEntity.prevContent = ContentMapper.map(resolvedPrevContent)
eventEntity.isUseless = event.type == EventType.STATE_ROOM_MEMBER && eventEntity.content == eventEntity.prevContent
eventEntity.prevContent = ContentMapper.map(event.resolvedPrevContent())
eventEntity.isUseless = IsUselessResolver.isUseless(event)
eventEntity.stateKey = event.stateKey
eventEntity.type = event.type
eventEntity.sender = event.senderId

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal.database.mapper
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toContent
internal object IsUselessResolver {
/**
* @return true if the event is useless
*/
fun isUseless(event: Event): Boolean {
return when (event.type) {
EventType.STATE_ROOM_MEMBER -> {
// Call toContent(), to filter out null value
event.content?.toContent() == event.resolvedPrevContent()?.toContent()
}
else -> false
}
}
}