Skip to content
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 @@ -34,7 +34,6 @@ import io.getstream.chat.android.compose.viewmodel.channel.ChannelAttachmentsVie
import io.getstream.chat.android.compose.viewmodel.channel.ChannelAttachmentsViewModelFactory
import io.getstream.chat.android.models.AttachmentType
import io.getstream.chat.android.ui.common.feature.channel.attachments.ChannelAttachmentsViewEvent
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import kotlinx.coroutines.flow.collectLatest

class ChannelMediaAttachmentsActivity : ComponentActivity() {
Expand All @@ -50,7 +49,7 @@ class ChannelMediaAttachmentsActivity : ComponentActivity() {
ChannelAttachmentsViewModelFactory(
cid = requireNotNull(intent.getStringExtra(KEY_CID)),
attachmentTypes = listOf(AttachmentType.IMAGE, AttachmentType.VIDEO),
localFilter = { !it.imagePreviewUrl.isNullOrEmpty() && it.titleLink.isNullOrEmpty() },
localFilter = { !(it.imageUrl ?: it.thumbUrl).isNullOrEmpty() && it.titleLink.isNullOrEmpty() },
Comment thread
VelikovPetar marked this conversation as resolved.
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import io.getstream.chat.android.ui.common.feature.channel.info.ChannelInfoViewE
import io.getstream.chat.android.ui.common.state.channel.info.ChannelInfoViewState
import io.getstream.chat.android.ui.common.state.messages.list.ChannelHeaderViewState
import io.getstream.chat.android.ui.common.state.messages.list.DeletedMessageVisibility
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -577,7 +576,7 @@ class ChatsActivity : ComponentActivity() {
val viewModelFactory = ChannelAttachmentsViewModelFactory(
cid = cid,
attachmentTypes = listOf(AttachmentType.IMAGE, AttachmentType.VIDEO),
localFilter = { !it.imagePreviewUrl.isNullOrEmpty() && it.titleLink.isNullOrEmpty() },
localFilter = { !(it.imageUrl ?: it.thumbUrl).isNullOrEmpty() && it.titleLink.isNullOrEmpty() },
)
val viewModel = viewModel<ChannelAttachmentsViewModel>(
factory = viewModelFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.compose.ui.util.AsyncImagePreviewHandler
import io.getstream.chat.android.compose.ui.util.StreamAsyncImage
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl

/**
* UI for currently selected image attachments, within the [MessageInput].
Expand Down Expand Up @@ -76,7 +75,7 @@ private fun ImageAttachmentPreviewContentItem(
attachment: Attachment,
onAttachmentRemoved: (Attachment) -> Unit,
) {
val data = attachment.upload ?: attachment.imagePreviewUrl
val data = attachment.upload ?: attachment.imageUrl

Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ import io.getstream.chat.android.compose.ui.util.AsyncImagePreviewHandler
import io.getstream.chat.android.compose.ui.util.StreamAsyncImage
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import io.getstream.chat.android.ui.common.utils.extensions.linkPreviewImageUrl
import io.getstream.chat.android.ui.common.utils.extensions.linkUrl
import io.getstream.chat.android.uiutils.extension.addSchemeToUrlIfNeeded
import io.getstream.chat.android.uiutils.extension.hasLink

Expand Down Expand Up @@ -137,7 +138,7 @@ public fun LinkAttachmentContent(
"Missing link attachment."
}

val previewUrl = attachment.titleLink ?: attachment.ogUrl
val previewUrl = attachment.linkUrl
val urlWithScheme = previewUrl?.addSchemeToUrlIfNeeded()

checkNotNull(previewUrl) {
Expand Down Expand Up @@ -179,8 +180,8 @@ public fun LinkAttachmentContent(
onLongClick = { onLongItemClick(message) },
),
) {
val imagePreviewUrl = attachment.imagePreviewUrl
if (imagePreviewUrl != null) {
val linkPreviewUrl = attachment.linkPreviewImageUrl
if (linkPreviewUrl != null) {
LinkAttachmentImagePreview(attachment, isMine)
}

Expand All @@ -198,7 +199,7 @@ public fun LinkAttachmentContent(

@Composable
private fun LinkAttachmentImagePreview(attachment: Attachment, isMine: Boolean) {
val data = attachment.imagePreviewUrl
val data = attachment.linkPreviewImageUrl
var maxWidth by remember { mutableStateOf(0.dp) }

Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.ColorImage
import coil3.compose.LocalAsyncImagePreviewHandler
import io.getstream.chat.android.client.utils.attachment.isImage
import io.getstream.chat.android.compose.ui.attachments.factory.DefaultPreviewItemOverlayContent
import io.getstream.chat.android.compose.ui.components.CancelIcon
import io.getstream.chat.android.compose.ui.components.composer.MessageInput
Expand All @@ -45,7 +46,6 @@ import io.getstream.chat.android.compose.ui.util.AsyncImagePreviewHandler
import io.getstream.chat.android.compose.ui.util.StreamAsyncImage
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.models.AttachmentType
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl

/**
* UI for currently selected image and video attachments, within the [MessageInput].
Expand Down Expand Up @@ -98,7 +98,8 @@ private fun MediaAttachmentPreviewItem(
onAttachmentRemoved: (Attachment) -> Unit,
overlayContent: @Composable (attachmentType: String?) -> Unit,
) {
val data = mediaAttachment.upload ?: mediaAttachment.imagePreviewUrl
val data = mediaAttachment.upload
?: if (mediaAttachment.isImage()) mediaAttachment.imageUrl else mediaAttachment.thumbUrl

Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import io.getstream.chat.android.compose.ui.util.extensions.internal.imagePrevie
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.models.AttachmentType
import io.getstream.chat.android.ui.common.images.resizing.applyStreamCdnImageResizingIfEnabled
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import io.getstream.chat.android.ui.common.utils.extensions.giphyFallbackPreviewUrl
import java.io.File

/**
Expand Down Expand Up @@ -77,12 +77,9 @@ public fun MediaAttachmentQuotedContent(

val data =
when {
isGiphy ->
attachment.imagePreviewUrl
isGiphy -> attachment.giphyFallbackPreviewUrl
isImageContent ->
attachment.imagePreviewUrl
?.applyStreamCdnImageResizingIfEnabled(ChatTheme.streamCdnImageResizing)

attachment.imageUrl?.applyStreamCdnImageResizingIfEnabled(ChatTheme.streamCdnImageResizing)
else -> attachment.imagePreviewData
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.compose.ui.util.StreamAsyncImage
import io.getstream.chat.android.compose.ui.util.clickable
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import kotlinx.coroutines.coroutineScope
import kotlin.math.abs

Expand Down Expand Up @@ -103,7 +102,7 @@ internal fun MediaGalleryImagePage(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
val data = attachment.imagePreviewUrl
val data = attachment.imageUrl
val context = LocalContext.current

// Ensure we have a new imageRequest in case the data changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import io.getstream.chat.android.client.utils.attachment.isImage
import io.getstream.chat.android.client.utils.attachment.isVideo
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.ui.components.avatar.UserAvatar
Expand All @@ -50,7 +51,6 @@ import io.getstream.chat.android.compose.viewmodel.channel.ChannelAttachmentsVie
import io.getstream.chat.android.previewdata.PreviewMessageData
import io.getstream.chat.android.ui.common.feature.channel.attachments.ChannelAttachmentsViewAction
import io.getstream.chat.android.ui.common.state.channel.attachments.ChannelAttachmentsViewState
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import io.getstream.result.Error

/**
Expand Down Expand Up @@ -141,7 +141,8 @@ internal fun LazyGridItemScope.ChannelMediaAttachmentsItem(
item: ChannelAttachmentsViewState.Content.Item,
onClick: () -> Unit,
) {
val data = item.attachment.upload ?: item.attachment.imagePreviewUrl
val data = item.attachment.upload
?: if (item.attachment.isImage()) item.attachment.imageUrl else item.attachment.thumbUrl
Box(
modifier = Modifier
.clickable(onClick = onClick),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import io.getstream.chat.android.compose.ui.util.AsyncImagePreviewHandler
import io.getstream.chat.android.compose.ui.util.StreamAsyncImage
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.models.LinkPreview
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import io.getstream.chat.android.ui.common.utils.extensions.linkPreviewImageUrl
import io.getstream.chat.android.ui.common.utils.extensions.linkUrl
import io.getstream.chat.android.uiutils.extension.addSchemeToUrlIfNeeded
import io.getstream.log.StreamLog

Expand Down Expand Up @@ -91,7 +92,7 @@ public fun ComposerLinkPreview(

val context = LocalContext.current
val attachment = linkPreview.attachment
val previewUrl = attachment.titleLink ?: attachment.ogUrl
val previewUrl = attachment.linkUrl

checkNotNull(previewUrl) {
"Missing preview URL."
Expand Down Expand Up @@ -133,14 +134,14 @@ public fun ComposerLinkPreview(

@Composable
private fun ComposerLinkImagePreview(attachment: Attachment) {
val imagePreviewUrl = attachment.imagePreviewUrl ?: return
val linkPreviewUrl = attachment.linkPreviewImageUrl ?: return
val theme = ChatTheme.messageComposerTheme.linkPreview
Box(
modifier = Modifier.padding(theme.imagePadding),
contentAlignment = Alignment.Center,
) {
StreamAsyncImage(
data = imagePreviewUrl,
data = linkPreviewUrl,
modifier = Modifier
.height(theme.imageSize.height)
.width(theme.imageSize.width)
Expand Down Expand Up @@ -225,7 +226,7 @@ private fun ComposerLinkCancelIcon(
* @param preview The preview of the link attachment being clicked.
*/
private fun onLinkPreviewClick(context: Context, preview: LinkPreview) {
val previewUrl = preview.attachment.titleLink ?: preview.attachment.ogUrl
val previewUrl = preview.attachment.linkUrl
checkNotNull(previewUrl) {
"Missing preview URL."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ import io.getstream.chat.android.client.utils.attachment.isVideo
import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.ui.common.images.resizing.applyStreamCdnImageResizingIfEnabled
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl

/**
* This property checks if the attachment is an image or a video with enabled thumbnails.
* If so, it returns the image preview URL (applied with Stream CDN image resizing if enabled)
* If so, it returns the appropriate URL (applied with Stream CDN image resizing if enabled)
* or the upload [java.io.File] object.
* Otherwise, it returns null.
*
* For image attachments, [Attachment.imageUrl] is used.
* For video attachments when thumbnails are enabled, [Attachment.thumbUrl] is used.
*/
@get:Composable
internal val Attachment.imagePreviewData: Any?
get() = if (isImage() || (isVideo() && ChatTheme.videoThumbnailsEnabled)) {
imagePreviewUrl
?.applyStreamCdnImageResizingIfEnabled(ChatTheme.streamCdnImageResizing)
?: upload
} else {
null
get() = when {
isImage() ->
imageUrl
?.applyStreamCdnImageResizingIfEnabled(ChatTheme.streamCdnImageResizing)
?: upload
isVideo() && ChatTheme.videoThumbnailsEnabled ->
thumbUrl
?.applyStreamCdnImageResizingIfEnabled(ChatTheme.streamCdnImageResizing)
?: upload
else -> null
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.ui.common.feature.channel.attachments.ChannelAttachmentsViewController
import io.getstream.chat.android.ui.common.utils.AttachmentConstants
import io.getstream.chat.android.ui.common.utils.extensions.getDisplayableName
import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl
import io.getstream.log.taggedLogger
import io.getstream.result.Error
import io.getstream.result.onErrorSuspend
Expand Down Expand Up @@ -81,7 +80,10 @@ internal class ChannelMediaAttachmentsPreviewViewModel(
}

private fun startSharing(attachment: Attachment) {
logger.d { "[startSharing] mimeType: ${attachment.mimeType}, attachment: ${attachment.imagePreviewUrl}" }
logger.d {
"[startSharing] mimeType: ${attachment.mimeType}, imageUrl: ${attachment.imageUrl}, " +
"thumbUrl: ${attachment.thumbUrl}"
}
if (attachment.fileSize >= AttachmentConstants.MAX_SIZE_BEFORE_DOWNLOAD_WARNING_IN_BYTES) {
logger.d {
"[startSharing] Attachment larger than " +
Expand Down Expand Up @@ -111,7 +113,10 @@ internal class ChannelMediaAttachmentsPreviewViewModel(
}

private fun share(attachment: Attachment) {
logger.d { "[share] mimeType: ${attachment.mimeType}, attachment: ${attachment.imagePreviewUrl}" }
logger.d {
"[share] mimeType: ${attachment.mimeType}, imageUrl: ${attachment.imageUrl}, " +
"thumbUrl: ${attachment.thumbUrl}"
}
_state.update { currentState ->
currentState.copy(
isPreparingToShare = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.getstream.chat.android.ui.common.utils.extensions

import io.getstream.chat.android.core.internal.InternalStreamChatApi
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.ui.common.helper.internal.StorageHelper
import io.getstream.chat.android.ui.common.utils.StringUtils
Expand All @@ -24,5 +25,39 @@
return StringUtils.removeTimePrefix(title ?: name ?: upload?.name, StorageHelper.TIME_FORMAT)
}

@Deprecated(
message = "Use the appropriate field for your attachment type: " +
"imageUrl for image attachments, " +
"thumbUrl for video thumbnails and link/giphy previews.",
level = DeprecationLevel.WARNING,
)
public val Attachment.imagePreviewUrl: String?

Check warning on line 34 in stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/utils/extensions/Attachment.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AZ0Z8qJiTb56BCVJUIwd&open=AZ0Z8qJiTb56BCVJUIwd&pullRequest=6280
get() = thumbUrl ?: imageUrl

/**
* The image URL to display for link attachment previews.
*
* Prefers [Attachment.thumbUrl] over [Attachment.imageUrl].
*/
@InternalStreamChatApi
public val Attachment.linkPreviewImageUrl: String?
get() = thumbUrl ?: imageUrl

/**
* The navigation URL for link attachments.
*
* Prefers [Attachment.titleLink] over [Attachment.ogUrl].
*/
@InternalStreamChatApi
public val Attachment.linkUrl: String?
get() = titleLink ?: ogUrl

/**
* The fallback preview URL for Giphy attachments when [io.getstream.chat.android.ui.common.utils.giphyInfo]
* is not available.
*
* Falls back through [Attachment.thumbUrl], [Attachment.titleLink], and [Attachment.ogUrl].
*/
@InternalStreamChatApi
public val Attachment.giphyFallbackPreviewUrl: String?
get() = thumbUrl ?: titleLink ?: ogUrl
Loading
Loading