From e7435eddc825beae3e9d68c4aba8ee08179e41f6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 11 Jan 2023 10:47:58 +1100 Subject: add funs --get-buffer-type and --has-toots-p still need to actually use these in the codebase tho --- lisp/mastodon-tl.el | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a86a7e6..d41e403 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1411,6 +1411,76 @@ UPDATE-PARAMS is any http parameters needed for the update function." link-header ,link-header update-params ,update-params))) +(defun mastodon-tl--get-buffer-type () + "Return a symbol descriptive of current mastodon buffer type. +Should work in all mastodon buffers." + (cond (mastodon-toot-mode + 'compose-toot) + ;; main timelines: + ((string= "timelines/home" (mastodon-tl--get-endpoint)) + 'home) + ((string= "timelines/public" (mastodon-tl--get-endpoint)) + 'federated) + ((string= "*mastodon-local*" (mastodon-tl--buffer-name)) + 'local) + ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) + 'tag-timeline) + ;; notifs: + ((string= "notifications" (mastodon-tl--get-endpoint)) + 'notifications) + ;; NB: check for mentions/filtering + ;; threads: + ((string-suffix-p "context" (mastodon-tl--get-endpoint)) + 'thread) + ;; profiles: + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (cond ; posts + ((string-suffix-p "statuses" (mastodon-tl--get-endpoint)) + 'profile-statuses) + ;; profile followers + ((string-suffix-p "followers" (mastodon-tl--get-endpoint)) + 'profile-followers) + ;; profile following + ((string-suffix-p "following" (mastodon-tl--get-endpoint)) + 'profile-following))) + ;; search + ((string-suffix-p "search" (mastodon-tl--get-endpoint)) + 'search) + ((string-suffix-p "trends" (mastodon-tl--get-endpoint)) + 'trending-tags) + ;; User's views: + ((string= "filters" (mastodon-tl--get-endpoint)) + 'filters) + ((string-prefix-p "lists" (mastodon-tl--get-endpoint)) + 'lists) + ((string= "suggestions" (mastodon-tl--get-endpoint)) + 'follow-suggestions) + ((string= "favourites" (mastodon-tl--get-endpoint)) + 'favourites) + ((string= "bookmarks" (mastodon-tl--get-endpoint)) + 'bookmarks) + ((string= "follow_requests" (mastodon-tl--get-endpoint)) + 'follow-requests) + ;; profile note + ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) + 'update-profile-note) + ;; instance description + ((string= "instance" (mastodon-tl--get-endpoint)) + 'instance-description))) + +(defun mastodon-tl--has-toots-p () + "Return non-nil if the current buffer contains toots. +Return value is that of `member'. +This is used to avoid running into trouble using functions that +presume we are in a timline of toots or similar elements, such as +`mastodon-tl--property'." + (let ((toot-buffers + '(home federated local tag-timeline notifications + thread profile-statuses search trending-tags bookmarks + favourites))) + ;; profile-followers profile following + (member (mastodon-tl--get-buffer-type) toot-buffers))) + (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) -- cgit v1.2.3 From 69dcaa6136a31553674f85fc6f1536a2167e1307 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 14 Jan 2023 07:20:14 +0100 Subject: add list timelines and scheduled statuses to --get-buffer-type --- lisp/mastodon-tl.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d41e403..732e1c0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1425,6 +1425,8 @@ Should work in all mastodon buffers." 'local) ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) 'tag-timeline) + ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint)) + 'tag-timeline) ;; notifs: ((string= "notifications" (mastodon-tl--get-endpoint)) 'notifications) @@ -1451,7 +1453,7 @@ Should work in all mastodon buffers." ;; User's views: ((string= "filters" (mastodon-tl--get-endpoint)) 'filters) - ((string-prefix-p "lists" (mastodon-tl--get-endpoint)) + ((string= "lists" (mastodon-tl--get-endpoint)) 'lists) ((string= "suggestions" (mastodon-tl--get-endpoint)) 'follow-suggestions) @@ -1461,9 +1463,11 @@ Should work in all mastodon buffers." 'bookmarks) ((string= "follow_requests" (mastodon-tl--get-endpoint)) 'follow-requests) + ((string= "scheduled_statuses" (mastodon-tl--get-endpoint)) + 'scheduled-statuses) ;; profile note ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) - 'update-profile-note) + 'update-profile-note) ;; instance description ((string= "instance" (mastodon-tl--get-endpoint)) 'instance-description))) -- cgit v1.2.3 From c1731fda740af4850109531b2fd1ebd9dee3a07d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 14 Jan 2023 09:16:02 +0100 Subject: add fun --timeline-proper-p --- lisp/mastodon-tl.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 732e1c0..a240f67 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1485,6 +1485,13 @@ presume we are in a timline of toots or similar elements, such as ;; profile-followers profile following (member (mastodon-tl--get-buffer-type) toot-buffers))) +(defun mastodon-tl--timeline-proper-p () + "Return non-nil if the current buffer is a 'proper' timeline. +A proper timeline excludes notifications, threads, and other toot +buffers that aren't strictly mastodon timelines." + (let ((timeline-buffers '(home federated local tag-timeline profile-statuses))) + (member (mastodon-tl--get-buffer-type) timeline-buffers))) + (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) -- cgit v1.2.3 From c7ba4d7739e578d7983c3338ac9fbc198a377f49 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 14 Jan 2023 14:42:32 +0100 Subject: remove insert call in toot--most-restritive-vis --- lisp/mastodon-toot.el | 1 - 1 file changed, 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 0d733bd..bff6677 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1362,7 +1362,6 @@ The default is given by `mastodon-toot--default-reply-visibility'." (unless (null reply-visibility) (let ((less-restrictive (member (intern mastodon-toot--default-reply-visibility) mastodon-toot-visibility-list))) - (insert (format "%s" reply-visibility)) (if (member (intern reply-visibility) less-restrictive) mastodon-toot--default-reply-visibility reply-visibility)))) -- cgit v1.2.3 From 3506668a6ab9449816c46f827f249ebd2a5d8ac9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:18:55 +0100 Subject: fix set buffer-spec for instance-description --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a240f67..31ef328 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2240,9 +2240,6 @@ INSTANCE is an instance domain name." (let ((buf (get-buffer-create "*mastodon-instance*"))) (with-current-buffer buf (switch-to-buffer-other-window buf) - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) (let ((inhibit-read-only t)) (erase-buffer) (special-mode) @@ -2260,6 +2257,9 @@ INSTANCE is an instance domain name." (assoc 'stats response)))) (mastodon-tl--print-json-keys response) (mastodon-mode) + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) (goto-char (point-min))))))))) (defun mastodon-tl--format-key (el pad) -- cgit v1.2.3 From 8214f35db91aca0f71dfdb15b0e42a511f31fb61 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:19:15 +0100 Subject: fix set buffer spec buffer name for trending tags --- lisp/mastodon-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 24ddfb3..0f2a6d4 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -94,7 +94,7 @@ QUERY is the string to search." (mastodon-mode) (let ((inhibit-read-only t)) (erase-buffer) - (mastodon-tl--set-buffer-spec buffer + (mastodon-tl--set-buffer-spec (buffer-name buffer) "api/v1/trends" nil) ;; hashtag results: -- cgit v1.2.3 From b1a3fd043383b4c19ca3bae21d965365c565be15 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:19:39 +0100 Subject: make sure get-buffer-type really works in all views --- lisp/mastodon-tl.el | 68 +++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 31ef328..36511ef 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1365,15 +1365,15 @@ this just means displaying toot client." Optionally get it for BUFFER." (mastodon-tl--get-buffer-property 'update-function buffer)) -(defun mastodon-tl--get-endpoint (&optional buffer) +(defun mastodon-tl--get-endpoint (&optional buffer no-error) "Get the ENDPOINT stored in `mastodon-tl--buffer-spec'. Optionally set it for BUFFER." - (mastodon-tl--get-buffer-property 'endpoint buffer)) + (mastodon-tl--get-buffer-property 'endpoint buffer no-error)) -(defun mastodon-tl--buffer-name (&optional buffer) +(defun mastodon-tl--buffer-name (&optional buffer no-error) "Get the BUFFER-NAME stored in `mastodon-tl--buffer-spec'. Optionally get it for BUFFER." - (mastodon-tl--get-buffer-property 'buffer-name buffer)) + (mastodon-tl--get-buffer-property 'buffer-name buffer no-error)) (defun mastodon-tl--link-header (&optional buffer) "Get the LINK HEADER stored in `mastodon-tl--buffer-spec'. @@ -1417,59 +1417,61 @@ Should work in all mastodon buffers." (cond (mastodon-toot-mode 'compose-toot) ;; main timelines: - ((string= "timelines/home" (mastodon-tl--get-endpoint)) + ((string= "timelines/home" (mastodon-tl--get-endpoint nil :no-error)) 'home) - ((string= "timelines/public" (mastodon-tl--get-endpoint)) - 'federated) - ((string= "*mastodon-local*" (mastodon-tl--buffer-name)) + ((string= "*mastodon-local*" (mastodon-tl--buffer-name nil :no-error)) 'local) - ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) - 'tag-timeline) - ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint)) + ((string= "timelines/public" (mastodon-tl--get-endpoint nil :no-error)) + 'federated) + ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint nil :no-error)) 'tag-timeline) + ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint nil :no-error)) + 'list-timeline) ;; notifs: - ((string= "notifications" (mastodon-tl--get-endpoint)) + ((string-suffix-p "mentions*" (mastodon-tl--buffer-name nil :no-error)) + 'mentions) + ((string= "notifications" (mastodon-tl--get-endpoint nil :no-error)) 'notifications) - ;; NB: check for mentions/filtering ;; threads: - ((string-suffix-p "context" (mastodon-tl--get-endpoint)) + ((string-suffix-p "context" (mastodon-tl--get-endpoint nil :no-error)) 'thread) ;; profiles: - ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (cond ; posts - ((string-suffix-p "statuses" (mastodon-tl--get-endpoint)) + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint nil :no-error)) + (cond + ;; profile note: + ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name nil :no-error)) + 'update-profile-note) + ;; posts + ((string-suffix-p "statuses" (mastodon-tl--get-endpoint nil :no-error)) 'profile-statuses) ;; profile followers - ((string-suffix-p "followers" (mastodon-tl--get-endpoint)) + ((string-suffix-p "followers" (mastodon-tl--get-endpoint nil :no-error)) 'profile-followers) ;; profile following - ((string-suffix-p "following" (mastodon-tl--get-endpoint)) + ((string-suffix-p "following" (mastodon-tl--get-endpoint nil :no-error)) 'profile-following))) ;; search - ((string-suffix-p "search" (mastodon-tl--get-endpoint)) + ((string-suffix-p "search" (mastodon-tl--get-endpoint nil :no-error)) 'search) - ((string-suffix-p "trends" (mastodon-tl--get-endpoint)) + ((string-suffix-p "trends" (mastodon-tl--get-endpoint nil :no-error)) 'trending-tags) ;; User's views: - ((string= "filters" (mastodon-tl--get-endpoint)) + ((string= "filters" (mastodon-tl--get-endpoint nil :no-error)) 'filters) - ((string= "lists" (mastodon-tl--get-endpoint)) - 'lists) - ((string= "suggestions" (mastodon-tl--get-endpoint)) + ((string= "lists" (mastodon-tl--get-endpoint nil :no-error)) + 'lists-view) + ((string= "suggestions" (mastodon-tl--get-endpoint nil :no-error)) 'follow-suggestions) - ((string= "favourites" (mastodon-tl--get-endpoint)) + ((string= "favourites" (mastodon-tl--get-endpoint nil :no-error)) 'favourites) - ((string= "bookmarks" (mastodon-tl--get-endpoint)) + ((string= "bookmarks" (mastodon-tl--get-endpoint nil :no-error)) 'bookmarks) - ((string= "follow_requests" (mastodon-tl--get-endpoint)) + ((string= "follow_requests" (mastodon-tl--get-endpoint nil :no-error)) 'follow-requests) - ((string= "scheduled_statuses" (mastodon-tl--get-endpoint)) + ((string= "scheduled_statuses" (mastodon-tl--get-endpoint nil :no-error)) 'scheduled-statuses) - ;; profile note - ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) - 'update-profile-note) ;; instance description - ((string= "instance" (mastodon-tl--get-endpoint)) + ((string= "instance" (mastodon-tl--get-endpoint nil :no-error)) 'instance-description))) (defun mastodon-tl--has-toots-p () -- cgit v1.2.3