From 0368d42c1f481cee74c42e3137598f54dccb9979 Mon Sep 17 00:00:00 2001 From: "Ivan I. Ovchinnikov" Date: Mon, 23 Nov 2026 09:09:32 +0300 Subject: [PATCH] forgotten file --- lisp/mattermost-files.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lisp/mattermost-files.el diff --git a/lisp/mattermost-files.el b/lisp/mattermost-files.el new file mode 100644 index 0000000..312ad75 --- /dev/null +++ b/lisp/mattermost-files.el @@ -0,0 +1,30 @@ +;;; mattermost-files.el --- File attachment helpers -*- lexical-binding: t; -*- + +(require 'mattermost-custom) +(require 'mattermost-protocol) + +(defun mattermost--format-file-size (bytes) + "Format BYTES as human-readable size." + (cond + ((< bytes 1024) (format "%d B" bytes)) + ((< bytes (* 1024 1024)) (format "%.1f KB" (/ bytes 1024.0))) + ((< bytes (* 1024 1024 1024)) (format "%.1f MB" (/ bytes (* 1024.0 1024.0)))) + (t (format "%.1f GB" (/ bytes (* 1024.0 1024.0 1024.0)))))) + +(defun mattermost--format-file-block (files) + "Return a propertized multi-line string describing FILES plist list." + (mapconcat + (lambda (f) + (let* ((name (or (plist-get f :name) "unknown")) + (size (or (plist-get f :size) 0)) + (id (plist-get f :id))) + (propertize + (format " 📎 %s (%s)\n" name (mattermost--format-file-size size)) + 'mm-file-id id + 'mm-file-name name + 'mouse-face 'highlight + 'help-echo "RET to download and open"))) + files + "")) + +(provide 'mattermost-files)