diff options
-rw-r--r-- | README.org | 1 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 34 | ||||
-rw-r--r-- | lisp/mastodon.el | 2 | ||||
-rw-r--r-- | test/mastodon-tl-tests.el | 21 |
4 files changed, 50 insertions, 8 deletions
@@ -77,6 +77,7 @@ Opens a =*mastodon-home*= buffer in the major mode so you can see toots. You wil | Key | Action | |--------------------------+-----------------------------------------------------------------------------------| | =?= | Open context menu (if =discover= is available) | +| =c= | Toggle the visibility of sensitive text (if there is text with a content warning) | | =b= | Boost toot under =point= | | =f= | Favourite toot under =point= | | =F= | Open federated timeline | 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) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 7f02295..c362513 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -41,6 +41,7 @@ (autoload 'mastodon-tl--next-tab-item "mastodon-tl") (autoload 'mastodon-tl--previous-tab-item "mastodon-tl") (autoload 'mastodon-tl--thread "mastodon-tl") +(autoload 'mastodon-tl--toggle-spoiler-text-in-toot "mastodon-tl") (autoload 'mastodon-tl--update "mastodon-tl") (autoload 'mastodon-toot--compose-buffer "mastodon-toot") (autoload 'mastodon-toot--reply "mastodon-toot") @@ -120,6 +121,7 @@ If REPLY-TO-ID is non-nil, attach new toot to a conversation." "Major mode for Mastodon, the federated microblogging network." :group 'mastodon (let ((map mastodon-mode-map)) + (define-key map (kbd "c") #'mastodon-tl--toggle-spoiler-text-in-toot) (define-key map (kbd "b") #'mastodon-toot--toggle-boost) (define-key map (kbd "f") #'mastodon-toot--toggle-favourite) (define-key map (kbd "F") #'mastodon-tl--get-federated-timeline) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index 04f00e5..1a10614 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -817,6 +817,10 @@ constant." (mastodon-tl--spoiler normal-toot-with-spoiler))) (setq toot-end (point)) (insert "\nsome more text.") + (add-text-properties + toot-start toot-end + (list 'toot-json normal-toot-with-spoiler + 'toot-id (cdr (assoc 'id normal-toot-with-spoiler)))) (goto-char toot-start) (should (eq t (looking-at "This is the spoiler warning text"))) @@ -843,7 +847,22 @@ constant." (mastodon-tl--do-link-action-at-point (car link-region)) ;; The body is invisible again: - (should (eq t (get-text-property body-position 'invisible)))))) + (should (eq t (get-text-property body-position 'invisible))) + + ;; Go back to the toot's beginning + (goto-char toot-start) + ;; Press 'c' and the body is visible again and point hasn't changed: + (mastodon-tl--toggle-spoiler-text-in-toot) + (should (eq nil (get-text-property body-position 'invisible))) + (should (eq toot-start (point))) + + ;; Go to the toot's end + (goto-char toot-end) + ;; Press 'c' and the body is invisible again and point hasn't changed: + (mastodon-tl--toggle-spoiler-text-in-toot) + (should (eq t (get-text-property body-position 'invisible))) + (should (eq toot-end (point))) + ))) (ert-deftest mastodon-tl--hashtag () "Should recognise hashtags in a toot and add the required properties to it." |