diff options
author | H Durer <h.duerer@gmail.com> | 2018-03-10 06:04:13 +0000 |
---|---|---|
committer | Johnson Denen <johnson.denen@gmail.com> | 2018-08-10 22:20:04 -0400 |
commit | 1e7882a709ac1d67b2ff1ec17577637b70571b6a (patch) | |
tree | acd9c1c68b67829f702ee14b7c4355706ae69513 /lisp/mastodon-tl.el | |
parent | 967d2835da2a77a0f4935a2392f667e0330608c8 (diff) |
Support toggling content warning anywhere in the toot. (#180)
This new functionality is bound to the 'c' key.
To help with this functionality this also changes the 'toot-json and 'toot-id properties. These are now applied to the whole toot not just the toot's byline.
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r-- | lisp/mastodon-tl.el | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4865b4f..ee7c48d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -337,8 +337,7 @@ the byline that takes one variable. ACTION-BYLINE is a function for adding an action, such as boosting favouriting and following to the byline. It also takes a single function. By default it is `mastodon-tl--byline-boosted'" - (let ((id (cdr (assoc 'id toot))) - (parsed-time (date-to-time (mastodon-tl--field 'created_at toot))) + (let ((parsed-time (date-to-time (mastodon-tl--field 'created_at toot))) (faved (equal 't (mastodon-tl--field 'favourited toot))) (boosted (equal 't (mastodon-tl--field 'reblogged toot)))) (concat @@ -363,9 +362,7 @@ it is `mastodon-tl--byline-boosted'" parsed-time)) (propertize "\n ------------" 'face 'default)) 'favourited-p faved - 'boosted-p boosted - 'toot-id id - 'toot-json toot)))) + 'boosted-p boosted)))) (defun mastodon-tl--render-text (string toot) "Returns a propertized text giving the rendering of the given HTML string STRING. @@ -454,6 +451,26 @@ the toot)." (list 'invisible (not (get-text-property (car spoiler-text-region) 'invisible))))))) + +(defun mastodon-tl--toggle-spoiler-text-in-toot () + "Toggle the visibility of the spoiler text in the current toot." + (interactive) + (let* ((toot-range (or (mastodon-tl--find-property-range + 'toot-json (point)) + (mastodon-tl--find-property-range + 'toot-json (point) t))) + (spoiler-range (when toot-range + (mastodon-tl--find-property-range + 'mastodon-content-warning-body + (car toot-range))))) + (cond ((null toot-range) + (message "No toot here")) + ((or (null spoiler-range) + (> (car spoiler-range) (cdr toot-range))) + (message "No content warning text here")) + (t + (mastodon-tl--toggle-spoiler-text (car spoiler-range)))))) + (defun mastodon-tl--make-link (string link-type) "Return a propertized version of STRING that will act like link. @@ -551,8 +568,11 @@ ACTION-BYLINE is also an optional function for adding an action, such as boostin favouriting and following to the byline. It also takes a single function. By default it is `mastodon-tl--byline-boosted'" (insert - body - (mastodon-tl--byline toot author-byline action-byline) + (propertize + (concat body + (mastodon-tl--byline toot author-byline action-byline)) + 'toot-id (cdr (assoc 'id toot)) + 'toot-json toot) "\n\n")) (defun mastodon-tl--toot(toot) |