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

Implement MSC2530: render caption for image and video if available and add white backround to images in timeline. #2570

Merged
merged 18 commits into from
Mar 20, 2024

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Mar 19, 2024

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Based on #2522 (thanks @surakin!) .

  • Adds a caption to image and video content when filename != null && body != filename.
  • Displays the caption below the image or video content in the timeline.
  • Changes how images are displayed, following what we suggested some time ago:
    • Behind the image and up until it covers the min size of a bubble a blur hash will be displayed.
    • Over it the image will be scaled until it fits with its aspect ratio, and centered in the available space.
    • We add a white background behind the image to make sure images with alpha channel will display their contents fine.

You can review only my commits, starting from 6cfe0c8.

Motivation and context

Closes #2521.

Screenshots / GIFs

Image Video

Tests

You'll need a room where images or videos with captions have been sent.

  • Open the room.
  • Make sure the images and videos both using and not using captions are displayed fine.

Tested devices

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

Checklist

surakin and others added 14 commits March 10, 2024 15:02
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
added video captions

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
@jmartinesp jmartinesp requested a review from a team as a code owner March 19, 2024 16:03
@jmartinesp jmartinesp requested review from bmarty and removed request for a team March 19, 2024 16:03
Copy link
Contributor

github-actions bot commented Mar 19, 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/edSPw2

@surakin
Copy link
Contributor

surakin commented Mar 19, 2024

This does look better :D

Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 78.62595% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 73.16%. Comparing base (5cc5a0b) to head (ecab819).
Report is 3 commits behind head on develop.

Files Patch % Lines
.../designsystem/components/blurhash/BlurHashImage.kt 35.29% 6 Missing and 5 partials ⚠️
...timeline/components/event/TimelineItemImageView.kt 78.94% 3 Missing and 5 partials ⚠️
...timeline/components/event/TimelineItemVideoView.kt 85.71% 2 Missing and 4 partials ⚠️
.../components/blurhash/BlurHashBackgroundModifier.kt 50.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2570      +/-   ##
===========================================
+ Coverage    73.14%   73.16%   +0.01%     
===========================================
  Files         1408     1410       +2     
  Lines        34095    34183      +88     
  Branches      6617     6638      +21     
===========================================
+ Hits         24939    25009      +70     
- Misses        5699     5709      +10     
- Partials      3457     3465       +8     

☔ 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.

LGTM, some remarks

Copy link
Member

Choose a reason for hiding this comment

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

Suspicious change, as if a filter was applied to the image

Copy link
Member Author

Choose a reason for hiding this comment

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

It's only alpha being 0.8f instead of 1f. Otherwise the image itself might not be distinguishable from the blurhash behind it (this happened with a mostly black image I was testing).

AsyncImage(
modifier = Modifier
.fillMaxWidth()
.then(if (isLoaded) Modifier.background(Color.White) else Modifier),
Copy link
Member

Choose a reason for hiding this comment

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

I know this has been reported internally, but I am pretty sure adding a white bg can cause more troubles than fixes (rendering in Dark theme for instance), but let's see.
FTR last time I checked, Element Web does not add white BG to images.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the white background the cause of these strange artifacts on the border/corners?
Screenshot_20240320-113301.png

Copy link
Member Author

Choose a reason for hiding this comment

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

FTR last time I checked, Element Web does not add white BG to images.

Yes, but Matthew said it was a mistake. i.e. png images with no background and black letters were impossible to read in dark mode.

Is the white background the cause of these strange artifacts on the border/corners?

Sadly, I think that's the case...

Copy link
Member

Choose a reason for hiding this comment

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

png images with no background and black letters

OK, so with a white background, how a png image with no background and white letters will render?

I'd say this is the problem for only a minority of files, probably built just to make applications fail (not only Element).

Adding a background to image with transparency is like not supporting image with transparency, this is a shame. I still believe we should not add a white background. This degrades the user experience (stickers, etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

You might be right. If the users find it annoying we can always remove this white background.

This degrades the user experience (stickers, etc.)

Stickers use a different view, so they won't have this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but Matthew said it was a mistake. i.e. png images with no background and black letters were impossible to read in dark mode.

Could we only add the background if we detect that the image is both transparent, and has a specific contrast ratio relative to the app colour scheme?

Copy link
Member Author

Choose a reason for hiding this comment

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

To check if an image is transparent we'd have to load it twice in memory if I'm not mistaken, which isn't really efficient, or add some transformation when Coil loads them, but it seems like it could affect animated images (GIFs, WebP...), so I don't think it's something we want to invest too much time on.

content.formatted?.body?.takeIf { content.formatted.format == MessageFormat.HTML } ?: SpannedString(content.caption)
}
Box {
EditorStyledText(
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to provide a LocalContentColor, as per this place, this will fix the fact that color of caption is not the same for my captions and for other people captions. (see the recorded screenshot)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

@Composable
internal fun TimelineImageWithCaptionRowPreview() = ElementPreview {
Column {
sequenceOf(false, true).forEach {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe name it for clarity:

Suggested change
sequenceOf(false, true).forEach {
sequenceOf(false, true).forEach { isMine ->

(do not apply suggestion, it will not compile!)

Note that this is not done everywhere, so maybe an opportunity to replace all occurences of isMine = it in the codebase :)

Copy link
Member

Choose a reason for hiding this comment

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

Please see my comment about the difference between the caption colors.

@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Mar 20, 2024
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Mar 20, 2024
@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Mar 20, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Mar 20, 2024
Copy link

sonarcloud bot commented Mar 20, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@jmartinesp jmartinesp merged commit 6aa84d6 into develop Mar 20, 2024
19 checks passed
@jmartinesp jmartinesp deleted the feature/add-caption-to-image-and-video-events branch March 20, 2024 12:58
@bmarty bmarty changed the title Implement MSC2530 Implement MSC2530: render caption for image and video if available Mar 20, 2024
@bmarty bmarty changed the title Implement MSC2530: render caption for image and video if available Implement MSC2530: render caption for image and video if available and add white backround to images in timeline. Mar 20, 2024
@bmarty
Copy link
Member

bmarty commented Mar 20, 2024

(updating the title for further reference when searching for this PR)

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.

Implement MSC2530 (Body field as media caption)
5 participants