From bfc9f6217ba414b9f376d5032a4a12118ba72b2a Mon Sep 17 00:00:00 2001 From: Alexander Griffith Date: Sun, 23 Apr 2017 23:44:06 -0400 Subject: Added content warnings and inserted media links into toots --- lisp/mastodon-tl.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1c6117b..2d323b9 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -143,6 +143,44 @@ Return value from boosted content if available." 'toot-id id 'toot-json toot))) + +(defun mastodon-tl--set-face (string face render) + "Set the face of a string. If `render` is not 'nil +also render the html" + (propertize + (with-temp-buffer + (insert (decode-coding-string string 'utf-8)) + (when render + (shr-render-region (point-min) (point-max))) + (buffer-string)) + 'face face)) + +(defun mastodon-tl--spoiler (toot) + "Retrieve spoiler message from TOOT." + (let* ((spoiler (mastodon-tl--field 'spoiler_text toot)) + (string (mastodon-tl--set-face spoiler 'default t)) + (message (concat "\n ---------------" + "\n Content Warning" + "\n ---------------\n")) + (cw (mastodon-tl--set-face message 'success 'nil))) + (if (> (length string) 0) + (replace-regexp-in-string "\n\n\n ---------------" + "\n ---------------" (concat string cw)) + ""))) + + +(defun mastodon-tl--media (toot) + "Retreive a media attachment link if one exits" + (let ((media (mastodon-tl--field 'media_attachments toot))) + (if(> (length media) 0 ) + ;; Extract the preview_url, other options here + ;; are url and remote_url + (let ((link (cdr(assoc 'preview_url (elt media 0))))) + (concat "Media_Link:: " + (mastodon-tl--set-face link 'mouse-face 'nil))) + ;; Otherwise return an empty string + ""))) + (defun mastodon-tl--content (toot) "Retrieve text content from TOOT." (let ((content (mastodon-tl--field 'content toot))) @@ -156,7 +194,9 @@ Return value from boosted content if available." "Display TOOT content and byline." (insert (concat + (mastodon-tl--spoiler toot) (mastodon-tl--content toot) + (mastodon-tl--media toot) (mastodon-tl--byline toot) "\n\n"))) -- cgit v1.2.3