aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-01-15 08:20:17 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-01-15 08:20:17 +0100
commita4cce2f6c8f46b5b233c6096474ca4cdbb963150 (patch)
treea8eccba133dcfe46d6ce11802bfab4e4388da0ca
parent63edb7d5a2cae579d7e076398057e7a83cfa1888 (diff)
parentb1a3fd043383b4c19ca3bae21d965365c565be15 (diff)
Merge branch 'buffer-type-has-toots' into develop
-rw-r--r--lisp/mastodon-search.el2
-rw-r--r--lisp/mastodon-tl.el97
2 files changed, 91 insertions, 8 deletions
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:
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 7ca0ddd..b7054f5 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'.
@@ -1411,6 +1411,89 @@ 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 nil :no-error))
+ 'home)
+ ((string= "*mastodon-local*" (mastodon-tl--buffer-name nil :no-error))
+ 'local)
+ ((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-suffix-p "mentions*" (mastodon-tl--buffer-name nil :no-error))
+ 'mentions)
+ ((string= "notifications" (mastodon-tl--get-endpoint nil :no-error))
+ 'notifications)
+ ;; threads:
+ ((string-suffix-p "context" (mastodon-tl--get-endpoint nil :no-error))
+ 'thread)
+ ;; profiles:
+ ((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 nil :no-error))
+ 'profile-followers)
+ ;; profile following
+ ((string-suffix-p "following" (mastodon-tl--get-endpoint nil :no-error))
+ 'profile-following)))
+ ;; search
+ ((string-suffix-p "search" (mastodon-tl--get-endpoint nil :no-error))
+ 'search)
+ ((string-suffix-p "trends" (mastodon-tl--get-endpoint nil :no-error))
+ 'trending-tags)
+ ;; User's views:
+ ((string= "filters" (mastodon-tl--get-endpoint nil :no-error))
+ 'filters)
+ ((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 nil :no-error))
+ 'favourites)
+ ((string= "bookmarks" (mastodon-tl--get-endpoint nil :no-error))
+ 'bookmarks)
+ ((string= "follow_requests" (mastodon-tl--get-endpoint nil :no-error))
+ 'follow-requests)
+ ((string= "scheduled_statuses" (mastodon-tl--get-endpoint nil :no-error))
+ 'scheduled-statuses)
+ ;; instance description
+ ((string= "instance" (mastodon-tl--get-endpoint nil :no-error))
+ '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--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))))
@@ -2159,9 +2242,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)
@@ -2179,6 +2259,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)