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

Stream message URL issues #5294

Closed
DmytroRollo opened this issue Jun 18, 2024 · 1 comment
Closed

Stream message URL issues #5294

DmytroRollo opened this issue Jun 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DmytroRollo
Copy link

Dependencies used in a project

  • Io.getstream:stream-chat-android-compose
  • Io.getstream:stream-chat-android-offline
    Version: 6.4.0

Also can be reproduced In sample protect https://github.com/GetStream/stream-chat-android/tree/main/stream-chat-android-ui-components-sample

Description

The issue can be reproduced only with URLs that use both upper and lower case characters, for example:
www.ex.com/SomePathWithUpperCase

If user A sends a message with such URL to user B, both users see the original URL without any issues on the UI. However, if user A or B taps on the URL inside the message content, a redirect occurs with the URL formatted entirely in lowercase:
www.ex.com/somepathwithuppercase

I have identified the exact location in the io.getstream:stream-chat-android-compose:6.4.0 library where this transformation happens.
In the composable function of the library:

package io.getstream.chat.android.compose.ui.components.messages
@Composable
public fun MessageText(
   message: Message,
   currentUser: User?,
   modifier: Modifier = Modifier,
   onLongItemClick: (Message) -> Unit,
) { … }

There are two params of interest:

val styledText = ChatTheme.messageTextFormatter.format(message, currentUser)
val annotations = styledText.getStringAnnotations(0, styledText.lastIndex)

For this specific case, styledText has the value:
www.ex.com/SomePathWithUpperCase

Where annotations is a list containing one Range item with:

tag = "URL"
item = "www.ex.com/somepathwithuppercase"

As you can see, the item string now has the entire text in lowercase, which breaks the original URL.
Next, when the user clicks the URL, the following block of code is executed:

ClickableText(
   modifier = modifier
       .padding(
           start = 12.dp,
           end = 12.dp,
           top = 8.dp,
           bottom = 8.dp,
       ),
   text = styledText,
   style = style,
   onLongPress = { onLongItemClick(message) },
) { position ->
   val targetUrl = annotations.firstOrNull {
       position in it.start..it.end
   }?.item
   if (!targetUrl.isNullOrEmpty()) {
       context.startActivity(
           Intent(
               Intent.ACTION_VIEW,
               Uri.parse(targetUrl),
           ),
       )
   }
}

Here, targetUrl is taken from the annotations list, which contains the formatted link in lowercase. This processing causes an error for the end user.

@DmytroRollo DmytroRollo added the bug Something isn't working label Jun 18, 2024
@JcMinarro
Copy link
Member

Hello @DmytroRollo
We have fixed it in our last release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants