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

Open chat links in regular browser tabs #4198

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

cbs228
Copy link

@cbs228 cbs228 commented Jan 26, 2025

Content

Open web hyperlinks in chat messages in the user's regular, preferred web browser. Fixes bug introduced in v0.6.5.

Closes #3885

Motivation and context

In 5baefd4, a link to a "help" web page was added to the MessagesView. Since this page is essentially part of the app, it should and does open in an "in-app" Chrome Custom Tab, where supported.

Unfortunately, this change affects every link in the messages view, including links sent in chat messages. As of v0.6.5, links in chat messages now open in a Custom Tab instead of the user's configured "full" web browser. This is a UX nuisance.

Separate "regular" links from "custom tab" links with a new parameter onLinkClick(..., customTab). If true, the link opens in a custom tab.

Alternatively, the first patch in this PR removes the Custom Tab behavior from MessagesView entirely. This is likely not the preferred end result, however.

Screenshots / GIFs

Before After
Screenshot_20250125-211827_Fennec Screenshot_20250125-211852_Fennec

Tests

  1. Build F-Droid version with

    export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64/
    export GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xmx9g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -Dkotlin.daemon.jvm.options=-Xmx4g"
    ./gradlew app:assembleFDroidDebug
    
  2. Install on device.

  3. Sign in to Element.

  4. Open a chat room. Find a message which includes an https:// web link.

  5. Tap on the link.

  6. Observe that the link is opened in the "full" web browser with the full browser UI and other tabs. (See screenshots.)

I have not tried to force an identity change to test that the identity change help still loads in a Chrome Custom Tab. I'm not sure what the best way to test that is.

This PR should not introduce any new Android APIs. If API 24 emulator testing is required, can the project recommend an emulator?

Tested devices

  • Physical: Android 14 / LineageOS 21, with f-droid build and the Fennec F-Droid web browser
  • Emulator

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes (N/A, but tested anyway)
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

In [1], all hyperlinks within `MessagesNode` switched to using

    activity.openUrlInChromeCustomTab()

instead of with `openUrlInExternalApp()`.

This causes web links in chat messages to open in an "in-app"
Chrome Custom Tab [2] instead of the user's configured "full"
web browser. This is a UX nuisance. Open web links in a full
browser instead.

Closes element-hq#3885 [3].

[1]: 5baefd4 (Identity change: handle click on "learn more")

[2]: https://developer.chrome.com/docs/android/custom-tabs/guide-get-started#opening_a_custom_tab

[3]: element-hq#3885
@cbs228 cbs228 requested a review from a team as a code owner January 26, 2025 19:02
@cbs228 cbs228 requested review from ganfra and removed request for a team January 26, 2025 19:02
Copy link
Contributor

Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:

  • Your branch should be based on origin/develop, at least when it was created.
  • The title of the PR will be used for release notes, so it needs to describe the change visible to the user.
  • The test pass locally running ./gradlew test.
  • The code quality check suite pass locally running ./gradlew runQualityChecks.
  • If you modified anything related to the UI, including previews, you'll have to run the Record screenshots GH action in your forked repo: that will generate compatible new screenshots. However, given Github Actions limitations, it will prevent the CI from running temporarily, until you upload a new commit after that one. To do so, just pull the latest changes and push an empty commit.

@bmarty bmarty added the Z-Community-PR Issue is solved by a community member's PR label Jan 28, 2025
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. I think it makes sense to open links using the default browser since we do not have specific action like sharing like the X app may have.

Can you handle my remark about the lambda parameter? I believe it will do the same thing but with less change on the codebase.

@@ -112,6 +112,7 @@ fun MessagesView(
onEventContentClick: (event: TimelineItem.Event) -> Boolean,
onUserDataClick: (UserId) -> Unit,
onLinkClick: (String) -> Unit,
onHelpLinkClick: (String) -> Unit,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was maybe simpler to add a Boolean parameter to the lambda onLinkClick: (String) -> Unit, to allow the usage of CustomTab if true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely save a few lines of code this way. It might be more expressive to use an enum here—it's kind of hard to tell what the Boolean does when you're deep in the call tree—but that would definitely add complexity.

Ready for re-review.

Some links in the `MessagesView` are part of Element X itself,
such as the help pages in `LearnMoreConfig` [1]. These links
should open in an "in-app" Chrome Custom Tab, because they are
basically part of the app.

Web links from chat messages, on the other hand, should open in
the user's preferred web browser as regular tabs.

Separate "regular" links from "custom tab" links with a new
parameter `onLinkClick(..., customTab)`. If true, the link
opens in a custom tab.

Links within `TimelineView` are always opened in a normal tab.

[1]: appconfig/src/main/kotlin/io/element/android/appconfig/LearnMoreConfig.kt
@cbs228 cbs228 force-pushed the bugfix/full-browser-for-web-links branch from ed7d5a5 to ebdd945 Compare January 29, 2025 03:09
@cbs228 cbs228 requested a review from bmarty January 29, 2025 03:15
@cbs228
Copy link
Author

cbs228 commented Feb 3, 2025

@bmarty, I think I've worked through all the comments and checklists. I don't have permission to run CI. Is there anything more I need to do for this PR?

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, it looks good to me. I have triggered the CI.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.34%. Comparing base (3668e86) to head (ebdd945).
Report is 101 commits behind head on develop.

Files with missing lines Patch % Lines
...es/impl/crypto/identity/IdentityChangeStateView.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4198      +/-   ##
===========================================
- Coverage    83.35%   83.34%   -0.02%     
===========================================
  Files         1886     1886              
  Lines        49403    49403              
  Branches      5804     5804              
===========================================
- Hits         41180    41175       -5     
- Misses        6134     6135       +1     
- Partials      2089     2093       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links open in in-app browser
2 participants