HomePhabricator
Diffusion Comm 73e1804de16e

[native] Make `failed` `boolean` in `PendingMultimediaUpload`

Description

[native] Make failed boolean in PendingMultimediaUpload

Summary:
Change failed from ?string to boolean in PendingMultimediaUpload. This diff also adds an optional failureMessage prop to PendingMultimediaUpload to store the error message in case failed is true.

This is part of an effort to refactor InputStateContainer since some of its logic is confusing. More context here. The main reason why failed was confusing is highlighted in the linked comment, but this section made little sense when failed was a string:

input-state-container.react.js
uploadInProgress = () => {
  if (this.props.ongoingMessageCreation) {
    return true;
  }
  for (const localMessageID in this.state.pendingUploads) {
    const messagePendingUploads = this.state.pendingUploads[localMessageID];
    for (const localUploadID in messagePendingUploads) {
      const { failed } = messagePendingUploads[localUploadID];
      if (!failed) {
        return true;
      }
    }
  }
  return false;
}

Now that failed is a boolean, if !failed is true, that means that there is a non-failed upload (since failed is false), which means it is in progress. If every single pending upload's failed prop is true, then no uploads are in progress because they all failed.


This same refactoring of failed for web will be the next diff.

Test Plan:
Made sure sending photos and videos worked as expected on iOS Simulator and added console.log(...) statements to log pendingUploads to view failed as a boolean.

Searched through the codebase for all usages of PendingMultimediaUpload to do this refactor.

Reviewers: atul, tomek, jacek, ashoat

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D4890

Details

Provenance
aboshAuthored on Aug 19 2022, 1:40 PM
Reviewer
tomek
Differential Revision
D4890: [native] Make `failed` `boolean` in `PendingMultimediaUpload`
Parents
rCOMM7f7f5ebfdd11: [native] Use `Array.some(...)` in `uploadInProgress`
Branches
Unknown
Tags
Unknown