diff options
author | Alexander Griffith <griffitaj@gmail.com> | 2017-04-23 23:44:06 -0400 |
---|---|---|
committer | Johnson Denen <johnson.denen@gmail.com> | 2017-04-24 23:18:59 -0400 |
commit | bfc9f6217ba414b9f376d5032a4a12118ba72b2a (patch) | |
tree | 460dfa4321465455baf850ceacb56ff1e3573d58 | |
parent | 3cb5a6a9be2811b63a254d1c00b7ba30460d7629 (diff) |
Added content warnings and inserted media links into toots
-rw-r--r-- | lisp/mastodon-tl.el | 40 |
1 files changed, 40 insertions, 0 deletions
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"))) |