Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render edited caption. #3904

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
mediaSource = messageType.source,
thumbnailSource = messageType.info?.thumbnailSource,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand All @@ -106,6 +107,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,

Check warning on line 110 in features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt

View check run for this annotation

Codecov / codecov/patch

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt#L110

Added line #L110 was not covered by tests
mediaSource = messageType.source,
thumbnailSource = messageType.info?.thumbnailSource,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand Down Expand Up @@ -143,6 +145,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
thumbnailSource = messageType.info?.thumbnailSource,
videoSource = messageType.source,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand All @@ -162,6 +165,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
mediaSource = messageType.source,
duration = messageType.info?.duration ?: Duration.ZERO,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand All @@ -177,6 +181,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
mediaSource = messageType.source,
duration = messageType.info?.duration ?: Duration.ZERO,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand All @@ -188,6 +193,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
mediaSource = messageType.source,
duration = messageType.info?.duration ?: Duration.ZERO,
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
Expand All @@ -203,6 +209,7 @@
filename = messageType.filename,
caption = messageType.caption?.trimEnd(),
formattedCaption = parseHtml(messageType.formattedCaption) ?: messageType.caption?.withLinks(),
isEdited = content.isEdited,
thumbnailSource = messageType.info?.thumbnailSource,
fileSource = messageType.source,
mimeType = messageType.info?.mimetype ?: MimeTypes.fromFileExtension(fileExtension),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TimelineItemContentStickerFactory @Inject constructor(
filename = content.filename,
caption = content.body,
formattedCaption = null,
isEdited = false,
mediaSource = content.source,
thumbnailSource = content.info.thumbnailSource,
mimeType = content.info.mimetype ?: MimeTypes.OctetStream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data class TimelineItemAudioContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val duration: Duration,
val mediaSource: MediaSource,
val mimeType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun aTimelineItemAudioContent(fileName: String = "A sound.mp3") = TimelineItemAu
filename = fileName,
caption = null,
formattedCaption = null,
isEdited = false,
mimeType = MimeTypes.Mp3,
formattedFileSize = "100kB",
fileExtension = "mp3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ sealed interface TimelineItemEventContent {
val type: String
}

interface TimelineItemEventMutableContent {
/** Whether the event has been edited. */
val isEdited: Boolean
}

@Immutable
sealed interface TimelineItemEventContentWithAttachment : TimelineItemEventContent {
sealed interface TimelineItemEventContentWithAttachment :
TimelineItemEventContent,
TimelineItemEventMutableContent {
val filename: String
val caption: String?
val formattedCaption: CharSequence?
Expand Down Expand Up @@ -74,9 +81,7 @@ fun TimelineItemEventContent.canReact(): Boolean =
/**
* Whether the event content has been edited.
*/
fun TimelineItemEventContent.isEdited(): Boolean =
when (this) {
is TimelineItemTextBasedContent -> isEdited
is TimelineItemPollContent -> isEdited
else -> false
}
fun TimelineItemEventContent.isEdited(): Boolean = when (this) {
is TimelineItemEventMutableContent -> isEdited
else -> false
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class TimelineItemFileContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val fileSource: MediaSource,
val thumbnailSource: MediaSource?,
val formattedFileSize: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun aTimelineItemFileContent(
filename = fileName,
caption = null,
formattedCaption = null,
isEdited = false,
thumbnailSource = null,
fileSource = MediaSource(url = ""),
mimeType = MimeTypes.Pdf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class TimelineItemImageContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val mediaSource: MediaSource,
val thumbnailSource: MediaSource?,
val formattedFileSize: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun aTimelineItemImageContent(
filename = filename,
caption = caption,
formattedCaption = null,
isEdited = false,
mediaSource = MediaSource(""),
thumbnailSource = null,
mimeType = MimeTypes.IMAGE_JPEG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ data class TimelineItemPollContent(
val answerItems: List<PollAnswerItem>,
val pollKind: PollKind,
val isEnded: Boolean,
val isEdited: Boolean
) : TimelineItemEventContent {
override val isEdited: Boolean,
) : TimelineItemEventContent,
TimelineItemEventMutableContent {
override val type: String = "TimelineItemPollContent"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class TimelineItemStickerContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val mediaSource: MediaSource,
val thumbnailSource: MediaSource?,
val formattedFileSize: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun aTimelineItemStickerContent(
filename = "a sticker.gif",
caption = "a body",
formattedCaption = null,
isEdited = false,
mediaSource = MediaSource(""),
thumbnailSource = null,
mimeType = MimeTypes.IMAGE_JPEG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import org.jsoup.nodes.Document
* Represents a text based content of a timeline item event (a message, a notice, an emote event...).
*/
@Immutable
sealed interface TimelineItemTextBasedContent : TimelineItemEventContent {
sealed interface TimelineItemTextBasedContent :
TimelineItemEventContent,
TimelineItemEventMutableContent {
/** The raw body of the event, in Markdown format. */
val body: String

Expand All @@ -30,9 +32,6 @@ sealed interface TimelineItemTextBasedContent : TimelineItemEventContent {
/** The plain text version of the event body. This is the Markdown version without actual Markdown formatting. */
val plainText: String

/** Whether the event has been edited. */
val isEdited: Boolean

/** The raw HTML body of the event. */
val htmlBody: String?
get() = htmlDocument?.body()?.html()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class TimelineItemVideoContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val duration: Duration,
val videoSource: MediaSource,
val thumbnailSource: MediaSource?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fun aTimelineItemVideoContent(
filename = "Video.mp4",
caption = null,
formattedCaption = null,
isEdited = false,
thumbnailSource = null,
blurHash = blurhash,
aspectRatio = aspectRatio,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class TimelineItemVoiceContent(
override val filename: String,
override val caption: String?,
override val formattedCaption: CharSequence?,
override val isEdited: Boolean,
val duration: Duration,
val mediaSource: MediaSource,
val mimeType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun aTimelineItemVoiceContent(
filename = filename,
caption = caption,
formattedCaption = null,
isEdited = false,
duration = duration,
mediaSource = mediaSource,
mimeType = mimeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class MessagesPresenterTest {
filename = "image.jpg",
caption = null,
formattedCaption = null,
isEdited = false,
mediaSource = MediaSource(AN_AVATAR_URL),
thumbnailSource = null,
mimeType = MimeTypes.Jpeg,
Expand Down Expand Up @@ -359,6 +360,7 @@ class MessagesPresenterTest {
filename = "video.mp4",
caption = null,
formattedCaption = null,
isEdited = false,
duration = 10.milliseconds,
videoSource = MediaSource(AN_AVATAR_URL),
thumbnailSource = MediaSource(AN_AVATAR_URL),
Expand Down Expand Up @@ -400,6 +402,7 @@ class MessagesPresenterTest {
content = TimelineItemFileContent(
filename = "file.pdf",
caption = null,
isEdited = false,
formattedCaption = null,
fileSource = MediaSource(AN_AVATAR_URL),
thumbnailSource = MediaSource(AN_AVATAR_URL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = null,
formattedCaption = null,
isEdited = false,
duration = Duration.ZERO,
videoSource = MediaSource(url = "url", json = null),
thumbnailSource = null,
Expand Down Expand Up @@ -278,7 +279,8 @@ class TimelineItemContentMessageFactoryTest {
thumbnailSource = MediaSource("url_thumbnail"),
blurhash = A_BLUR_HASH,
),
)
),
isEdited = true,
),
senderDisambiguatedDisplayName = "Bob",
eventId = AN_EVENT_ID,
Expand All @@ -287,6 +289,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "body.mp4",
caption = "body.mp4 caption",
formattedCaption = SpannedString("formatted"),
isEdited = true,
duration = 1.minutes,
videoSource = MediaSource(url = "url", json = null),
thumbnailSource = MediaSource("url_thumbnail"),
Expand Down Expand Up @@ -315,6 +318,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = null,
formattedCaption = null,
isEdited = false,
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = MimeTypes.OctetStream,
Expand All @@ -339,7 +343,8 @@ class TimelineItemContentMessageFactoryTest {
size = 123L,
mimetype = MimeTypes.Mp3,
)
)
),
isEdited = true,
),
senderDisambiguatedDisplayName = "Bob",
eventId = AN_EVENT_ID,
Expand All @@ -348,6 +353,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "body.mp3",
caption = null,
formattedCaption = null,
isEdited = true,
duration = 1.minutes,
mediaSource = MediaSource(url = "url", json = null),
mimeType = MimeTypes.Mp3,
Expand All @@ -370,6 +376,7 @@ class TimelineItemContentMessageFactoryTest {
eventId = AN_EVENT_ID,
caption = null,
formattedCaption = null,
isEdited = false,
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = MimeTypes.OctetStream,
Expand Down Expand Up @@ -397,7 +404,8 @@ class TimelineItemContentMessageFactoryTest {
duration = 1.minutes,
waveform = persistentListOf(1f, 2f),
),
)
),
isEdited = true,
),
senderDisambiguatedDisplayName = "Bob",
eventId = AN_EVENT_ID,
Expand All @@ -407,6 +415,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "body.ogg",
caption = null,
formattedCaption = null,
isEdited = true,
duration = 1.minutes,
mediaSource = MediaSource(url = "url", json = null),
mimeType = MimeTypes.Ogg,
Expand All @@ -433,6 +442,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = null,
formattedCaption = null,
isEdited = false,
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = MimeTypes.OctetStream,
Expand All @@ -454,6 +464,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = "body",
formattedCaption = null,
isEdited = false,
mediaSource = MediaSource(url = "url", json = null),
thumbnailSource = null,
formattedFileSize = "0 Bytes",
Expand Down Expand Up @@ -483,6 +494,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = null,
formattedCaption = null,
isEdited = false,
mediaSource = MediaSource(url = "url", json = null),
thumbnailSource = MediaSource(url = "thumbnail://url", json = null),
formattedFileSize = "8192 Bytes",
Expand Down Expand Up @@ -520,15 +532,17 @@ class TimelineItemContentMessageFactoryTest {
thumbnailSource = MediaSource("url_thumbnail"),
blurhash = A_BLUR_HASH,
)
)
),
isEdited = true,
),
senderDisambiguatedDisplayName = "Bob",
eventId = AN_EVENT_ID,
)
val expected = TimelineItemImageContent(
filename = "body.jpg",
formattedCaption = SpannedString("formatted"),
caption = "body.jpg caption",
formattedCaption = SpannedString("formatted"),
isEdited = true,
mediaSource = MediaSource(url = "url", json = null),
thumbnailSource = MediaSource("url_thumbnail"),
formattedFileSize = "888 Bytes",
Expand Down Expand Up @@ -556,6 +570,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "filename",
caption = null,
formattedCaption = null,
isEdited = false,
fileSource = MediaSource(url = "url", json = null),
thumbnailSource = null,
formattedFileSize = "0 Bytes",
Expand Down Expand Up @@ -586,7 +601,8 @@ class TimelineItemContentMessageFactoryTest {
),
thumbnailSource = MediaSource("url_thumbnail"),
)
)
),
isEdited = true,
),
senderDisambiguatedDisplayName = "Bob",
eventId = AN_EVENT_ID,
Expand All @@ -595,6 +611,7 @@ class TimelineItemContentMessageFactoryTest {
filename = "body.pdf",
caption = null,
formattedCaption = null,
isEdited = true,
fileSource = MediaSource(url = "url", json = null),
thumbnailSource = MediaSource("url_thumbnail"),
formattedFileSize = "123 Bytes",
Expand Down
Loading