From d8121e7447bf30767cd91523e12429a7a934a2c9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 25 May 2021 11:22:26 +0200 Subject: pin/unpin now toggle fun, and moved copy/delete to mastodon-toot. --- lisp/mastodon-discover.el | 5 ++-- lisp/mastodon-tl.el | 66 ----------------------------------------------- lisp/mastodon-toot.el | 51 ++++++++++++++++++++++++++++++++++++ lisp/mastodon.el | 12 ++++----- 4 files changed, 60 insertions(+), 74 deletions(-) diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 9e1cbad..55623f7 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -54,8 +54,9 @@ ("S-TAB" "Prev link item" mastodon-tl--previous-tab-item) ("t" "New toot" mastodon-toot) ("r" "Reply" mastodon-toot--reply) - ("C" "Copy toot URL" mastodon-tl--copy-toot-url) - ("d" "Delete (your) toot" mastodon-tl--delete-toot) + ("C" "Copy toot URL" mastodon-toot--copy-toot-url) + ("d" "Delete (your) toot" mastodon-toot--delete-toot) + ("i" "Pin/Unpin (your) toot" mastodon-toot--pin-toot-toggle) ("P" "View user profile" mastodon-profile--show-user) ("T" "View thread" mastodon-tl--thread)) ("Timelines" diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 85f5641..5bc07e0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -814,72 +814,6 @@ webapp" (cdr (assoc 'descendants context)))))) (message "No Thread!")));) -(defun mastodon-tl--copy-toot-url () - "Copy URL of toot at point." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (url (if (mastodon-tl--field 'reblog toot) - (cdr (assoc 'url (cdr (assoc 'reblog toot)))) - (cdr (assoc 'url toot))))) - (kill-new url) - (message "Toot URL copied to the clipboard."))) - -;; TODO redraw buffer on success? -(defun mastodon-tl--delete-toot () - "Delete user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s" id)))) - (if (or (cdr (assoc 'reblog toot)) - (not (equal (cdr (assoc 'acct - (cdr (assoc 'account toot)))) - (mastodon-auth--user-acct)))) - (message "You can only delete your own toots.") - (if (y-or-n-p (format "Delete this toot? ")) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response - (lambda () - (message "Toot deleted!")))))))) - -;; TODO: rewrite pin/unpin as toggle functions -(defun mastodon-tl--pin-toot () - "Pin user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/pin" id))) - (pinnable-p (and - (not (cdr (assoc 'reblog toot))) - (equal (cdr (assoc 'acct - (cdr (assoc 'account toot)))) - (mastodon-auth--user-acct)))) - (pinned-p (equal (cdr (assoc 'pinned toot)) t))) - (if (not pinnable-p) - (message "You can only pin your own toots.") - (if pinned-p - (message "Looks like toot is already pinned.") - (if (y-or-n-p (format "Pin this toot to your profile? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot pinned!"))))))))) - -(defun mastodon-tl--unpin-toot () - "Unpin user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/unpin" id))) - (pinned-p (equal (cdr (assoc 'pinned toot)) t))) - (if (not pinned-p) - (message "No pinned toot to unpin here.") - (if (y-or-n-p (format "Unpin this toot? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot unpinned!")))))))) - (defun mastodon-tl--follow-user (user-handle) "Query for USER-HANDLE from current status and follow that user." (interactive diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a11bfa0..6f82ded 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -35,6 +35,7 @@ (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") (autoload 'mastodon-http--triage "mastodon-http") +(autoload 'mastodon-http--delete "mastodon-http") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-tl--clean-tabs-and-nl "mastodon-tl") (autoload 'mastodon-tl--field "mastodon-tl") @@ -182,6 +183,56 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (message (format "%s #%s" action id)))) (message "Nothing to favorite here?!?")))) +(defun mastodon-toot--pin-toot-toggle () + "Pin or unpin user's toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s/pin" id))) + (pinnable-p (and + (not (cdr (assoc 'reblog toot))) + (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (pinned-p (equal (cdr (assoc 'pinned toot)) t)) + (action (if pinned-p "unpin" "pin")) + (msg (if pinned-p "unpinned" "pinned")) + (msg-y-or-n (if pinned-p "Unpin" "Pin"))) + (if (not pinnable-p) + (message "You can only pin your own toots.") + (if (y-or-n-p (format "%s this toot? " msg-y-or-n)) + (mastodon-toot--action action + (lambda () + (message "Toot %s!" msg))))))) + +(defun mastodon-toot--copy-toot-url () + "Copy URL of toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (url (if (mastodon-tl--field 'reblog toot) + (cdr (assoc 'url (cdr (assoc 'reblog toot)))) + (cdr (assoc 'url toot))))) + (kill-new url) + (message "Toot URL copied to the clipboard."))) + +;; TODO redraw buffer on success? +(defun mastodon-toot--delete-toot () + "Delete user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s" id)))) + (if (or (cdr (assoc 'reblog toot)) + (not (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (message "You can only delete your own toots.") + (if (y-or-n-p (format "Delete this toot? ")) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (message "Toot deleted!")))))))) + (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." (kill-buffer-and-window)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2d51120..f6635c0 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -57,12 +57,13 @@ (autoload 'mastodon-tl--unblock-user "mastodon-tl") (autoload 'mastodon-tl--mute-user "mastodon-tl") (autoload 'mastodon-tl--unmute-user "mastodon-tl") -(autoload 'mastodon-tl--delete-toot "mastodon-tl") (autoload 'mastodon-tl--follow-user "mastodon-tl") (autoload 'mastodon-tl--unfollow-user "mastodon-tl") (autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") -(autoload 'mastodon-tl--copy-toot-url "mastodon-tl") +(autoload 'mastodon-toot--delete-toot "mastodon-toot") +(autoload 'mastodon-toot--copy-toot-url "mastodon-toot") +(autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") (defgroup mastodon nil @@ -118,7 +119,6 @@ Use. e.g. \"%c\" for your locale's date and time format." ;; override special mode binding (define-key map (kbd "g") #'undefined) ;; mousebot additions - (define-key map (kbd "d") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) (define-key map (kbd "B") #'mastodon-tl--block-user) @@ -127,9 +127,9 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) - (define-key map (kbd "C") #'mastodon-tl--copy-toot-url) - (define-key map (kbd "i") #'mastodon-tl--pin-toot) - (define-key map (kbd "I") #'mastodon-tl--unpin-toot) + (define-key map (kbd "d") #'mastodon-toot--delete-toot) + (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) + (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3