diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-03-29 16:51:21 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-03-29 17:15:35 +0200 |
commit | ded80d1dff2d80c3be659f569f067a7ec4633c97 (patch) | |
tree | 1249d740221452ff1a3a5e91f6aa778abed930ed /lisp | |
parent | 4b66cea2086e477e529d805b6cf0633e31acfe3c (diff) |
refactor trending-tags to view-trending, add trending-statuses
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-search.el | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index e8ab093..bc51d22 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -40,10 +40,13 @@ (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-tl--set-buffer-spec "mastodon-tl") (autoload 'mastodon-tl--set-face "mastodon-tl") +(autoload 'mastodon-tl--timeline "mastodon-tl") +(autoload 'mastodon-tl--toot "mastodon-tl") (defvar mastodon-toot--completion-style-for-mentions) (defvar mastodon-instance-url) (defvar mastodon-tl--link-keymap) +(defvar mastodon-tl--horiz-bar) ;; functions for completion of mentions in mastodon-toot @@ -81,26 +84,53 @@ QUERY is the string to search." (defun mastodon-search--trending-tags () "Display a list of tags trending on your instance." (interactive) - (let* ((url (mastodon-http--api "trends")) + (mastodon-search--view-trending "tags" + #'mastodon-search--print-tags-list)) + +(defun mastodon-search--trending-statuses () + "Display a list of statuses trending on your instance." + (interactive) + (mastodon-search--view-trending "statuses" + #'mastodon-tl--timeline)) + +(defun mastodon-search--get-full-statuses-data (response) + "For statuses list in RESPONSE, fetch and return full status JSON." + (let ((status-ids-list + (mapcar #'mastodon-search--get-id-from-status response))) + (mapcar #'mastodon-search--fetch-full-status-from-id + status-ids-list))) + +(defun mastodon-search--view-trending (type print-fun) + "Display a list of tags trending on your instance. +TYPE is a string, either tags, statuses, or links. +PRINT-FUN is the function used to print the data from the response." + (let* ((url (mastodon-http--api + (format "trends/%s" type))) (response (mastodon-http--get-json url)) - (tags (mapcar #'mastodon-search--get-hashtag-info - response)) - (buffer (get-buffer-create "*mastodon-trending*"))) + (data (cond ((equal type "tags") + (mapcar #'mastodon-search--get-hashtag-info + response)) + ((equal type "statuses") + (mastodon-search--get-full-statuses-data response)) + ((equal type "links") + (message "todo")))) + (buffer (get-buffer-create + (format "*mastodon-trending-%s*" type)))) (with-current-buffer buffer (switch-to-buffer (current-buffer)) (mastodon-mode) (let ((inhibit-read-only t)) (erase-buffer) (mastodon-tl--set-buffer-spec (buffer-name buffer) - "api/v1/trends" + (format "api/v1/trends/%s" type) nil) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n" - " TRENDING HASHTAGS\n" + (upcase (format " TRENDING %s\n" type)) " " mastodon-tl--horiz-bar "\n\n") 'success)) - (mastodon-search--print-tags-list tags))))) + (funcall print-fun data))))) ;; functions for mastodon search @@ -118,12 +148,8 @@ QUERY is the string to search." ;; accts)) ; returns a list of three-item lists (tags-list (mapcar #'mastodon-search--get-hashtag-info tags)) - ;; (status-list (mapcar #'mastodon-search--get-status-info - ;; statuses)) - (status-ids-list (mapcar #'mastodon-search--get-id-from-status - statuses)) - (toots-list-json (mapcar #'mastodon-search--fetch-full-status-from-id - status-ids-list))) + (toots-list-json + (mastodon-search--get-full-statuses-data statuses))) (with-current-buffer (get-buffer-create buffer) (switch-to-buffer buffer) (mastodon-mode) |