From 0d665388b87cc9cc7588e75afa9d154f4d9894c8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Apr 2024 13:56:44 +0200 Subject: [PATCH] Add Timeline item and reply preview with ambiguous display name --- ...imelineItemEventRowDisambiguatedPreview.kt | 47 +++++++++++++++++++ .../TimelineItemEventRowWithReplyPreview.kt | 5 +- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowDisambiguatedPreview.kt diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowDisambiguatedPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowDisambiguatedPreview.kt new file mode 100644 index 0000000000..019eb183b2 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowDisambiguatedPreview.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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 io.element.android.features.messages.impl.timeline.components + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.PreviewParameter +import io.element.android.features.messages.impl.timeline.model.InReplyToDetails +import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.designsystem.preview.PreviewsDayNight +import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType + +@PreviewsDayNight +@Composable +internal fun TimelineItemEventRowDisambiguatedPreview( + @PreviewParameter(InReplyToDetailsDisambiguatedProvider::class) inReplyToDetails: InReplyToDetails, +) = ElementPreview { + TimelineItemEventRowWithReplyContentToPreview(inReplyToDetails) +} + +class InReplyToDetailsDisambiguatedProvider : InReplyToDetailsProvider() { + override val values: Sequence + get() = sequenceOf( + aMessageContent( + body = "Message which are being replied.", + type = TextMessageType("Message which are being replied.", null) + ), + ).map { + aInReplyToDetails( + displayNameAmbiguous = true, + eventContent = it, + ) + } +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt index ca81acbd72..61d16f3e35 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt @@ -151,7 +151,7 @@ open class InReplyToDetailsProvider : PreviewParameterProvider ) } - private fun aMessageContent( + protected fun aMessageContent( body: String, type: MessageType, ) = MessageContent( @@ -164,13 +164,14 @@ open class InReplyToDetailsProvider : PreviewParameterProvider protected fun aInReplyToDetails( eventContent: EventContent, + displayNameAmbiguous: Boolean = false, ) = InReplyToDetails( eventId = EventId("\$event"), eventContent = eventContent, senderId = UserId("@Sender:domain"), senderProfile = ProfileTimelineDetails.Ready( displayName = "Sender", - displayNameAmbiguous = false, + displayNameAmbiguous = displayNameAmbiguous, avatarUrl = null, ), textContent = (eventContent as? MessageContent)?.body.orEmpty(),