Skip to content

Commit 57ac200

Browse files
committed
Fix: (ement-room-download-file) Default filename, message, clicking
See <#323 (comment)>. Reported-by: Phil Sainty <[email protected]>
1 parent cd75afe commit 57ac200

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

ement-room.el

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5558,9 +5558,9 @@ Then invalidate EVENT's node to show the image."
55585558
(file-size-human-readable size)))
55595559
(string (format "[file: %s (%s) (%s)]" filename mimetype human-size)))
55605560
(concat (propertize string
5561-
'action #'ement-room-download-file
5561+
'action #'call-interactively
55625562
'button t
5563-
'button-data event
5563+
'button-data #'ement-room-download-file
55645564
'category t
55655565
'face 'button
55665566
'follow-link t
@@ -5581,9 +5581,9 @@ Then invalidate EVENT's node to show the image."
55815581
(human-size (file-size-human-readable size))
55825582
(string (format "[video: %s (%s) (%sx%s) (%s)]" body mimetype w h human-size)))
55835583
(concat (propertize string
5584-
'action #'ement-room-download-file
5584+
'action #'call-interactively
55855585
'button t
5586-
'button-data event
5586+
'button-data #'ement-room-download-file
55875587
'category t
55885588
'face 'button
55895589
'follow-link t
@@ -5972,19 +5972,26 @@ otherwise, download to the filename. Interactively, download to
59725972
(cl-typecase eww-download-directory
59735973
(string eww-download-directory)
59745974
(function (funcall eww-download-directory))))))))
5975-
(pcase-let (((cl-struct ement-event
5976-
(content (map ('filename event-filename)
5977-
('url mxc-url))))
5978-
event)
5979-
(started-at (current-time)))
5980-
(when (directory-name-p destination)
5975+
(pcase-let* (((cl-struct ement-event
5976+
(content (map ('filename event-filename) ('url mxc-url)
5977+
body)))
5978+
event)
5979+
(started-at (current-time))
5980+
(filename (if (not event-filename)
5981+
body
5982+
(if (equal body event-filename)
5983+
body
5984+
event-filename))))
5985+
(when (file-directory-p destination)
59815986
(unless (file-exists-p destination)
59825987
(make-directory destination 'parents))
5983-
(setf destination (file-name-concat destination event-filename)))
5988+
(setf destination (file-name-concat destination filename)))
59845989
(unless (file-writable-p destination)
5985-
(user-error "Destination path not writable: %S" destination))
5990+
;; FIXME: Pressing "C-u" before clicking a download link doesn't work.
5991+
(user-error "Destination path not writable: %S (Call with prefix to prompt for filename)"
5992+
destination))
59865993
(when (file-exists-p destination)
5987-
(user-error "File already exists: %S" destination))
5994+
(user-error "File already exists: %S (Call with prefix to prompt for filename)" destination))
59885995
;; TODO: For bonus points, provide a way to cancel a download (otherwise the user
59895996
;; would have to use `list-processes' and find the right one to delete), and to see
59905997
;; progress (perhaps borrowing some of the relevant code in hyperdrive.el).
@@ -5998,7 +6005,8 @@ otherwise, download to the filename. Interactively, download to
59986005
(message "File downloaded: %S (%s in %s at %s/sec) "
59996006
destination (file-size-human-readable file-size)
60006007
(format-seconds "%h:%m:%s%z seconds" duration)
6001-
speed))))))
6008+
speed))))
6009+
(message "Downloading to %S..." destination)))
60026010

60036011
;;;; Footer
60046012

0 commit comments

Comments
 (0)