aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-tl.el82
1 files changed, 81 insertions, 1 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index f3c3527..d69cb1a 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -168,6 +168,12 @@ types of mastodon links and not just shr.el-generated ones.")
We need to override the keymap so tabbing will navigate to all
types of mastodon links and not just shr.el-generated ones.")
+(defvar mastodon-tl--view-filters-keymap
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "d") 'mastodon-tl--delete-filter)
+ (keymap-canonicalize map))
+ "Keymap for viewing filters.")
+
(defvar mastodon-tl--byline-link-keymap
(when (require 'mpv nil :no-error)
(let ((map (make-sparse-keymap)))
@@ -1058,7 +1064,6 @@ webapp"
(reblog (alist-get 'reblog json)))
(if reblog (alist-get 'id reblog) id)))
-
(defun mastodon-tl--thread ()
"Open thread buffer for toot under `point'."
(interactive)
@@ -1090,6 +1095,81 @@ webapp"
(mastodon-tl--goto-next-toot))
(message "No Thread!"))))
+(defun mastodon-tl--create-filter ()
+ "Create a filter for a word.
+Prompt for a context, must be a list containting at least one of \"home\",
+\"notifications\", \"public\", \"thread\"."
+ (interactive)
+ (let* ((url (mastodon-http--api "filters"))
+ (word (read-string
+ (format "Word to filter (%s): " (current-word))
+ nil nil (current-word)))
+ (contexts (completing-read-multiple
+ "Contexts to filter [TAB for options]:"
+ '("home" "notifications" "public" "thread")))
+ (contexts-processed
+ (mapcar (lambda (x)
+ (cons "context[]" x))
+ contexts))
+ (response (mastodon-http--post url (push
+ `("phrase" . ,word)
+ contexts-processed)
+ nil)))
+ (mastodon-http--triage response
+ (lambda ()
+ (message "Filter created for %s!" word)
+ (when (string= (plist-get mastodon-tl--buffer-spec 'buffer-name)
+ "*mastodon-filters*")
+ (mastodon-tl--view-filters))))))
+
+(defun mastodon-tl--view-filters ()
+ ""
+ (interactive)
+ (let ((url (mastodon-http--api "filters")))
+ (mastodon-tl--init-sync "*mastodon-filters*"
+ "filters"
+ 'mastodon-tl--insert-filters)
+ (mastodon-tl--goto-next-toot)))
+
+(defun mastodon-tl--insert-filters (json)
+ ""
+ (insert (mastodon-tl--set-face
+ (concat "\n ------------\n"
+ " CURRENT FILTERS\n"
+ " ------------\n\n")
+ 'success))
+ (mapc (lambda (x)
+ (mastodon-tl--insert-filter-string x)
+ (insert "\n\n"))
+ json))
+
+(defun mastodon-tl--insert-filter-string (filter)
+ ""
+ (let* ((phrase (alist-get 'phrase filter))
+ (contexts (alist-get 'context filter))
+ (id (alist-get 'id filter))
+ (filter-string (concat "- \"" phrase "\" filtered in: "
+ (mapconcat #'identity contexts ", "))))
+ (insert
+ (propertize filter-string
+ 'toot-id id ;for goto-next-toot compat
+ 'phrase phrase
+ 'help-echo "d to delete filter at point, n/p to go to next/prev filter."
+ 'keymap mastodon-tl--view-filters-keymap
+ 'byline t)))) ;for goto-next-toot compat
+
+(defun mastodon-tl--delete-filter ()
+ ""
+ (interactive)
+ (let* ((filter-id (mastodon-tl--property 'toot-id))
+ (phrase (mastodon-tl--property 'phrase))
+ (url (mastodon-http--api
+ (format "filters/%s" filter-id)))
+ (response (mastodon-http--delete url)))
+ (mastodon-http--triage response (lambda ()
+ (message "Filter for \"%s\" deleted!" phrase)
+ (mastodon-tl--view-filters)))))
+
(defun mastodon-tl--get-follow-suggestions ()
"Display a buffer of suggested accounts to follow."
(interactive)