diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryPresenter.kt index 5f9a2ea428..bba17d7f9d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryPresenter.kt @@ -47,7 +47,7 @@ class ReactionSummaryPresenter @Inject constructor( fun handleEvents(event: ReactionSummaryEvents) { when (event) { is ReactionSummaryEvents.ShowReactionSummary -> target.value = ReactionSummaryState.Summary( - reactions = event.reactions, + reactions = event.reactions.toImmutableList(), selectedKey = event.selectedKey, selectedEventId = event.eventId ) @@ -73,8 +73,8 @@ class ReactionSummaryPresenter @Inject constructor( avatarUrl = member?.avatarUrl ) sender.copy(user = user) - }) - }) + }.toImmutableList()) + }.toImmutableList()) } } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryState.kt index 1d1606e53d..1ccfdc9abf 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryState.kt @@ -18,13 +18,14 @@ package io.element.android.features.messages.impl.timeline.components.reactionsu import io.element.android.features.messages.impl.timeline.model.AggregatedReaction import io.element.android.libraries.matrix.api.core.EventId +import kotlinx.collections.immutable.ImmutableList data class ReactionSummaryState( val target: Summary?, val eventSink: (ReactionSummaryEvents) -> Unit ) { data class Summary( - val reactions: List, + val reactions: ImmutableList, val selectedKey: String, val selectedEventId: EventId ) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemEventFactory.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemEventFactory.kt index aea1019f11..c5d303b3f1 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemEventFactory.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemEventFactory.kt @@ -117,6 +117,7 @@ class TimelineItemEventFactory @Inject constructor( sentTime = timeFormatter.format(date), ) } + .toImmutableList() ) } // Sort aggregated reactions by count and then timestamp ascending, using @@ -127,7 +128,9 @@ class TimelineItemEventFactory @Inject constructor( compareByDescending { it.count } .thenBy { it.senders[0].timestamp } ) - return TimelineItemReactions(aggregatedReactions.toImmutableList()) + return TimelineItemReactions( + reactions = aggregatedReactions.toImmutableList() + ) } private fun MatrixTimelineItem.Event.computeReadReceiptState( diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReaction.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReaction.kt index 59c52ed8cf..cc6e956a1c 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReaction.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReaction.kt @@ -18,6 +18,7 @@ package io.element.android.features.messages.impl.timeline.model import io.element.android.libraries.core.extensions.ellipsize import io.element.android.libraries.matrix.api.core.UserId +import kotlinx.collections.immutable.ImmutableList /** * Length at which we ellipsize a reaction key for display @@ -35,28 +36,22 @@ private const val MAX_DISPLAY_CHARS = 16 data class AggregatedReaction( val currentUserId: UserId, val key: String, - val senders: List + val senders: ImmutableList ) { /** * The key to be displayed on screen. * * See [MAX_DISPLAY_CHARS]. */ - val displayKey: String by lazy { - key.ellipsize(MAX_DISPLAY_CHARS) - } + val displayKey: String = key.ellipsize(MAX_DISPLAY_CHARS) /** * The number of users who reacted with this key. */ - val count: Int by lazy { - senders.count() - } + val count: Int = senders.count() /** * True if the reaction has (also) been sent by the current user. */ - val isHighlighted: Boolean by lazy { - senders.any { it.senderId.value == currentUserId.value } - } + val isHighlighted: Boolean = senders.any { it.senderId == currentUserId } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt index dcd6bb105c..087de1753a 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt @@ -18,6 +18,7 @@ package io.element.android.features.messages.impl.timeline.model import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.libraries.matrix.api.core.UserId +import kotlinx.collections.immutable.toImmutableList import java.text.DateFormat import java.util.Date @@ -53,6 +54,6 @@ fun anAggregatedReaction( return AggregatedReaction( currentUserId = userId, key = key, - senders = senders + senders = senders.toImmutableList() ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionSender.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionSender.kt index 276ee0b266..987474bf04 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionSender.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionSender.kt @@ -16,10 +16,12 @@ package io.element.android.features.messages.impl.timeline.model +import androidx.compose.runtime.Immutable import io.element.android.libraries.matrix.api.core.UserId import io.element.android.libraries.matrix.api.user.MatrixUser import java.util.Date +@Immutable data class AggregatedReactionSender( val senderId: UserId, val timestamp: Date,