Skip to content
Open
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
3 changes: 1 addition & 2 deletions src/com/android/messaging/debug/TestDataSeeder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import kotlinx.coroutines.runBlocking

private const val TAG = "TestDataSeeder"
private const val TEST_PHONE_PREFIX = "+15550"
private const val TEST_YOUTUBE_VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
private const val TEST_LINK_MESSAGE_URL = "https://grapheneos.org"
private const val MEDIA_SCRATCH_FILE_EXTENSION_QUERY_PARAMETER = "ext"
private const val SEED_IMAGE_1_FILE_ID = "800001"
Expand Down Expand Up @@ -1358,7 +1357,7 @@ private fun seedScenarioH(
),
Msg("text", text = "We all had the same idea haha", senderId = jackId),
Msg("image", attachmentUri = img1, senderId = carolId),
Msg("text", text = TEST_YOUTUBE_VIDEO_URL, senderId = carolId),
Msg("text", text = "Found a clip of it online", senderId = carolId),
Msg("text", text = "The clip version is even better", senderId = jackId),
Msg("video", attachmentUri = videoUri, senderId = carolId),
Msg("text", text = "And here's the ambient audio from the room", senderId = jackId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ internal sealed interface ConversationMessageAttachment {
override val key: String,
val part: ConversationMessagePartUiModel.Attachment,
) : ConversationMessageAttachment

@Immutable
data class YouTubePreview(
override val key: String,
val sourceUrl: String,
val thumbnailUrl: String,
) : ConversationMessageAttachment
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,5 @@ internal fun ConversationMessageAttachment.toConversationAttachmentOpenActionOrN
)
}
}

is ConversationMessageAttachment.YouTubePreview -> {
ConversationAttachmentOpenAction.OpenExternal(
uri = sourceUrl,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private fun isGalleryVisualAttachment(
attachment.part is ConversationMessagePartUiModel.Attachment.Image
}

is ConversationMessageAttachment.YouTubePreview -> true
is ConversationMessageAttachment.Unsupported -> false
}
}
Expand All @@ -57,9 +56,7 @@ private fun isStandaloneVisualAttachment(
is ConversationMessageAttachment.Media ->
attachment.part is ConversationMessagePartUiModel.Attachment.Video

is ConversationMessageAttachment.Unsupported,
is ConversationMessageAttachment.YouTubePreview,
-> false
is ConversationMessageAttachment.Unsupported -> false
}
}

Expand Down Expand Up @@ -98,8 +95,6 @@ private fun isInlineAttachment(
is ConversationMessageAttachment.Media,
is ConversationMessageAttachment.Unsupported,
-> true

else -> false
}
}

Expand All @@ -122,8 +117,6 @@ private fun toInlineAttachment(
openAction = attachment.toConversationAttachmentOpenActionOrNull(),
)
}

is ConversationMessageAttachment.YouTubePreview -> null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import com.android.messaging.ui.conversation.messages.model.attachment.Conversat
import com.android.messaging.ui.conversation.messages.model.message.ConversationMessagePartUiModel
import com.android.messaging.ui.conversation.preview.previewMessageAttachments
import com.android.messaging.ui.core.MessagingPreviewColumn
import com.android.messaging.util.ContentType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf

Expand Down Expand Up @@ -278,16 +277,6 @@ private fun ConversationAttachmentThumbnail(
)
}

is ConversationMessageAttachment.YouTubePreview -> {
ConversationMediaThumbnail(
modifier = modifier,
contentUri = attachment.thumbnailUrl,
contentType = ContentType.IMAGE_JPEG,
size = thumbnailSize,
contentScale = contentScale,
)
}

is ConversationMessageAttachment.Unsupported -> {
Box(
modifier = modifier.background(
Expand Down Expand Up @@ -356,7 +345,6 @@ private fun ConversationMessageAttachment.requiresPlaybackAffordance(): Boolean
is ConversationMessageAttachment.Media -> {
part is ConversationMessagePartUiModel.Attachment.Video
}
is ConversationMessageAttachment.YouTubePreview -> true
is ConversationMessageAttachment.Unsupported -> false
}
}
Expand All @@ -369,10 +357,6 @@ private fun resolveAttachmentAspectRatio(
resolvePartAspectRatio(part = attachment.part)
}

is ConversationMessageAttachment.YouTubePreview -> {
MESSAGE_ATTACHMENT_DEFAULT_VIDEO_ASPECT_RATIO
}

is ConversationMessageAttachment.Unsupported -> {
MESSAGE_ATTACHMENT_DEFAULT_IMAGE_ASPECT_RATIO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,6 @@ private fun ConversationMessageAttachmentContentPreview() {
),
simDisplayName = "Work",
)
ConversationMessagePreviewItem(
message = previewOutgoingMessage(
messageId = "outgoing-youtube-preview",
text = "Watch this: https://www.youtube.com/watch?v=dQw4w9WgXcQ",
status = Status.Outgoing.Delivered,
),
simDisplayName = "Personal",
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,6 @@ private fun ConversationMessageBubbleAttachmentSurfacePreview() {
isSelectionMode = true,
simDisplayName = "Work",
)
ConversationMessageBubblePreviewItem(
message = previewOutgoingMessage(
messageId = "bubble-outgoing-youtube",
text = "Watch this: https://www.youtube.com/watch?v=dQw4w9WgXcQ",
status = Status.Outgoing.Delivered,
),
bubbleLayoutMode = ConversationMessageBubbleLayoutMode.AttachmentsInSurface,
simDisplayName = "Personal",
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.android.messaging.ui.conversation.messages.ui.message

import android.net.Uri
import android.util.Patterns
import android.webkit.URLUtil
import com.android.messaging.R
import com.android.messaging.ui.conversation.messages.model.attachment.ConversationMessageAttachment
import com.android.messaging.ui.conversation.messages.model.message.ConversationMessageContent
import com.android.messaging.ui.conversation.messages.model.message.ConversationMessagePartUiModel
import com.android.messaging.ui.conversation.messages.model.message.ConversationMessageUiModel
import com.android.messaging.ui.conversation.messages.ui.attachment.buildConversationAttachmentSections
import com.android.messaging.util.YouTubeUtil
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

internal fun buildConversationMessageContent(
message: ConversationMessageUiModel,
subjectText: String?,
): ConversationMessageContent {
val attachments = buildConversationMessageAttachments(message = message)
val attachments = message
.parts
.mapIndexedNotNull(::toConversationMessageAttachment)
.toImmutableList()
val attachmentSections = buildConversationAttachmentSections(
attachments = attachments,
vCardSubtitleTextResIdOverride = vCardSubtitleTextResIdOverride(message),
Expand Down Expand Up @@ -47,31 +46,6 @@ private fun vCardSubtitleTextResIdOverride(message: ConversationMessageUiModel):
}
}

private fun buildConversationMessageAttachments(
message: ConversationMessageUiModel,
): ImmutableList<ConversationMessageAttachment> {
val attachmentItems = message
.parts
.mapIndexedNotNull(::toConversationMessageAttachment)
.toImmutableList()

val hasImageAttachment = attachmentItems.any { attachment ->
attachment is ConversationMessageAttachment.Media &&
attachment.part is ConversationMessagePartUiModel.Attachment.Image
}

if (hasImageAttachment) {
return attachmentItems
}

return message.text
?.let(::findSingleYouTubePreview)
?.let { youtubePreview ->
(attachmentItems + youtubePreview).toImmutableList()
}
?: attachmentItems
}

private fun toConversationMessageAttachment(
index: Int,
part: ConversationMessagePartUiModel,
Expand Down Expand Up @@ -145,38 +119,3 @@ private fun ConversationMessagePartUiModel.Attachment.isSupportedAttachment(): B
is ConversationMessagePartUiModel.Attachment.File -> false
}
}

private fun findSingleYouTubePreview(
text: String,
): ConversationMessageAttachment.YouTubePreview? {
return extractConversationWebUrls(text)
.asSequence()
.mapNotNull { sourceUrl ->
val thumbnailUrl = YouTubeUtil
.getYoutubePreviewImageLink(sourceUrl)
?: return@mapNotNull null

ConversationMessageAttachment.YouTubePreview(
key = "youtube:$sourceUrl",
sourceUrl = sourceUrl,
thumbnailUrl = thumbnailUrl,
)
}
.take(2)
.singleOrNull()
}

private fun extractConversationWebUrls(text: String): Set<String> {
val webUrlMatcher = Patterns.WEB_URL.matcher(text)
val urls = LinkedHashSet<String>()

while (webUrlMatcher.find()) {
webUrlMatcher
.group()
.takeIf { it.isNotBlank() }
?.let(URLUtil::guessUrl)
?.let(urls::add)
}

return urls
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,6 @@ private fun ConversationMessageRowsAttachmentPreview() {
simDisplayName = "Work",
metadataText = "18:11 \u2022 Failed",
)

ConversationMessageRowsPreviewItem(
message = previewOutgoingMessage(
messageId = "rows-attachments-youtube-preview",
text = "Reference clip: https://www.youtube.com/watch?v=dQw4w9WgXcQ",
status = Status.Outgoing.Delivered,
),
simDisplayName = "Personal",
metadataText = "18:12 \u2022 Delivered",
)
}
}

Expand Down
98 changes: 0 additions & 98 deletions src/com/android/messaging/util/YouTubeUtil.java

This file was deleted.

Loading