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

Allow downloading multiple images into one directory #7030

Closed

Conversation

major-mayer
Copy link
Contributor

@major-mayer major-mayer commented Sep 26, 2024

First time contributor checklist:

Contributor checklist:

  • My contribution is not related to translations.
  • My commits are in nice logical chunks with good commit messages
  • My changes are rebased on the latest main branch
  • A npm run ready run passes successfully (more about tests here)
  • My changes are ready to be shipped to users

Description

Describe briefly what your pull request changes. Focus on the value provided to users.
Today I noticed, that right now it's not possible to download multiple images at once, which makes saving large galleries to the disk very time-consuming.
I was very surprised why this is the case, given that downloading a single image works without problems.

So I decided that I could maybe take a look into the code and try to fix things on my own, because the feature requests regarding this issue have not seen any attention for 3 years.
My experience with React is basically non-existent, so it was a lot of copy-pasting and adjusting the existing approach to download a single attachment.

It took a while to understand the data-flow between the different files, functions and actions, but I got it to work 🥳
I would like to get some feedback on my approach, then I can clean it up, maybe add some tests (although I would need some guidance on how to write these, maybe a similar example) and rebase it.

Does it address any outstanding issues in this project?

Please write a summary of your test approach:

  • What kind of manual testing did you do?
    • I only used the staging environment so far, and sent a few pictures and other attachments to myself. I checked if I could download them without any problems.
  • Did you write any new tests?
    • At least not yet. I checked briefly if I could find any test regarding the download of single attachments, but couldn't find one. Before I invest more time into this, I would like to get some feedback, if this has the chance to be accepted.
  • What operating systems did you test with? (please use specific versions: http://whatsmyos.com/)
    • Manjaro KDE Wayland
    • Windows 11 Home 23H2 22631.4037
  • What other devices did you test with? (other Desktop devices, Android, Android Simulator, iOS, iOS Simulator)
    • None, but I could test it on my laptop as well (right now just desktop PC).

Edit: In addition to my regular Manjaro Linux system, I successfully tested the changes with Windows 11 as well.

Copy link
Contributor Author

@major-mayer major-mayer left a comment

Choose a reason for hiding this comment

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

In general, I tried to re-use as much existing code as possible and not mutate existing functions.
That's why I added an additional saveAttachments() function that takes an array of attachments, opens a directory picker dialog once and uses this base directory for all files.

One could probably combine the functionality to save a single attachment (with a user-defined name) and multiple attachments into one common function, but I didn't want to risk breaking too much existing functionality.
If wanted, I can use saveAttachments() for single attachments as well, skip the showSaveMultiDialog() call if the array's length is one and set dirPath to undefined.

ts/components/conversation/TimelineMessage.tsx Outdated Show resolved Hide resolved
Comment on lines 3909 to 3910
// TODO shouldn't we throw some kind of error here? Original code also doesn't do anything, but...
if (fullPath == null) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In saveAttachments() (so the function to download a single attachment), I guess this was a check to skip showing the toast, when the user cancels the download/ file picker dialog.
Since I'm doing this check a few lines above, we probably should either remove this check here completely or throw an error, because something went wrong in the Attachments.save() method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this should probably be a throw

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed that, please check the error message.

app/main.ts Outdated Show resolved Hide resolved
kickOffAttachmentDownload({
attachment,
messageId: id,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want a toast here telling the user why the save dialog isn't showing up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like "Can't save attachment, since it hasn't finished downloading yet." ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, probably pluralized for the single vs. multiple case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a new toast type and an action "showAttachmentDownloadStillInProgressToast" for this.
Hope that was correct, but I didn't know how to show the toast otherwise.

dispatch({
type: SHOW_TOAST,
payload: {
toastType: ToastType.FileSaved,
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a new toast for this situation, because the toast currently says the singular 'Attachment saved.' instead of listing the number saved.

Copy link
Contributor

Choose a reason for hiding this comment

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

(or a pluralized toast, with a number parameter or something)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pluralized the toast message if multiple attachments are saved.

@major-mayer major-mayer marked this pull request as ready for review October 5, 2024 21:44
@@ -23,7 +23,7 @@ import type {
PropsData as MessagePropsData,
PropsHousekeeping,
} from './Message';
import type { PushPanelForConversationActionType } from '../../state/ducks/conversations';
import { type PushPanelForConversationActionType } from '../../state/ducks/conversations';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want the type to be outside the braces, in fact. That's generally how we do things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted the change, but shouldn't npm run format take care of this.
I cannot remember that I did this change intentionally and had hoped that Prettier will include a rule for these imports.

},
"icu:attachmentSavedShow": {
"messageformat": "Im Ordner anzeigen"
},
"icu:attachmentStillDownloading": {
"messageformat": "{count, plural, one {Anhang kann} other {Anhänge können}} nicht gespeichert werden, da {count, plural, one {er} other {#}} noch nicht fertig heruntergeladen {count, plural, one {wurde} other {wurden}}."
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't modify the non-english files - those are managed by our translators. This will be overwritten the next time we pull strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I wasn't sure how to interpret this "You only need to modify the default locale _locales/en/messages.json." statement.
I thought this means that I have to modify the English file, but can edit other languages as well.
In my case this was necessary, because I had the Signal instance running in German and it crashed when the translated string wasn't present.

But if I understand you correctly, this means that I can leave the string as is?

@scottnonnenberg-signal
Copy link
Contributor

I think we're ready to merge this as soon as that last TODO is removed. Would you consider pushing a squashed version of all these changes, taking it down to one commit?

Use download directory as default for single file downloads

Check if any attachment is still pending

Cleaning up comments

Apply suggestions from code review

Co-authored-by: Scott Nonnenberg <[email protected]>

Add more changes from code review

Revert change to default path in show-save-dialog method

Add toast when attachment download is still in progress + pluralize FileSaved toast + fix linter errors

Remove unnecessary comment

More changes from code review

Remove comment

Remove comment
@major-mayer
Copy link
Contributor Author

I think we're ready to merge this as soon as that last TODO is removed. Would you consider pushing a squashed version of all these changes, taking it down to one commit?

Done, I hope the PR is ready now 🙂

@scottnonnenberg-signal
Copy link
Contributor

Thanks for all of your work on this - it was merged internally, and is now available in our latest beta: https://github.com/signalapp/Signal-Desktop/releases/tag/v7.31.0-beta.1

You can see the final commit here: 76e2597

@major-mayer
Copy link
Contributor Author

I'm glad (and a bit proud ;) to see my changes finally merged. Thanks for your great support during development ❤️

@major-mayer major-mayer deleted the download-multiple-images branch October 25, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants