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

feat(media)!: Make all fields of Thumbnail required #4324

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

zecakeh
Copy link
Collaborator

@zecakeh zecakeh commented Nov 26, 2024

Thumbnail is used to provide the data and information when uploading a thumbnail along an attachment. It seems sensible to assume that if a client is able to generate a thumbnail, it should be able to get all this information for it too.
A thumbnail with no information is not really useful, as we don't know when it could be used instead of the original image.

It allows to simplify the send queue to not have to handle the case where the dimensions of the thumbnail are missing.

Removes BaseThumbnailInfo in the process by merging its fields in Thumbnail directly.

There are also 2 pre-commits to refactor part of the code to simplify the changes.

cc @bnjbvr.

… the encrypted thumbnail's content type

Signed-off-by: Kévin Commaille <[email protected]>
It seems sensible to assume that if a client is able to generate a thumbnail,
it should be able to get all this information for it too.
A thumbnail with no information is not really useful, as we don't know when it could be used instead of the original image.

Removes `BaseThumbnailInfo`.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh requested a review from a team as a code owner November 26, 2024 12:04
@zecakeh zecakeh requested review from andybalaam and removed request for a team November 26, 2024 12:04
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.10%. Comparing base (c61f707) to head (d9df0f9).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/encryption/mod.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4324      +/-   ##
==========================================
+ Coverage   85.07%   85.10%   +0.02%     
==========================================
  Files         275      275              
  Lines       30314    30297      -17     
==========================================
- Hits        25789    25783       -6     
+ Misses       4525     4514      -11     

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

@bnjbvr bnjbvr self-requested a review November 26, 2024 12:34
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Super nice refactoring, thanks. Just one small comment about the FFI layer, and we should be good to go.

Comment on lines +147 to +158
let height = thumbnail_info
.height
.and_then(|u| UInt::try_from(u).ok())
.ok_or(RoomError::InvalidAttachmentData)?;
let width = thumbnail_info
.width
.and_then(|u| UInt::try_from(u).ok())
.ok_or(RoomError::InvalidAttachmentData)?;
let size = thumbnail_info
.width
.and_then(|u| UInt::try_from(u).ok())
.ok_or(RoomError::InvalidAttachmentData)?;
Copy link
Member

Choose a reason for hiding this comment

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

Since we're failing if any's missing, maybe the FFI's ThumbnailInfo could also have non-optional fields for height/width/size? (also the last one is wrong, let size = thumbnail_info.width)

@bnjbvr
Copy link
Member

bnjbvr commented Nov 26, 2024

@jmartinesp @stefanceriu can you confirm it's OK to always require a height/width/size for a thumbnail?

@bnjbvr bnjbvr removed the request for review from andybalaam November 26, 2024 12:48
@stefanceriu
Copy link
Member

@jmartinesp @stefanceriu can you confirm it's OK to always require a height/width/size for a thumbnail?

I think it's fine, yes, we were already enforcing them on the FFI level on the same if a client is able to generate a thumbnail, it should be able to get all this information for it too logic

@jmartinesp
Copy link
Contributor

@jmartinesp @stefanceriu can you confirm it's OK to always require a height/width/size for a thumbnail?

I think it's fine, yes, we were already enforcing them on the FFI level on the same if a client is able to generate a thumbnail, it should be able to get all this information for it too logic

On Android we weren't, but I think it makes sense. However, I'm not sure if this makes sense if this info comes from the HS: if we get the mxc url of the thumbnail for a timeline event and we don't have a size, I think we could still display this thumbnail without those if the other client didn't provide them.

@bnjbvr
Copy link
Member

bnjbvr commented Nov 26, 2024

On Android we weren't, but I think it makes sense. However, I'm not sure if this makes sense if this info comes from the HS: if we get the mxc url of the thumbnail for a timeline event and we don't have a size, I think we could still display this thumbnail without those if the other client didn't provide them.

Ah yeah; forgot to say, this is only in the context of sending, so you could still receive thumbnails that lack dimensions, IIUC.

@zecakeh
Copy link
Collaborator Author

zecakeh commented Nov 26, 2024

So I should create a new type for sending? If I'm not mistaken that also means creating new ImageInfo and VideoInfo for sending, or changing the API to look more like the Rust API (with Thumbnail, BaseImageInfo and BaseVideoInfo).

@bnjbvr
Copy link
Member

bnjbvr commented Nov 26, 2024

So I should create a new type for sending? If I'm not mistaken that also means creating new ImageInfo and VideoInfo for sending, or changing the API to look more like the Rust API (with Thumbnail, BaseImageInfo and BaseVideoInfo).

Unless I'm mistaken, I think your change is fine ad we don't need a new type for sending, because it only touches places where we're sending a Thumbnail, right?

@zecakeh
Copy link
Collaborator Author

zecakeh commented Nov 26, 2024

I was talking about the FFI crate, if that's not clear.

@bnjbvr
Copy link
Member

bnjbvr commented Nov 26, 2024

Ah yeah, I missed that the ThumbnailInfo type was used for both sending and reading, at the FFI layer. Then we can merge this PR as is; no need to reintroduce moar types there :)

Thanks @zecakeh as usual for the nice PR!

@bnjbvr bnjbvr merged commit d4d5f45 into matrix-org:main Nov 26, 2024
40 checks passed
@zecakeh zecakeh deleted the thumbnail-no-option branch November 26, 2024 14:22
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.

4 participants