Merge pull request #3224 from element-hq/feature/fga/compose_reaction_stability
Compose : add immutability to some Reaction classes
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AggregatedReaction>,
|
||||
val reactions: ImmutableList<AggregatedReaction>,
|
||||
val selectedKey: String,
|
||||
val selectedEventId: EventId
|
||||
)
|
||||
|
||||
@@ -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<AggregatedReaction> { it.count }
|
||||
.thenBy { it.senders[0].timestamp }
|
||||
)
|
||||
return TimelineItemReactions(aggregatedReactions.toImmutableList())
|
||||
return TimelineItemReactions(
|
||||
reactions = aggregatedReactions.toImmutableList()
|
||||
)
|
||||
}
|
||||
|
||||
private fun MatrixTimelineItem.Event.computeReadReceiptState(
|
||||
|
||||
@@ -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<AggregatedReactionSender>
|
||||
val senders: ImmutableList<AggregatedReactionSender>
|
||||
) {
|
||||
/**
|
||||
* 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 }
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user