From 79158bd0fd0c67aab90f8ae52d4f90b4b167be22 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Nov 2022 15:38:21 +0100 Subject: wholly remove parent-toot; use base-toot/-id only the confusion came from the three different types of statuses we often encounter: - toot - boost/fave - notification (of boost/fave/mention) in notifications, we can't just use -tl--toot-id. it will return the notif's id, not the base toot's. so we do still fetch base-toot JSON (formerly 'parent-toot prop), and get base-toot-id from there, else from toot JSON. --- lisp/mastodon-tl.el | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3f5dd04..bd2f9d6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -938,7 +938,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--media toot)))) (defun mastodon-tl--insert-status (toot body author-byline action-byline - &optional id parent-toot detailed-p) + &optional id base-toot detailed-p) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -950,9 +950,10 @@ such as boosting favouriting and following to the byline. It also takes a single function. By default it is `mastodon-tl--byline-boosted'. -ID is that of the toot, which is attached as a property if it is -a notification. If the status is a favourite or a boost, -PARENT-TOOT is the JSON of the toot responded to. +ID is that of the status if it is a notification, which is +attached as a `toot-id' property if provided. If the +status is a favourite or boost notification, BASE-TOOT is the +JSON of the toot responded to. DETAILED-P means display more detailed info. For now this just means displaying toot client." @@ -963,13 +964,16 @@ this just means displaying toot client." body " \n" (mastodon-tl--byline toot author-byline action-byline detailed-p)) - 'toot-id (or id ; for notifications - (alist-get 'id toot)) + 'toot-id (or id ; notification's own id + (alist-get 'id toot)) ; toot id 'base-toot-id (mastodon-tl--toot-id - ;; if a favourite/boost notif, get ID of toot responded to: - (or parent-toot toot)) + ;; if status is a notif, get id from base-toot + ;; (-tl--toot-id toot) will not work here: + (or base-toot + ;; else normal toot with reblog check: + toot)) 'toot-json toot - 'parent-toot parent-toot) + 'base-toot base-toot) "\n") (when mastodon-tl--display-media-p (mastodon-media--inline-images start-pos (point))))) @@ -1268,20 +1272,11 @@ webapp" (reblog (alist-get 'reblog json))) (if reblog (alist-get 'id reblog) id))) -(defun mastodon-tl--single-toot (&optional id) +(defun mastodon-tl--single-toot (id) "View toot at point in separate buffer. ID is that of the toot to view." (interactive) - (let* ((id - (or id - (if (equal (mastodon-tl--get-endpoint) "notifications") - ;; for boosts/faves: - (if (mastodon-tl--property 'parent-toot) - (mastodon-tl--as-string (mastodon-tl--toot-id - (mastodon-tl--property 'parent-toot))) - (mastodon-tl--property 'base-toot-id)) - (mastodon-tl--property 'base-toot-id)))) - (buffer (format "*mastodon-toot-%s*" id)) + (let* ((buffer (format "*mastodon-toot-%s*" id)) (toot (mastodon-http--get-json (mastodon-http--api (concat "statuses/" id))))) (if (equal (caar toot) 'error) @@ -1300,13 +1295,10 @@ ID is that of the toot to view." (interactive) (let* ((id (or id - (if (equal (mastodon-tl--get-endpoint) "notifications") - ;; for boosts/faves: - (if (mastodon-tl--property 'parent-toot) - (mastodon-tl--as-string (mastodon-tl--toot-id - (mastodon-tl--property 'parent-toot))) - (mastodon-tl--property 'base-toot-id)) - (mastodon-tl--property 'base-toot-id)))) + ;; avoid -tl--property here, we don't want to try next toot: + ;; this requires that 'base-toot-id always be set: + (get-text-property (point) 'base-toot-id) + )) (url (mastodon-http--api (format "statuses/%s/context" id))) (buffer (format "*mastodon-thread-%s*" id)) (toot -- cgit v1.2.3 From 32939e5ea4d44b05a4136b9cda64ff3d21728750 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Nov 2022 17:30:55 +0100 Subject: don't try to load thread if status at point is foll_req --- lisp/mastodon-tl.el | 80 +++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index bd2f9d6..355c215 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1297,45 +1297,47 @@ ID is that of the toot to view." (or id ;; avoid -tl--property here, we don't want to try next toot: ;; this requires that 'base-toot-id always be set: - (get-text-property (point) 'base-toot-id) - )) - (url (mastodon-http--api (format "statuses/%s/context" id))) - (buffer (format "*mastodon-thread-%s*" id)) - (toot - ;; refetch current toot in case we just faved/boosted: - (mastodon-http--get-json - (mastodon-http--api (concat "statuses/" id)) - :silent)) - (context (mastodon-http--get-json url :silent)) - (marker (make-marker))) - (if (equal (caar toot) 'error) - (message "Error: %s" (cdar toot)) - (when (member (alist-get 'type toot) '("reblog" "favourite")) - (setq toot (alist-get 'status toot))) - (if (> (+ (length (alist-get 'ancestors context)) - (length (alist-get 'descendants context))) - 0) - ;; if we have a thread: - (progn - (with-output-to-temp-buffer buffer - (switch-to-buffer buffer) - (mastodon-mode) - (mastodon-tl--set-buffer-spec - buffer - (format "statuses/%s/context" id) - (lambda (_toot) (message "END of thread."))) - (let ((inhibit-read-only t)) - (mastodon-tl--timeline (alist-get 'ancestors context)) - (goto-char (point-max)) - (move-marker marker (point)) - ;; print re-fetched toot: - (mastodon-tl--toot toot :detailed-p) - (mastodon-tl--timeline (alist-get 'descendants context)))) - ;; put point at the toot: - (goto-char (marker-position marker)) - (mastodon-tl--goto-next-toot)) - ;; else just print the lone toot: - (mastodon-tl--single-toot id))))) + (get-text-property (point) 'base-toot-id))) + (type (mastodon-tl--field 'type (mastodon-tl--property 'toot-json)))) + (if (string= type "follow_request") ; no can thread this + (error "No thread") + (let* ((url (mastodon-http--api (format "statuses/%s/context" id))) + (buffer (format "*mastodon-thread-%s*" id)) + (toot + ;; refetch current toot in case we just faved/boosted: + (mastodon-http--get-json + (mastodon-http--api (concat "statuses/" id)) + :silent)) + (context (mastodon-http--get-json url :silent)) + (marker (make-marker))) + (if (equal (caar toot) 'error) + (message "Error: %s" (cdar toot)) + (when (member (alist-get 'type toot) '("reblog" "favourite")) + (setq toot (alist-get 'status toot))) + (if (> (+ (length (alist-get 'ancestors context)) + (length (alist-get 'descendants context))) + 0) + ;; if we have a thread: + (progn + (with-output-to-temp-buffer buffer + (switch-to-buffer buffer) + (mastodon-mode) + (mastodon-tl--set-buffer-spec + buffer + (format "statuses/%s/context" id) + (lambda (_toot) (message "END of thread."))) + (let ((inhibit-read-only t)) + (mastodon-tl--timeline (alist-get 'ancestors context)) + (goto-char (point-max)) + (move-marker marker (point)) + ;; print re-fetched toot: + (mastodon-tl--toot toot :detailed-p) + (mastodon-tl--timeline (alist-get 'descendants context)))) + ;; put point at the toot: + (goto-char (marker-position marker)) + (mastodon-tl--goto-next-toot)) + ;; else just print the lone toot: + (mastodon-tl--single-toot id))))))) (defun mastodon-tl--create-filter () "Create a filter for a word. -- cgit v1.2.3