Rocket.Chat.Electron icon indicating copy to clipboard operation
Rocket.Chat.Electron copied to clipboard

fix: File not getting download when clicked on its name

Open preeesha opened this issue 1 year ago • 4 comments

Closes RocketChat/Rocket.Chat.Electron#2763, RocketChat/Rocket.Chat.Electron#2764, RocketChat/Rocket.Chat.Electron#2723, RocketChat/Rocket.Chat.Electron#2615 (may be)

It was observed in the mentioned issue that the users of the desktop app (only) were not able to download the file when clicked on it's name. Though, it was possible by clicking on the little cloud icon. So, this was a discrepancy in the UX. During my investigation I have found that the issue lies in the Rocket.Chat's web view although it's behaviour is pretty suitable for the browser. But for desktop, we can fix it here.

It was observed that it's caused due to the difference in the link building or <a> tag in the rocket chat's web view. Here're the differences:

  1. Working element (cloud icon) image
  2. Problematic element (file name) image

The difference is in the attributes of href and download. The working element

  1. Has the download attribute specifying the file name which is missing in the other.
  2. Has the ?download applied at the end of the file's URL in the href attribute

To solve this issue, I have attached an event listener to the DOM of the Rocket.Chat's webview and whenever a link is clicked it checks whether the link is meant to download a file or not. If it is, a new temporary element (<a>) is created in the DOM with the modified attributes to process the download of the file.

Here're the results: Animation

preeesha avatar Dec 31 '23 07:12 preeesha

This seems a little instrusive, the core team already modified the core to fix this. Dont think that we should make this to fix the issue. Can you test the newer version of server to see what happens?

jeanfbrito avatar Feb 06 '24 17:02 jeanfbrito

Thanks @jeanfbrito for your views! I'll test it out on the latest versions of the servers and update you shortly.

preeesha avatar Feb 06 '24 17:02 preeesha

@jeanfbrito I have tested it on the latest development version of the rocket chat server. It's still there.

preeesha avatar Feb 09 '24 13:02 preeesha

Its only fixed (3.9.14) for pdf files but not for example docx etc pp

teach404W avatar Feb 22 '24 10:02 teach404W