Skip to content

Conversation

@MatthieuTexier
Copy link

Adds the ability to fast tap on urls in message text to open the browser.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

Greptile Overview

Greptile Summary

This PR adds clickable URL detection to message text using Android's Patterns.WEB_URL matcher. URLs are styled with underline and primary color, and tapping them opens in the default browser.

Key implementation details:

  • New LinkifiedMessageText composable replaces the plain Text in message bubbles
  • URLs are detected using Patterns.WEB_URL and stored as AnnotatedString annotations
  • Custom gesture handling with pointerInput distinguishes between taps (opens link) and long presses (shows message menu)
  • URLs without schemes are prefixed with https://
  • Trailing punctuation (., ,, ;, :, !, ?, ), ], }) is stripped from URLs
  • Events are consumed to prevent parent's combinedClickable from triggering on link taps
  • Error handling with Toast message if browser cannot be opened

Confidence Score: 4/5

  • This PR is safe to merge with low risk
  • The implementation is well-structured with proper gesture coordination, error handling, and security considerations. URL scheme handling prevents malicious schemes, and the gesture logic correctly prevents conflicts with the parent message bubble's long-press behavior. The use of Android's built-in Patterns.WEB_URL is appropriate. Minor deduction because the interaction between nested gesture handlers could benefit from additional testing in edge cases (e.g., very fast taps, simultaneous touches).
  • No files require special attention

Important Files Changed

Filename Overview
app/src/main/java/com/lxmf/messenger/ui/screens/MessagingScreen.kt Adds URL detection and click handling to message text with proper gesture coordination and error handling

Sequence Diagram

sequenceDiagram
    participant User
    participant LinkifiedMessageText
    participant AnnotatedString
    participant GestureDetector
    participant Browser
    participant MessageBubble

    User->>LinkifiedMessageText: Tap on URL
    LinkifiedMessageText->>GestureDetector: awaitFirstDown(requireUnconsumed=false)
    GestureDetector->>MessageBubble: Press event (for animation)
    MessageBubble->>MessageBubble: Start press animation
    GestureDetector-->>LinkifiedMessageText: Down event captured
    LinkifiedMessageText->>GestureDetector: waitForUpOrCancellation()
    GestureDetector-->>LinkifiedMessageText: Up event captured
    LinkifiedMessageText->>LinkifiedMessageText: Check tap duration < longPressTimeout
    LinkifiedMessageText->>AnnotatedString: getOffsetForPosition(up.position)
    AnnotatedString-->>LinkifiedMessageText: Offset at tap location
    LinkifiedMessageText->>AnnotatedString: getStringAnnotations(URL_TAG, offset)
    AnnotatedString-->>LinkifiedMessageText: URL string
    LinkifiedMessageText->>GestureDetector: Consume down & up events
    LinkifiedMessageText->>LinkifiedMessageText: toBrowsableUri(url)
    LinkifiedMessageText->>Browser: startActivity(ACTION_VIEW, uri)
    Browser-->>User: Opens URL in browser
    MessageBubble->>MessageBubble: Cancel press animation (events consumed)
Loading

@torlando-tech
Copy link
Owner

Thank you for this @MatthieuTexier! I had just noticed the need for this in the last few days. Will try it out tonight!

@MatthieuTexier
Copy link
Author

oops sorry I didn't wanted to push this last patch in this pull request.
I don't know how to rollback.

@torlando-tech
Copy link
Owner

oops sorry I didn't wanted to push this last patch in this pull request. I don't know how to rollback.

no worries! maybe a git revert?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants