aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-notifications.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-notifications.el')
-rw-r--r--lisp/mastodon-notifications.el101
1 files changed, 40 insertions, 61 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 9f92172..1c2aad7 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -115,32 +115,31 @@ With no argument, the request is accepted. Argument REJECT means
reject the request. Can be called in notifications view or in
follow-requests view."
(if (not (mastodon-tl--find-property-range 'item-json (point)))
- (message "No follow request at point?")
+ (user-error "No follow request at point?")
(let* ((item-json (mastodon-tl--property 'item-json))
(f-reqs-view-p (string= "follow_requests"
(plist-get mastodon-tl--buffer-spec 'endpoint)))
(f-req-p (or (string= "follow_request" (alist-get 'type item-json)) ;notifs
f-reqs-view-p)))
(if (not f-req-p)
- (message "No follow request at point?")
+ (user-error "No follow request at point?")
(let-alist (or (alist-get 'account item-json) ;notifs
item-json) ;f-reqs
- (if .id
- (let ((response
- (mastodon-http--post
- (concat
- (mastodon-http--api "follow_requests")
- (format "/%s/%s" .id (if reject "reject" "authorize"))))))
- (mastodon-http--triage response
- (lambda (_)
- (if f-reqs-view-p
- (mastodon-views--view-follow-requests)
- (mastodon-tl--reload-timeline-or-profile))
- (message "Follow request of %s (@%s) %s!"
- .username .acct (if reject
- "rejected"
- "accepted")))))
- (message "No account result at point?")))))))
+ (if (not .id)
+ (user-error "No account result at point?")
+ (let ((response
+ (mastodon-http--post
+ (mastodon-http--api
+ (format "follow_requests/%s/%s"
+ .id (if reject "reject" "authorize"))))))
+ (mastodon-http--triage
+ response
+ (lambda (_)
+ (if f-reqs-view-p
+ (mastodon-views--view-follow-requests)
+ (mastodon-tl--reload-timeline-or-profile))
+ (message "Follow request of %s (@%s) %s!"
+ .username .acct (if reject "rejected" "accepted")))))))))))
(defun mastodon-notifications--follow-request-accept ()
"Accept a follow request.
@@ -191,7 +190,6 @@ Status notifications are given when
(defun mastodon-notifications--comment-note-text (str)
"Add comment face to all text in STR with `shr-text' face only."
(with-temp-buffer
- (switch-to-buffer (current-buffer))
(insert str)
(goto-char (point-min))
(let (prop)
@@ -206,7 +204,7 @@ Status notifications are given when
;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot'
(let* ((id (alist-get 'id note))
(profile-note
- (when (equal 'follow-request type)
+ (when (eq 'follow-request type)
(let ((str (mastodon-tl--field
'note
(mastodon-tl--field 'account note))))
@@ -223,15 +221,15 @@ Status notifications are given when
nil
(mastodon-tl--insert-status
;; toot
- (cond ((or (equal type 'follow)
- (equal type 'follow-request))
+ (cond ((or (eq type 'follow)
+ (eq type '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 (equal type 'favourite)
- (equal type 'boost))
+ ((or (eq type 'favourite)
+ (eq type 'boost))
note)
(t
status))
@@ -241,12 +239,12 @@ Status notifications are given when
(mastodon-tl--clean-tabs-and-nl
(if (mastodon-tl--has-spoiler status)
(mastodon-tl--spoiler status)
- (if (equal 'follow-request type)
+ (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 (equal type 'follow)
+ (if (eq type 'follow)
(propertize "Congratulations, you have a new follower!"
'face 'default)
(concat
@@ -263,59 +261,40 @@ Status notifications are given when
(mastodon-notifications--comment-note-text body))
(t body)))
;; author-byline
- (if (or (equal type 'follow)
- (equal type 'follow-request)
- (equal type 'mention))
+ (if (or (eq type 'follow)
+ (eq type 'follow-request)
+ (eq type '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 ((equal type 'boost)
+ (cond ((eq type 'boost)
"Boosted")
- ((equal type 'favourite)
+ ((eq type 'favourite)
"Favourited")
- ((equal type 'follow-request)
+ ((eq type 'follow-request)
"Requested to follow")
- ((equal type 'follow)
+ ((eq type 'follow)
"Followed")
- ((equal type 'mention)
+ ((eq type 'mention)
"Mentioned")
- ((equal type 'status)
+ ((eq type 'status)
"Posted")
- ((equal type 'poll)
+ ((eq type 'poll)
"Posted a poll")
- ((equal type 'edit)
+ ((eq type 'edit)
"Edited"))))
id
;; base toot
- (when (or (equal type 'favourite)
- (equal type 'boost))
+ (when (or (eq type 'favourite)
+ (eq type 'boost))
status)))))
-(defun mastodon-notifications--insert-status
- (toot body author-byline action-byline id &optional base-toot)
- "Display the content and byline of timeline element TOOT.
-BODY will form the section of the toot above the byline.
-
-AUTHOR-BYLINE is an optional function for adding the author
-portion of the byline that takes one variable. By default it is
-`mastodon-tl--byline-author'.
-
-ACTION-BYLINE is also an optional function for adding an action,
-such as boosting favouriting and following to the byline. It also
-takes a single function. By default it is
-`mastodon-tl--byline-boosted'.
-
-ID is the notification's own id, which is attached as a property.
-If the status is a favourite or a boost, BASE-TOOT is the JSON
-of the toot responded to."
- (when toot ; handle rare blank notif server bug
- (mastodon-tl--insert-status toot body author-byline action-byline id base-toot)))
-
(defun mastodon-notifications--by-type (note)
- "Filters NOTE for those listed in `mastodon-notifications--types-alist'."
+ "Filter NOTE for those listed in `mastodon-notifications--types-alist'.
+Call its function in that list on NOTE."
(let* ((type (mastodon-tl--field 'type note))
(fun (cdr (assoc type mastodon-notifications--types-alist)))
(start-pos (point)))
@@ -327,7 +306,7 @@ of the toot responded to."
(defun mastodon-notifications--timeline (json)
"Format JSON in Emacs buffer."
(if (seq-empty-p json)
- (message "Looks like you have no (more) notifications for the moment.")
+ (user-error "Looks like you have no (more) notifications for now")
(mapc #'mastodon-notifications--by-type json)
(goto-char (point-min))))