emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/mastodon babb3a1adf 28/50: fold-toot - respect CW state


From: ELPA Syncer
Subject: [nongnu] elpa/mastodon babb3a1adf 28/50: fold-toot - respect CW state
Date: Sat, 2 Nov 2024 13:00:54 -0400 (EDT)

branch: elpa/mastodon
commit babb3a1adf7dbc2c458c65d841e758aafaabd298
Author: marty hiatt <martianhiatus@disroot.org>
Commit: marty hiatt <martianhiatus@disroot.org>

    fold-toot - respect CW state
---
 lisp/mastodon-tl.el | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 5178a25721..b655bec41f 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1772,15 +1772,18 @@ title, and context."
     (mastodon-tl--filter-by-context context filters-no-context)))
 
 (defun mastodon-tl--toot (toot &optional detailed-p thread domain
-                               unfolded no-byline)
+                               unfolded no-byline no-cw)
   "Format TOOT and insert it into the buffer.
 DETAILED-P means display more detailed info. For now
 this just means displaying toot client.
 THREAD means the status will be displayed in a thread view.
 When DOMAIN, force inclusion of user's domain in their handle.
 UNFOLDED is a boolean meaning whether to unfold or fold item if foldable.
-NO-BYLINE means just insert toot body, used for folding."
-  (let* ((filtered (mastodon-tl--field 'filtered toot))
+NO-BYLINE means just insert toot body, used for folding.
+NO-CW means treat content warnings as unfolded."
+  (let* ((mastodon-tl--expand-content-warnings
+          (or no-cw mastodon-tl--expand-content-warnings))
+         (filtered (mastodon-tl--field 'filtered toot))
          (filters (when filtered
                     (mastodon-tl--current-filters filtered)))
          (spoiler-or-content (if-let ((match (assoc "warn" filters)))
@@ -1826,9 +1829,14 @@ When DOMAIN, force inclusion of user's domain in their 
handle."
 (defun mastodon-tl--fold-body (body)
   "Fold toot BODY if it is very long.
 Folding decided by `mastodon-tl--fold-toots-at-length'."
-  (let* ((heading (mastodon-search--format-heading
-                   (mastodon-tl--make-link "READ MORE" 'read-more)
-                   nil :no-newline))
+  (let* ((invis (get-text-property (1- (length body)) 'invisible body))
+         (spoiler (get-text-property (1- (length body))
+                                     'mastodon-content-warning-body body))
+         (heading (propertize (mastodon-search--format-heading
+                               (mastodon-tl--make-link "READ MORE" 'read-more)
+                               nil :no-newline)
+                              'mastodon-content-warning-body spoiler
+                              'invisible invis))
          (display (concat (substring body 0
                                      mastodon-tl--fold-toots-at-length)
                           heading)))
@@ -1848,6 +1856,10 @@ FOLD means to fold it instead."
       (let* ((inhibit-read-only t)
              (body-range (mastodon-tl--find-property-range 'toot-body
                                                            (point) :backward))
+             (cw-range (mastodon-tl--find-property-range
+                        'mastodon-content-warning-body
+                        (point) :backward))
+             (cw-invis (get-text-property (car cw-range) 'invisible))
              (toot (mastodon-tl--property 'item-json :no-move))
              ;; `replace-region-contents' is much too slow, our hack from
              ;; fedi.el is much simpler and much faster:
@@ -1863,7 +1875,8 @@ FOLD means to fold it instead."
         (delete-region beg end)
         (delete-char 1) ;; prevent newlines accumulating
         ;; insert toot body:
-        (mastodon-tl--toot toot nil nil nil (not fold) :no-byline)
+        (mastodon-tl--toot toot nil nil nil (not fold) :no-byline
+                           (unless cw-invis :no-cw)) ;; respect CW state
         ;; set toot-folded prop on entire toot (not just body):
         (let ((toot-range ;; post fold action range:
                (mastodon-tl--find-property-range 'item-json



reply via email to

[Prev in Thread] Current Thread [Next in Thread]