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: unify file and image types #3050

Open
wants to merge 4 commits into
base: V7
Choose a base branch
from
Open

fix: unify file and image types #3050

wants to merge 4 commits into from

Conversation

khushal87
Copy link
Member

The goal of the PR is to unify the File and the Asset type, which was previously vaguely implemented to a common Client supported type, RNFile. This can be imported directly from the LLC and used in the SDK and by integrators as well.
The following are the changes and bug fixes in the PR:

  • Unify the File and Asset type to RNFile.
  • Unifying FileUpload and ImageUpload type to a common FileUpload type. This can be removed in future once we utilize the full capability of the new message composer. We can have everything as a LocalAttachment post upload and send the message.
  • The FileUpload type is now a lot simplified compared to what it was before.
  • Now, the image compression logic is improved as we do the compression a long time before we upload the file.
  • I have introduced optional parameters on uploadNewFile; this is for the case where, for audio voice recordings, we do send the type, which cannot be really derived from the mime_type. We can remove it once we finally move to the message composer completely imo.
  • The important change is the native handlers are now unified on the types of key they return from all the upload related APIs.

NOTE: The PR is tested on all the upload modes for native CLI/expo android/iOS.

selectedFiles.some((file) =>
file.id ? file.id === asset.id : file.uri === asset.uri || file.originalUri === asset.uri,
),
selectedImages.some((image) => image.uri === asset.uri) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this change exactly ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't rely on asset ID or originalUri(which is gone now), which is irrelevant for the new changes and are not supported by the RNFile type anyways. This can be pretty much checked from the file URI only and we can avoid the complex check here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We generate an id when we upload an image or file anyways so no point of getting an id from the native API here IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm talking about the file.id specifically. Let's please not introduce such changes (that we haven't tested properly) in larger PRs like this that involve quite a bit of refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we are not passing ID anymore and RNFile doesn't have a property ID, you can't check for it ideally and talking about uri, this works as far as I have tested.

const fileUploadsValue = fileUploads
.map(({ duration, paused, progress, state }) => `${state},${paused},${progress},${duration}`)
.join();
const fileUploadsValue = fileUploads.map(({ state }) => state).join();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we getting rid of the other values here ? I feel like this could break memoization for file uploads, but not sure

Copy link
Member Author

@khushal87 khushal87 Apr 7, 2025

Choose a reason for hiding this comment

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

It was vague. I tested it after removal and we don't really need it.

uri: attachment.asset_url,
size: attachment.file_size || 0,
type: attachment.mime_type || '',
uri: attachment.asset_url || '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we fail if there is no asset_url ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we should, but here, it is almost certain that an attachment would have a URI if it's uploaded because we derive the file uploads from attachments here. I am not sure why the LLC decided to keep these fields as optional. If you have any alternate solution please feel free to propose.

@isekovanic
Copy link
Contributor

@khushal87 khushal87 requested a review from oliverlaz April 7, 2025 15:47
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.

2 participants