mirror of
https://github.com/vale981/ement.el
synced 2025-03-05 17:21:41 -05:00
Add: Format m.file events
This commit is contained in:
parent
b3b1bd84b0
commit
6dc47f683c
1 changed files with 28 additions and 1 deletions
|
@ -2948,7 +2948,9 @@ If FORMATTED-P, return the formatted body content, when available."
|
||||||
(or new-content-format content-format) body)))))
|
(or new-content-format content-format) body)))))
|
||||||
(appendix (pcase msgtype
|
(appendix (pcase msgtype
|
||||||
("m.image" (ement-room--format-m.image event))
|
("m.image" (ement-room--format-m.image event))
|
||||||
(_ nil))))
|
("m.text" nil)
|
||||||
|
("m.file" (ement-room--format-m.file event))
|
||||||
|
(_ (format "[unrecognized msgtype: %s]" msgtype )))))
|
||||||
(when body
|
(when body
|
||||||
;; HACK: Once I got an error when body was nil, so let's avoid that.
|
;; HACK: Once I got an error when body was nil, so let's avoid that.
|
||||||
(setf body (ement-room--linkify-urls body)))
|
(setf body (ement-room--linkify-urls body)))
|
||||||
|
@ -3543,6 +3545,31 @@ Then invalidate EVENT's node to show the image."
|
||||||
(lambda (node-data)
|
(lambda (node-data)
|
||||||
(eq node-data event))))))))
|
(eq node-data event))))))))
|
||||||
|
|
||||||
|
(defun ement-room--format-m.file (event)
|
||||||
|
"Return \"m.file\" EVENT formatted as a string."
|
||||||
|
;; TODO: Insert thumbnail images when enabled.
|
||||||
|
(pcase-let* (((cl-struct ement-event
|
||||||
|
(content (map filename
|
||||||
|
('info (map mimetype size))
|
||||||
|
('url mxc-url))))
|
||||||
|
event)
|
||||||
|
(url (when mxc-url
|
||||||
|
(ement--mxc-to-url mxc-url ement-session)))
|
||||||
|
(human-size (file-size-human-readable size))
|
||||||
|
(string (format "[file: %s (%s) (%s)]" filename mimetype human-size)))
|
||||||
|
(concat (propertize string
|
||||||
|
'action #'browse-url
|
||||||
|
'button t
|
||||||
|
'button-data url
|
||||||
|
'category t
|
||||||
|
'face 'button
|
||||||
|
'follow-link t
|
||||||
|
'help-echo url
|
||||||
|
'keymap button-map
|
||||||
|
'mouse-face 'highlight)
|
||||||
|
(propertize " "
|
||||||
|
'display '(space :relative-height 1.5)))))
|
||||||
|
|
||||||
;;;;; Org format sending
|
;;;;; Org format sending
|
||||||
|
|
||||||
;; Some of these declarations may need updating as Org changes.
|
;; Some of these declarations may need updating as Org changes.
|
||||||
|
|
Loading…
Add table
Reference in a new issue