Rename val for code clarity, and use facility

This commit is contained in:
Benoit Marty 2021-03-02 11:37:13 +01:00
parent 5d69a1ab91
commit a8ba125bd2
5 changed files with 7 additions and 12 deletions

View File

@ -18,7 +18,7 @@ package org.matrix.android.sdk.api.session.room.model
import org.matrix.android.sdk.api.session.events.model.Content
data class EditAggregatedSummary(
val aggregatedContent: Content? = null,
val latestContent: Content? = null,
// The list of the eventIDs used to build the summary (might be out of sync if chunked received from message chunk)
val sourceEvents: List<String>,
val localEchos: List<String>,

View File

@ -123,8 +123,7 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? {
return if (root.getClearType() == EventType.STICKER) {
root.getClearContent().toModel<MessageStickerContent>()
} else {
annotations?.editSummary?.aggregatedContent?.toModel()
?: root.getClearContent().toModel()
(annotations?.editSummary?.latestContent ?: root.getClearContent()).toModel()
}
}

View File

@ -40,7 +40,7 @@ internal object EventAnnotationsSummaryMapper {
?.let {
val latestEdition = it.editions.maxByOrNull { editionOfEvent -> editionOfEvent.timestamp } ?: return@let null
EditAggregatedSummary(
aggregatedContent = ContentMapper.map(latestEdition.content),
latestContent = ContentMapper.map(latestEdition.content),
sourceEvents = it.editions.filter { editionOfEvent -> !editionOfEvent.isLocalEcho }
.map { editionOfEvent -> editionOfEvent.eventId },
localEchos = it.editions.filter { editionOfEvent -> editionOfEvent.isLocalEcho }

View File

@ -89,6 +89,7 @@ import org.matrix.android.sdk.api.session.room.read.ReadService
import org.matrix.android.sdk.api.session.room.send.UserDraft
import org.matrix.android.sdk.api.session.room.timeline.Timeline
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
import org.matrix.android.sdk.api.session.room.timeline.getRelationContent
import org.matrix.android.sdk.api.session.room.timeline.getTextEditableContent
import org.matrix.android.sdk.api.session.widgets.model.Widget
@ -785,9 +786,7 @@ class RoomDetailViewModel @AssistedInject constructor(
room.editReply(state.sendMode.timelineEvent, it, action.text.toString())
}
} else {
val messageContent: MessageContent? =
state.sendMode.timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
?: state.sendMode.timelineEvent.root.getClearContent().toModel()
val messageContent = state.sendMode.timelineEvent.getLastMessageContent()
val existingBody = messageContent?.body ?: ""
if (existingBody != action.text) {
room.editTextMessage(state.sendMode.timelineEvent.root.eventId ?: "",
@ -802,9 +801,7 @@ class RoomDetailViewModel @AssistedInject constructor(
popDraft()
}
is SendMode.QUOTE -> {
val messageContent: MessageContent? =
state.sendMode.timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
?: state.sendMode.timelineEvent.root.getClearContent().toModel()
val messageContent = state.sendMode.timelineEvent.getLastMessageContent()
val textMsg = messageContent?.body
val finalText = legacyRiotQuoteText(textMsg, action.text.toString())

View File

@ -229,8 +229,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
private fun actionsForEvent(timelineEvent: TimelineEvent, actionPermissions: ActionPermissions): List<EventSharedAction> {
val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
?: timelineEvent.root.getClearContent().toModel()
val messageContent = timelineEvent.getLastMessageContent()
val msgType = messageContent?.msgType
return arrayListOf<EventSharedAction>().apply {