Add: Format m.file events

This commit is contained in:
Adam Porter 2022-05-02 05:59:47 -05:00
parent b3b1bd84b0
commit 6dc47f683c

View file

@ -2948,7 +2948,9 @@ If FORMATTED-P, return the formatted body content, when available."
(or new-content-format content-format) body)))))
(appendix (pcase msgtype
("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
;; HACK: Once I got an error when body was nil, so let's avoid that.
(setf body (ement-room--linkify-urls body)))
@ -3543,6 +3545,31 @@ Then invalidate EVENT's node to show the image."
(lambda (node-data)
(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
;; Some of these declarations may need updating as Org changes.