aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-10-16 10:30:47 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-10-16 10:30:47 +0200
commitd87d7af24159369af5b7540ffb1cde973cc9efb2 (patch)
tree04fd4034964248e91fcd2e0de1793a25147cf424 /lisp
parent56e555945b06662bad0d687c1bc53fabe4beafed (diff)
parentd7536942c9d749a6e98eec7e36a1aab00fe39bcf (diff)
Merge branch 'develop' into byline-rework
Diffstat (limited to 'lisp')
-rw-r--r--lisp/.dir-locals.el7
-rw-r--r--lisp/mastodon-search.el38
-rw-r--r--lisp/mastodon-tl.el79
3 files changed, 108 insertions, 16 deletions
diff --git a/lisp/.dir-locals.el b/lisp/.dir-locals.el
index bcb8ba5..da012d6 100644
--- a/lisp/.dir-locals.el
+++ b/lisp/.dir-locals.el
@@ -1,7 +1,6 @@
-;;; Directory Local Variables
+;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")
-;; Preferred indentation style:
((nil . ((indent-tabs-mode . nil)))
- ;; setting this makes package-lint look in the main file for deps:
- (emacs-lisp-mode . ((package-lint-main-file . "mastodon.el"))))
+ (emacs-lisp-mode . ((elisp-flymake-byte-compile-load-path . load-path)
+ (package-lint-main-file . "mastodon.el"))))
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 cf7f9aa..3ebfa4e 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.
@@ -823,12 +832,15 @@ BASE-TOOT is JSON for the base toot, if any."
(funcall author-byline toot nil domain :base)
" "
;; timestamp:
- (propertize
- (format-time-string mastodon-toot-timestamp-format parsed-time)
- 'timestamp parsed-time
- 'display (if mastodon-tl--enable-relative-timestamps
- (mastodon-tl--relative-time-description parsed-time)
- parsed-time))
+ (let ((ts (format-time-string
+ mastodon-toot-timestamp-format parsed-time)))
+ (propertize ts
+ 'timestamp parsed-time
+ 'display
+ (if mastodon-tl--enable-relative-timestamps
+ (mastodon-tl--relative-time-description parsed-time)
+ parsed-time)
+ 'help-echo ts))
;; detailed:
(when detailed-p
(let* ((app (alist-get 'application toot))
@@ -917,17 +929,60 @@ links in the text. If TOOT is nil no parsing occurs."
0
(- (window-width) 3)))))
(shr-render-region (point-min) (point-max)))
- ;; Make all links a tab stop recognized by our own logic, make things point
- ;; to our own logic (e.g. hashtags), and update keymaps where needed:
+ ;; Make all links a tab stop recognized by our own logic, make
+ ;; things point to our own logic (e.g. hashtags), and update keymaps
+ ;; where needed:
(when toot
(let (region)
(while (setq region (mastodon-tl--find-property-range
'shr-url (or (cdr region) (point-min))))
(mastodon-tl--process-link toot
(car region) (cdr region)
- (get-text-property (car region) 'shr-url)))))
+ (get-text-property (car region) 'shr-url))
+ (when (proper-list-p toot) ;; not on profile fields cons cells
+ ;; render card author maybe:
+ (let* ((card (alist-get 'card toot))
+ (card-url (alist-get 'url card))
+ (authors (alist-get 'authors card))
+ (url (buffer-substring (car region) (cdr region)))
+ (url-no-query (car (split-string url "?"))))
+ (when (and (string= url-no-query card-url)
+ ;; only if we have an account's data:
+ (alist-get 'account (car authors)))
+ (goto-char (point-max))
+ (mastodon-tl--insert-card-authors authors)))))))
(buffer-string))))
+(defun mastodon-tl--insert-card-authors (authors)
+ "Insert a string of card AUTHORS."
+ (let ((authors-str (format "Author%s: "
+ (if (< 1 (length authors)) "s" ""))))
+ (insert
+ (concat
+ "\n(" authors-str
+ (mapconcat #'mastodon-tl--format-card-author authors "\n")
+ ")\n"))))
+
+(defun mastodon-tl--format-card-author (data)
+ "Render card author DATA."
+ (when-let ((account (alist-get 'account data))) ;.account
+ (let-alist account ;.account
+ ;; FIXME: replace with refactored handle render fun
+ ;; in byline refactor branch:
+ (concat
+ (propertize .username
+ 'face 'mastodon-display-name-face
+ 'item-type 'user
+ 'item-id .id)
+ " "
+ (propertize (concat "@" .acct)
+ 'face 'mastodon-handle-face
+ 'mouse-face 'highlight
+ 'mastodon-tab-stop 'user-handle
+ 'keymap mastodon-tl--link-keymap
+ 'mastodon-handle (concat "@" .acct)
+ 'help-echo (concat "Browse user profile of @" .acct))))))
+
(defun mastodon-tl--process-link (toot start end url)
"Process link URL in TOOT as hashtag, userhandle, or normal link.
START and END are the boundaries of the link in the toot."
@@ -1598,7 +1653,7 @@ NO-BYLINE means just insert toot body, used for folding."
(propertize ;; body only:
(concat
"\n"
- ;; relpy symbol (broken):
+ ;; relpy symbol:
(when (and after-reply-status-p thread)
(concat (mastodon-tl--symbol 'replied)
"\n"))
@@ -2033,7 +2088,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."