diff options
-rw-r--r-- | lisp/mastodon-notifications.el | 26 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 32 | ||||
-rw-r--r-- | test/mastodon-notifications-test.el | 4 |
3 files changed, 56 insertions, 6 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 4437635..15633be 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -54,7 +54,8 @@ ("follow" . mastodon-notifications--follow) ("favourite" . mastodon-notifications--favourite) ("reblog" . mastodon-notifications--reblog) - ("follow_request" . mastodon-notifications--follow-request)) + ("follow_request" . mastodon-notifications--follow-request) + ("status" . mastodon-notifications--status)) "Alist of notification types and their corresponding function.") (defvar mastodon-notifications--response-alist @@ -62,7 +63,8 @@ ("Followed" . "you") ("Favourited" . "your status from") ("Boosted" . "your status from") - ("Requested to follow" . "you")) + ("Requested to follow" . "you") + ("Posted" . "a post")) "Alist of subjects for notification types.") (defun mastodon-notifications--byline-concat (message) @@ -204,6 +206,26 @@ "Boosted")) id))) +(defun mastodon-notifications--status (note) + "Format for a `status' NOTE. +Status notifications are given when +`mastodon-tl--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) + (mastodon-tl--spoiler status) + (mastodon-tl--content status))) + (lambda (_status) + (mastodon-tl--byline-author + note)) + (lambda (_status) + (mastodon-notifications--byline-concat + "Posted")) + id))) + (defun mastodon-notifications--insert-status (toot body author-byline action-byline &optional id) "Display the content and byline of timeline element TOOT. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fbebd69..9305bea 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -951,12 +951,38 @@ webapp" (alist-get 'descendants context))))) (message "No Thread!")))) -(defun mastodon-tl--follow-user (user-handle) - "Query for USER-HANDLE from current status and follow that user." +(defun mastodon-tl--follow-user (user-handle &optional notify) + "Query for USER-HANDLE from current status and follow that user. +If NOTIFY is \"true\", enable notifications when that user posts. +If NOTIFY is \"false\", disable notifications when that user posts." (interactive (list (mastodon-tl--interactive-user-handles-get "follow"))) - (mastodon-tl--do-user-action-and-response user-handle "follow")) + (mastodon-tl--do-user-action-and-response user-handle "follow" notify)) + +(defun mastodon-tl--notify-user-posts (user-handle) + "Query for USER-HANDLE from current status and enable notifications when they post." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "Receive notifications when user posts: " + user-handles + nil ; predicate + 'confirm)))) + (mastodon-tl--follow-user user-handle "true")) + +(defun mastodon-tl--no-notify-user-posts (user-handle) + "Query for USER-HANDLE from current status and disable notifications when they post." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "Disable notifications when user posts: " + user-handles + nil ; predicate + 'confirm)))) + (mastodon-tl--follow-user user-handle "false")) (defun mastodon-tl--unfollow-user (user-handle) "Query for USER-HANDLE from current status and unfollow that user." diff --git a/test/mastodon-notifications-test.el b/test/mastodon-notifications-test.el index ee6748a..4804e10 100644 --- a/test/mastodon-notifications-test.el +++ b/test/mastodon-notifications-test.el @@ -210,6 +210,8 @@ notification to be tested." (string= " Favourited your status from" (mastodon-notifications--byline-concat "Favourited")) (string= " Boosted your status from" - (mastodon-notifications--byline-concat "Boosted"))))) + (mastodon-notifications--byline-concat "Boosted")) + (string= " Posted a post" + (mastodon-notifications--byline-concat "Posted"))))) |