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

Fix pillification not working for non formatted message bodies #3201

Merged

Conversation

jmartinesp
Copy link
Member

Content

Pure Markdown bodies weren't being 'pillified' so their mentions were turned into UI elements in the timeline.

A new pillifiedBody property was added to TimelineItemTextBasedContent to fix this.

Motivation and context

#2966

Screenshots / GIFs

There shouldn't be any changes 🤞 .

Tests

  • Send a message with a single @room mention.
  • Check the message is properly rendered in the timeline with the @room pill.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • 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
  • Pull request includes a sign off
  • You've made a self review of your PR

Pure Markdown bodies weren't being 'pillified' so their mentions were turned into UI elements in the timeline.

A new `pillifiedBody` property was added to `TimelineItemTextBasedContent` to fix this.
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Jul 16, 2024
@jmartinesp jmartinesp requested a review from a team as a code owner July 16, 2024 07:48
@jmartinesp jmartinesp requested review from bmarty and removed request for a team July 16, 2024 07:48
Copy link
Contributor

github-actions bot commented Jul 16, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/x8juJt

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

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

Project coverage is 76.15%. Comparing base (2ff5fa6) to head (04880ec).
Report is 25 commits behind head on develop.

Files Patch % Lines
.../timeline/components/event/TimelineItemTextView.kt 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3201   +/-   ##
========================================
  Coverage    76.15%   76.15%           
========================================
  Files         1645     1645           
  Lines        38738    38747    +9     
  Branches      7496     7496           
========================================
+ Hits         29501    29509    +8     
  Misses        5343     5343           
- Partials      3894     3895    +1     

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

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, the pillification is working as expected. But there are still difference when sending @room from Element Web and from EXA (tested in a DM):

image

Also on EXA I do not have completion for @room, I have it on Web. This may be fixed later, not related to this PR.

EDIT: apparently this is working as expected: code

remember(content.pillifiedBody, mentionSpanTheme, lastCacheUpdate) {
updateMentionSpans(content.pillifiedBody, userProfileCache)
mentionSpanTheme.updateMentionStyles(content.pillifiedBody)
content.pillifiedBody
Copy link
Member

Choose a reason for hiding this comment

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

Is all this block equivalent to this simpler form?

    val formattedBody = content.formattedBody ?: content.pillifiedBody
    val textWithMentions = remember(formattedBody, mentionSpanTheme, lastCacheUpdate) {
        updateMentionSpans(formattedBody, userProfileCache)
        mentionSpanTheme.updateMentionStyles(formattedBody)
        formattedBody
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, nice catch!

val isEdited: Boolean

/** The raw HTML body of the event. */
Copy link
Member

Choose a reason for hiding this comment

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

Kudos for adding some documentation 👍

package io.element.android.features.messages.impl.utils

class FakeTextPillificationHelper(
private val pillifyLambda: (CharSequence) -> CharSequence = { it }
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to have a default lambda content with lambdaError() so that we ensure that it's not called when it's not expected, which is actually doing more test. Note that in this particular case, this is maybe OK to keep the current default implementation. I let you choose what's best.

Copy link
Member Author

Choose a reason for hiding this comment

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

This component is sometimes used as a dependency deep in the hierarchy so I think it's better to not have to customise it for testing other components that may depend on it for functionality but don't check its output.

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 17, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 17, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) July 17, 2024 07:58
Copy link

sonarcloud bot commented Jul 17, 2024

@jmartinesp jmartinesp merged commit f5e866e into develop Jul 17, 2024
30 checks passed
@jmartinesp jmartinesp deleted the fix/jme/display-pills-for-non-formatted-messages-too branch July 17, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants