Do not decorate local echos as sent.

This commit is contained in:
Onuray Sahin 2021-03-04 14:17:07 +03:00 committed by Benoit Marty
parent f5f16fd330
commit ab304b0b9f
1 changed files with 17 additions and 3 deletions

View File

@ -31,6 +31,7 @@ import org.matrix.android.sdk.api.crypto.VerificationState
import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.LocalEcho
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
@ -76,7 +77,9 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
val time = dateFormatter.format(event.root.originServerTs, DateFormatKind.MESSAGE_SIMPLE) val time = dateFormatter.format(event.root.originServerTs, DateFormatKind.MESSAGE_SIMPLE)
val e2eDecoration = getE2EDecoration(event) val e2eDecoration = getE2EDecoration(event)
// SendState Decoration
val isSentByMe = event.root.senderId == session.myUserId val isSentByMe = event.root.senderId == session.myUserId
val isLocalEcho = LocalEcho.isLocalEchoId(event.eventId)
val sendStateDecoration = if (isSentByMe) { val sendStateDecoration = if (isSentByMe) {
val isMedia = when (event.root.content?.toModel<MessageContent>()) { val isMedia = when (event.root.content?.toModel<MessageContent>()) {
is MessageImageContent, is MessageImageContent,
@ -85,7 +88,12 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
is MessageFileContent -> true is MessageFileContent -> true
else -> false else -> false
} }
getSendStateDecoration(event.root.sendState, prevEvent?.root?.sendState, event.readReceipts.any { it.user.userId != session.myUserId }, isMedia) getSendStateDecoration(
eventSendState = event.root.sendState,
prevEventSendState = prevEvent?.root?.sendState,
anyReadReceipts = event.readReceipts.any { it.user.userId != session.myUserId },
isMedia = isMedia,
isLocalEcho = isLocalEcho)
} else { } else {
SendStateDecoration.NONE SendStateDecoration.NONE
} }
@ -136,8 +144,14 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
) )
} }
private fun getSendStateDecoration(eventSendState: SendState, prevEventSendState: SendState?, anyReadReceipts: Boolean, isMedia: Boolean): SendStateDecoration { private fun getSendStateDecoration(
return if (eventSendState.isSending()) { eventSendState: SendState,
prevEventSendState: SendState?,
anyReadReceipts: Boolean,
isMedia: Boolean,
isLocalEcho: Boolean
): SendStateDecoration {
return if (eventSendState.isSending() || (eventSendState.isSent() && isLocalEcho)) {
if (isMedia) SendStateDecoration.SENDING_MEDIA else SendStateDecoration.SENDING_NON_MEDIA if (isMedia) SendStateDecoration.SENDING_MEDIA else SendStateDecoration.SENDING_NON_MEDIA
} else if (eventSendState.hasFailed()) { } else if (eventSendState.hasFailed()) {
SendStateDecoration.FAILED SendStateDecoration.FAILED