aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-notifications.el72
-rw-r--r--lisp/mastodon-search.el38
-rw-r--r--lisp/mastodon-tl.el28
3 files changed, 88 insertions, 50 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 0c56cbb..2091118 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -180,7 +180,7 @@ Can be called in notifications view or in follow-requests view."
(defun mastodon-notifications--reblog (note)
"Format for a `boost' NOTE."
- (mastodon-notifications--format-note note 'boost))
+ (mastodon-notifications--format-note note 'reblog))
(defun mastodon-notifications--status (note)
"Format for a `status' NOTE.
@@ -208,6 +208,16 @@ Status notifications are given when
'(face (font-lock-comment-face shr-text)))))
(buffer-string)))
+(defvar mastodon-notifications--action-alist
+ '((reblog . "Boosted")
+ (favourite . "Favourited")
+ (follow-request . "Requested to follow")
+ (follow . "Followed")
+ (mention . "Mentioned")
+ (status . "Posted")
+ (poll . "Posted a poll")
+ (edit . "Edited")))
+
(defun mastodon-notifications--format-note (note type)
"Format for a NOTE of TYPE."
;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot'
@@ -230,18 +240,15 @@ Status notifications are given when
nil
(mastodon-tl--insert-status
;; toot
- (cond ((or (eq type 'follow)
- (eq type 'follow-request))
+ (cond ((member type '(follow follow-request))
;; Using reblog with an empty id will mark this as something
;; non-boostable/non-favable.
(cons '(reblog (id . nil)) note))
;; reblogs/faves use 'note' to process their own json
;; not the toot's. this ensures following etc. work on such notifs
- ((or (eq type 'favourite)
- (eq type 'boost))
+ ((member type '(favourite reblog))
note)
- (t
- status))
+ (t status))
;; body
(let ((body (if-let ((match (assoc "warn" filters)))
(mastodon-tl--spoiler toot (cadr match))
@@ -251,54 +258,35 @@ Status notifications are given when
(if (eq 'follow-request type)
(mastodon-tl--render-text profile-note)
(mastodon-tl--content status)))))))
- (cond ((or (eq type 'follow)
- (eq type 'follow-request))
- (if (eq type 'follow)
- (propertize "Congratulations, you have a new follower!"
- 'face 'default)
- (concat
- (propertize
- (format "You have a follow request from... %s"
- follower)
- 'face 'default)
- (when mastodon-notifications--profile-note-in-foll-reqs
+ (cond ((eq type 'follow)
+ (propertize "Congratulations, you have a new follower!"
+ 'face 'default))
+ ((eq type 'follow-request)
+ (concat
+ (propertize
+ (format "You have a follow request from... %s"
+ follower)
+ 'face 'default)
+ (if mastodon-notifications--profile-note-in-foll-reqs
(concat
":\n"
- (mastodon-notifications--comment-note-text body))))))
- ((or (eq type 'favourite)
- (eq type 'boost))
+ (mastodon-notifications--comment-note-text body))
+ "")))
+ ((member type '(favourite reblog))
(mastodon-notifications--comment-note-text body))
(t body)))
;; author-byline
- (if (or (eq type 'follow)
- (eq type 'follow-request)
- (eq type 'mention))
+ (if (member type '(follow follow-request mention))
'mastodon-tl--byline-author
(lambda (_status &rest _args) ; unbreak stuff
(mastodon-tl--byline-author note)))
;; action-byline
(lambda (_status)
(mastodon-notifications--byline-concat
- (cond ((eq type 'boost)
- "Boosted")
- ((eq type 'favourite)
- "Favourited")
- ((eq type 'follow-request)
- "Requested to follow")
- ((eq type 'follow)
- "Followed")
- ((eq type 'mention)
- "Mentioned")
- ((eq type 'status)
- "Posted")
- ((eq type 'poll)
- "Posted a poll")
- ((eq type 'edit)
- "Edited"))))
+ (alist-get type mastodon-notifications--action-alist)))
id
;; base toot
- (when (or (eq type 'favourite)
- (eq type 'boost))
+ (when (member type '(favourite reblog))
status)))))
(defun mastodon-notifications--by-type (note)
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 e2cba94..0e61e29 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.
@@ -781,12 +790,15 @@ BASE-TOOT is JSON for the base toot, if any."
(funcall action-byline toot)
" "
;; 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))
@@ -2027,7 +2039,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."