aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-notifications.el
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-12-23 20:24:59 +0100
committermousebot <mousebot@riseup.net>2021-12-23 20:24:59 +0100
commit6c19decad2bdb86d55c96409cd0c96e1c8dd1a32 (patch)
tree59f4191d590d3713c73ac6b2e8a6197097bfbc5a /lisp/mastodon-notifications.el
parent0cffc91cfd362190eac9580983cda74248a2d3a0 (diff)
parentab37e43c60edf5f0d591441e8cece61a27dd2a6d (diff)
Merge branch 'main'
Diffstat (limited to 'lisp/mastodon-notifications.el')
-rw-r--r--lisp/mastodon-notifications.el170
1 files changed, 152 insertions, 18 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 4d68437..bb05103 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -2,9 +2,10 @@
;; Copyright (C) 2017-2019 Johnson Denen
;; Author: Johnson Denen <johnson.denen@gmail.com>
-;; Version: 0.7.2
-;; Homepage: https://github.com/jdenen/mastodon.el
-;; Package-Requires: ((emacs "24.4"))
+;; Maintainer: Marty Hiatt <martianhiatus@riseup.net>
+;; Version: 0.10.0
+;; Package-Requires: ((emacs "27.1"))
+;; Homepage: https://git.blast.noho.st/mouse/mastodon.el
;; This file is not part of GNU Emacs.
@@ -29,30 +30,41 @@
;;; Code:
+(autoload 'mastodon-http--api "mastodon-http.el")
+(autoload 'mastodon-http--post "mastodon-http.el")
+(autoload 'mastodon-http--triage "mastodon-http.el")
(autoload 'mastodon-media--inline-images "mastodon-media.el")
+(autoload 'mastodon-tl--byline "mastodon-tl.el")
(autoload 'mastodon-tl--byline-author "mastodon-tl.el")
(autoload 'mastodon-tl--clean-tabs-and-nl "mastodon-tl.el")
(autoload 'mastodon-tl--content "mastodon-tl.el")
(autoload 'mastodon-tl--field "mastodon-tl.el")
+(autoload 'mastodon-tl--find-property-range "mastodon-tl.el")
(autoload 'mastodon-tl--has-spoiler "mastodon-tl.el")
(autoload 'mastodon-tl--init "mastodon-tl.el")
+(autoload 'mastodon-tl--init-sync "mastodon-tl.el")
(autoload 'mastodon-tl--insert-status "mastodon-tl.el")
+(autoload 'mastodon-tl--property "mastodon-tl.el")
(autoload 'mastodon-tl--spoiler "mastodon-tl.el")
+(autoload 'mastodon-tl--toot-id "mastodon-tl.el")
(defvar mastodon-tl--display-media-p)
-
(defvar mastodon-notifications--types-alist
'(("mention" . mastodon-notifications--mention)
("follow" . mastodon-notifications--follow)
("favourite" . mastodon-notifications--favourite)
- ("reblog" . mastodon-notifications--reblog))
+ ("reblog" . mastodon-notifications--reblog)
+ ("follow_request" . mastodon-notifications--follow-request)
+ ("status" . mastodon-notifications--status))
"Alist of notification types and their corresponding function.")
(defvar mastodon-notifications--response-alist
'(("Mentioned" . "you")
("Followed" . "you")
- ("Favourited" . "your status")
- ("Boosted" . "your status"))
+ ("Favourited" . "your status from")
+ ("Boosted" . "your status from")
+ ("Requested to follow" . "you")
+ ("Posted" . "a post"))
"Alist of subjects for notification types.")
(defun mastodon-notifications--byline-concat (message)
@@ -63,10 +75,63 @@
" "
(cdr (assoc message mastodon-notifications--response-alist))))
+(defun mastodon-notifications--follow-request-accept-notifs ()
+ "Accept the follow request of user at point, in notifications view."
+ (interactive)
+ (when (mastodon-tl--find-property-range 'toot-json (point))
+ (let* ((toot-json (mastodon-tl--property 'toot-json))
+ (f-req-p (string= "follow_request" (alist-get 'type toot-json))))
+ (if f-req-p
+ (let* ((account (alist-get 'account toot-json))
+ (id (alist-get 'id account))
+ (handle (alist-get 'acct account))
+ (name (alist-get 'username account)))
+ (if id
+ (let ((response
+ (mastodon-http--post
+ (concat
+ (mastodon-http--api "follow_requests")
+ (format "/%s/authorize" id))
+ nil nil)))
+ (mastodon-http--triage response
+ (lambda ()
+ (mastodon-notifications--get)
+ (message "Follow request of %s (@%s) accepted!"
+ name handle))))
+ (message "No account result at point?")))
+ (message "No follow request at point?")))))
+
+(defun mastodon-notifications--follow-request-reject-notifs ()
+ "Reject the follow request of user at point, in notifications view."
+ (interactive)
+ (when (mastodon-tl--find-property-range 'toot-json (point))
+ (let* ((toot-json (mastodon-tl--property 'toot-json))
+ (f-req-p (string= "follow_request" (alist-get 'type toot-json))))
+ (if f-req-p
+ (let* ((account (alist-get 'account toot-json))
+ (id (alist-get 'id account))
+ (handle (alist-get 'acct account))
+ (name (alist-get 'username account)))
+ (if id
+ (let ((response
+ (mastodon-http--post
+ (concat
+ (mastodon-http--api "follow_requests")
+ (format "/%s/reject" id))
+ nil nil)))
+ (mastodon-http--triage response
+ (lambda ()
+ (mastodon-notifications--get)
+ (message "Follow request of %s (@%s) rejected!"
+ name handle))))
+ (message "No account result at point?")))
+ (message "No follow request at point?")))))
+
(defun mastodon-notifications--mention (note)
"Format for a `mention' NOTE."
- (let ((status (mastodon-tl--field 'status note)))
- (mastodon-tl--insert-status
+ (let ((id (alist-get 'id note))
+ (status (mastodon-tl--field 'status note)))
+ (mastodon-notifications--insert-status
status
(mastodon-tl--clean-tabs-and-nl
(if (mastodon-tl--has-spoiler status)
@@ -75,7 +140,8 @@
'mastodon-tl--byline-author
(lambda (_status)
(mastodon-notifications--byline-concat
- "Mentioned")))))
+ "Mentioned"))
+ id)))
(defun mastodon-notifications--follow (note)
"Format for a `follow' NOTE."
@@ -90,10 +156,25 @@
(mastodon-notifications--byline-concat
"Followed"))))
+(defun mastodon-notifications--follow-request (note)
+ "Format for a `follow-request' NOTE."
+ (let ((id (alist-get 'id note))
+ (follower (alist-get 'username (alist-get 'account note))))
+ (mastodon-notifications--insert-status
+ (cons '(reblog (id . nil)) note)
+ (propertize (format "You have a follow request from... %s" follower)
+ 'face 'default)
+ 'mastodon-tl--byline-author
+ (lambda (_status)
+ (mastodon-notifications--byline-concat
+ "Requested to follow"))
+ id)))
+
(defun mastodon-notifications--favourite (note)
"Format for a `favourite' NOTE."
- (let ((status (mastodon-tl--field 'status note)))
- (mastodon-tl--insert-status
+ (let ((id (alist-get 'id note))
+ (status (mastodon-tl--field 'status note)))
+ (mastodon-notifications--insert-status
status
(mastodon-tl--clean-tabs-and-nl
(if (mastodon-tl--has-spoiler status)
@@ -104,12 +185,34 @@
note))
(lambda (_status)
(mastodon-notifications--byline-concat
- "Favourited")))))
+ "Favourited"))
+ id)))
(defun mastodon-notifications--reblog (note)
"Format for a `boost' NOTE."
- (let ((status (mastodon-tl--field 'status note)))
- (mastodon-tl--insert-status
+ (let ((id (alist-get 'id note))
+ (status (mastodon-tl--field 'status note)))
+ (mastodon-notifications--insert-status
+ status
+ (mastodon-tl--clean-tabs-and-nl
+ (if (mastodon-tl--has-spoiler status)
+ (mastodon-tl--spoiler status)
+ (mastodon-tl--content status)))
+ (lambda (_status)
+ (mastodon-tl--byline-author
+ note))
+ (lambda (_status)
+ (mastodon-notifications--byline-concat
+ "Boosted"))
+ id)))
+
+(defun mastodon-notifications--status (note)
+ "Format for a `status' NOTE.
+Status notifications are given when
+`mastodon-tl--enable-notify-user-posts' has been set."
+ (let ((id (cdr (assoc 'id note)))
+ (status (mastodon-tl--field 'status note)))
+ (mastodon-notifications--insert-status
status
(mastodon-tl--clean-tabs-and-nl
(if (mastodon-tl--has-spoiler status)
@@ -120,7 +223,37 @@
note))
(lambda (_status)
(mastodon-notifications--byline-concat
- "Boosted")))))
+ "Posted"))
+ id)))
+
+(defun mastodon-notifications--insert-status (toot body author-byline action-byline &optional id)
+ "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."
+ (let ((start-pos (point)))
+ (insert
+ (propertize
+ (concat "\n"
+ body
+ " \n"
+ (mastodon-tl--byline toot author-byline action-byline))
+ 'toot-id id
+ 'base-toot-id (mastodon-tl--toot-id toot)
+ 'toot-json toot)
+ "\n")
+ (when mastodon-tl--display-media-p
+ (mastodon-media--inline-images start-pos (point)))))
(defun mastodon-notifications--by-type (note)
"Filters NOTE for those listed in `mastodon-notifications--types-alist'."
@@ -140,8 +273,9 @@
(defun mastodon-notifications--get ()
"Display NOTIFICATIONS in buffer."
(interactive)
- (mastodon-tl--init
- "*mastodon-notifications*"
+ (message "Loading your notifications...")
+ (mastodon-tl--init-sync
+ "notifications"
"notifications"
'mastodon-notifications--timeline))