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

Change to use an unified constant for max media attachments per status #29073

Merged

Conversation

ileodo
Copy link
Contributor

@ileodo ileodo commented Feb 3, 2024

Currently, there are multiple places referring a hard coded magic number 4 as the max media attachment per status. This PR is creating a constant in MediaAttaments Mode to unifying the definition.

both JS and ruby will use the same definition.

@ileodo ileodo marked this pull request as ready for review February 3, 2024 10:15
@ileodo ileodo mentioned this pull request Feb 3, 2024
@ileodo ileodo force-pushed the feature/use-server-attachment-limit branch 4 times, most recently from 73c6f73 to ee93a5d Compare February 3, 2024 11:27
Copy link
Contributor

@mjankowski mjankowski left a comment

Choose a reason for hiding this comment

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

Looks good overall. Some followup ideas to add to this PR or afterwards:

  • The PostStatusService spec does check the 4 attachment limit -- this could be update to stub_const this new constant limit and simplify the spec (or at minimum, change the hard-coded 4 there to just reference the constant).
  • The UpdateStatusService is missing this spec coverage - could be added in similar way.

@ileodo
Copy link
Contributor Author

ileodo commented Feb 3, 2024

Thanks @mjankowski could you please help to enable the CI action for this PR?
Also do you want me to follow up on the two points? I'm not super familiar with Ruby on Rails, but I can give a try (it might take longer)
or you are fine to leave the for the future.

@ileodo ileodo changed the title [Add] Unified the config defining max media attachments per status Change to use an unified constant for max media attachments per status Feb 3, 2024
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

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

Project coverage is 85.00%. Comparing base (86500e3) to head (b4ffd04).
Report is 211 commits behind head on main.

❗ Current head b4ffd04 differs from pull request most recent head b21618c. Consider uploading reports for the commit b21618c to get more accurate results

Files Patch % Lines
app/services/update_status_service.rb 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29073      +/-   ##
==========================================
- Coverage   85.01%   85.00%   -0.02%     
==========================================
  Files        1059     1058       -1     
  Lines       28277    28282       +5     
  Branches     4538     4538              
==========================================
+ Hits        24040    24041       +1     
- Misses       3074     3078       +4     
  Partials     1163     1163              

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

Copy link
Contributor

github-actions bot commented Mar 6, 2024

This pull request has merge conflicts that must be resolved before it can be merged.

Copy link
Contributor

github-actions bot commented Mar 7, 2024

This pull request has resolved merge conflicts and is ready for review.

renchap
renchap previously approved these changes Mar 7, 2024
Copy link
Sponsor Member

@renchap renchap left a comment

Choose a reason for hiding this comment

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

Looks good!

Did you try locally to increase the value locally and check that both the UI and the API support the new value?

@ileodo
Copy link
Contributor Author

ileodo commented Mar 11, 2024

Looks good!

Did you try locally to increase the value locally and check that both the UI and the API support the new value?

thanks! yes, I did tested it locally with changing the const number.

@renchap renchap requested a review from a team March 11, 2024 11:13
@renchap
Copy link
Sponsor Member

renchap commented Mar 11, 2024

It looks like this is breaking the end-to-end tests in the admin panel, specifically this one: https://github.com/mastodon/mastodon/blob/main/spec/system/report_interface_spec.rb#L23

Can you please look at this and fix it?

@renchap renchap dismissed their stale review March 11, 2024 11:31

It breaks the admin panel

@ClearlyClaire
Copy link
Contributor

I think the admin panel failure is because the Media Gallery gets mounted out of a redux context there.

@ileodo
Copy link
Contributor Author

ileodo commented Mar 11, 2024

looks like there is some issue with the current main branch, under development mode (in docker), admin@localhost is not approved.. so I can't replicate and test the change, any idea about the "approved" issue?

@renchap
Copy link
Sponsor Member

renchap commented Mar 11, 2024

You can approve it from the CLI using bin/tootctl modify <username> --approved

@ileodo ileodo force-pushed the feature/use-server-attachment-limit branch from b21618c to 7f0ca08 Compare March 31, 2024 08:10
@ileodo
Copy link
Contributor Author

ileodo commented Mar 31, 2024

@ClearlyClaire Could you please help with fixing the media gallery in the report view? I'm not very familiar with how redux is used in mastodon, but definitely want to push for this PR. Thanks.

@renchap
Copy link
Sponsor Member

renchap commented Apr 2, 2024

The Redux store is not initialised at all when we render independent React components in a page (in your case, <MediaContainer>).

A way to solve this is to properly initialise Redux when mounting a MediaContainer so it has access to the Redux state. This is probably overkill in this specific case as you are only interested in one specific field from the instance endpoint.
I did this here, but I am not sure this is the best way to handle your issue: renchap@534ff0c

Another way to do this would be to somehow detect if we are in a Redux context, and if not, fetch this value and pass it to the component, but I do not think we do this in any other place?

@ileodo ileodo force-pushed the feature/use-server-attachment-limit branch from 5b209ad to 78370f3 Compare May 13, 2024 11:53
@ileodo ileodo force-pushed the feature/use-server-attachment-limit branch from 78370f3 to 93172ee Compare May 13, 2024 20:16
@ileodo
Copy link
Contributor Author

ileodo commented May 14, 2024

great. CI passed!

@ileodo ileodo requested a review from renchap May 14, 2024 23:08
@ileodo
Copy link
Contributor Author

ileodo commented May 17, 2024

bouncing this up.

Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@ileodo
Copy link
Contributor Author

ileodo commented Jun 11, 2024

This PR has been here for ages.. can any one review and see if it can get merged??

@ClearlyClaire
Copy link
Contributor

The authoring part is fine, but I'm not sure about the display part, for the following reasons:

  1. limiting the number of media in a gallery client-side seems unnecessary if the server also enforces this limit (note that there is a caveat in that very old versions of Mastodon did not limit the number of attachments stored)
  2. similarly, the request for the server configuration (fetchServer()) could be avoided
  3. design-wise, the media gallery component does not gracefully handle more than 4 attachments: when more than 4 attachments are attached, only the first two will be displayed, and the remaining ones will be part of the DOM, but below the first two, overflowing the component and thus hidden; this probably needs bigger design changes for such a feature to be useful

@ileodo
Copy link
Contributor Author

ileodo commented Jun 12, 2024

@ClearlyClaire I agree with what you said that there will be more work required if we want to support more than 4 media per post. This is why I made it clear in the PR title and description that the intention of this PR is just refactoring to have a constant indicate the limit instead having magic number 3/4 everywhere.

Are we fine with the refactoring?

@ClearlyClaire
Copy link
Contributor

Makes sense, but I think this would be easier done by:

  • removing the take(4) from the front-end entirely
  • possibly enforcing this server-side instead in REST::StatusSerializer

This would simplify the client-side code greatly and avoid doing an extra request to the API.

Further down the line, the UI can be changed to handle arbitrary many attachments in a more graceful way, and the limit can be lifted from the serializer.

@ileodo
Copy link
Contributor Author

ileodo commented Jun 14, 2024

@ClearlyClaire The client side need to be aware of this limit, because it's not only for display but also for uploading:

  1. The WebUI currently have the logic to check the limit when user uploading medias.
  2. Other clients (like iOS apps, e.g. IceCube) need to know the limit so that they can limit the same in the media picker widgets.

And still, I believe this PR is helping to move to a better place instead of making it worse. as in the master branch now, the backend is using a constant but magic number 3/4 everywhere in UI code

@ClearlyClaire
Copy link
Contributor

The client side need to be aware of this limit, because it's not only for display but also for uploading

I'm not disputing that, what I meant is that we can remove complexity from app/javascript/mastodon/components/media_gallery.jsx and app/javascript/mastodon/containers/media_container.jsx by not doing the checks here.

The changes in app/javascript/mastodon/actions/compose.js and app/javascript/mastodon/features/compose/containers/upload_button_container.js are fine.

@ileodo
Copy link
Contributor Author

ileodo commented Jun 18, 2024

@ClearlyClaire updated as per your comments

@ileodo
Copy link
Contributor Author

ileodo commented Jun 21, 2024

@ClearlyClaire may I know is it good to be merged now?

@ileodo
Copy link
Contributor Author

ileodo commented Jul 4, 2024

can someone have a look at this PR? it has been there for ages...

@ClearlyClaire
Copy link
Contributor

Please keep in mind that the Mastodon core team is very small, and has a lot of work to do (like handling the recent security release).

The code changes appear fine, although one of my suggestions is missing:

possibly enforcing this server-side instead in REST::StatusSerializer

I think this is important because in the absence of a media gallery redesign, having more than 4 media attachments results in a strictly less usable interface as only considering the 4 first media attachments. Furthermore, old versions of Mastodon used to not discard media attachments above 4 attachments, so viewing such posts would result in a degraded experience.

I will try to tackle these server-side changes myself soon, and I think this PR can be merged as soon as this is implemented.

But to be truly useful, the media gallery needs to be redesigned to gracefully handle more than 4 attachments.

@ileodo
Copy link
Contributor Author

ileodo commented Jul 5, 2024

thanks, apart form #30932, anything you think we need for this PR? @ClearlyClaire

@ClearlyClaire ClearlyClaire added this pull request to the merge queue Jul 8, 2024
Merged via the queue into mastodon:main with commit 36d819b Jul 8, 2024
31 checks passed
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.

None yet

4 participants