aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-10-14 19:19:38 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-10-16 09:54:38 +0200
commitc1c0d3a71d5bf81ac9e6f0169716c9903e54df06 (patch)
treecee82f631e0fa3be45fb91c71e1f8280b9c86142 /lisp
parente07fc229966a978fb22c741f40526301f204299f (diff)
implement rough trending links, and link timeline
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-search.el38
-rw-r--r--lisp/mastodon-tl.el13
2 files changed, 49 insertions, 2 deletions
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index 7fc4de3..90519ed 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -97,6 +97,41 @@ QUERY is the string to search."
(mastodon-search--view-trending "statuses"
#'mastodon-tl--timeline))
+(defun mastodon-search--trending-links ()
+ "Display a list of links trending on your instance."
+ (interactive)
+ (mastodon-search--view-trending "links"
+ #'mastodon-search--render-links))
+
+(defun mastodon-search--render-links (links)
+ "Render trending LINKS."
+ (cl-loop for l in links
+ do (mastodon-search--render-link l)))
+
+(defun mastodon-search--render-link (link)
+ "Render a trending LINK."
+ (let-alist link
+ (insert
+ (propertize
+ (mastodon-tl--render-text
+ (concat "<a href=\"" .url "\">" .url "</a>\n" .title)
+ link)
+ 'item-type 'link
+ 'item-json link
+ 'shr-url .url
+ 'byline t ;; nav
+ 'help-echo
+ (substitute-command-keys
+ "\\[`mastodon-search--load-link-posts'] to view a link's timeline"))
+ ;; TODO: display card link author here
+ "\n\n")))
+
+(defun mastodon-search--load-link-posts ()
+ "Load timeline of posts containing link at point."
+ (interactive)
+ (let* ((url (mastodon-tl--property 'shr-url)))
+ (mastodon-tl--link-timeline url)))
+
(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.
@@ -109,7 +144,8 @@ PRINT-FUN is the function used to print the data from the response."
(offset '(("offset" . "0")))
(params (push limit offset))
(data (mastodon-http--get-json url params))
- (buffer (get-buffer-create (format "*mastodon-trending-%s*" type))))
+ (buffer (get-buffer-create
+ (format "*mastodon-trending-%s*" type))))
(with-mastodon-buffer buffer #'mastodon-mode nil
(mastodon-tl--set-buffer-spec (buffer-name buffer)
(format "trends/%s" type)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 81be479..75bde95 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -279,6 +279,7 @@ etc.")
;; is already bound to w also
(define-key map (kbd "u") #'mastodon-tl--update)
(define-key map [remap shr-browse-url] #'mastodon-url-lookup)
+ (define-key map (kbd "M-RET") #'mastodon-search--load-link-posts)
map)
"The keymap to be set for shr.el generated links that are not images.
We need to override the keymap so tabbing will navigate to all
@@ -575,6 +576,14 @@ With a double PREFIX arg, limit results to your own instance."
(concat "timelines/tag/" (if (listp tag) (car tag) tag)) ; must be /tag/:sth
'mastodon-tl--timeline nil params)))
+(defun mastodon-tl--link-timeline (url)
+ "Load a link timeline, displaying posts containing URL."
+ (let ((endpoint (mastodon-http--api "timelines/link"))
+ (params `(("url" . ,url))))
+ (mastodon-tl--init "links" "timelines/link"
+ 'mastodon-tl--timeline nil
+ params)))
+
;;; BYLINES, etc.
@@ -1987,7 +1996,9 @@ call this function after it is set or use something else."
((string= "*mastodon-toot-edits*" buffer-name)
'toot-edits)
((string= "*masto-image*" (buffer-name))
- 'mastodon-image))))
+ 'mastodon-image)
+ ((mastodon-tl--endpoint-str-= "timelines/link")
+ 'link-timeline))))
(defun mastodon-tl--buffer-type-eq (type)
"Return t if current buffer type is equal to symbol TYPE."