Implement MSC2530: render caption for image and video if available and add white backround to images in timeline.#2570
Conversation
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>
Implement MSC2530
|
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
|
This does look better :D |
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this comment.
Suspicious change, as if a filter was applied to the image
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)
| @Composable | ||
| internal fun TimelineImageWithCaptionRowPreview() = ElementPreview { | ||
| Column { | ||
| sequenceOf(false, true).forEach { |
There was a problem hiding this comment.
Maybe name it for clarity:
| 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 :)
There was a problem hiding this comment.
Please see my comment about the difference between the caption colors.
|
|
(updating the title for further reference when searching for this PR) |
|
@jmartinesp Given this is part of the spec, is there a way we could get the event logic for this in the SDK so that iOS could reuse it? 😇 |
Sure, feel free to open a PR 😉 . |
|
Is the logic literally just Or is there more to this? |
|
I think that should be it, based on the implemented MSC contents. |
|
Would it make sense to have a similar function for the |
|
Let's see ruma/ruma#1919 🤞
I wondered about this too, wasn't really sure what to call it though. |
|
FWIW, I tried to mitigate the confusion in #3574 but it's still in discussion. |
Have opened ruma/ruma#1921 to try address this in Ruma and then we can use it in the SDK. |





Type of change
Content
Based on #2522 (thanks @surakin!) .
filename != null && body != filename.You can review only my commits, starting from 6cfe0c8.
Motivation and context
Closes #2521.
Screenshots / GIFs
Tests
You'll need a room where images or videos with captions have been sent.
Tested devices
Checklist