diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-auth.el | 2 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 14 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 13 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 109 |
4 files changed, 71 insertions, 67 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index e4f5934..74d4404 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -166,7 +166,7 @@ Handle any errors from the server." (defun mastodon-auth--user-acct () "Return a mastodon user acct name." - (or (cdr (assoc mastodon-instance-url mastodon-auth--acct-alist)) + (or (cdr (assoc mastodon-instance-url mastodon-auth--acct-alist)) (let ((acct (mastodon-auth--get-account-name))) (push (cons mastodon-instance-url acct) mastodon-auth--acct-alist) acct))) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 98e5090..c7ef718 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -66,7 +66,6 @@ (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") -;; this way you can update it with C-M-x: (defvar mastodon-profile-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "s") #'mastodon-profile--open-followers) @@ -82,13 +81,9 @@ This minor mode is used for mastodon profile pages and adds a couple of extra keybindings." :init-value nil - ;; The mode line indicator. + ;; modeline indicator: :lighter " Profile" :keymap mastodon-profile-mode-map - ;; :keymap '(((kbd "O") . mastodon-profile--open-followers) - ;; ((kbd "o") . mastodon-profile--open-following) - ;; ((kbd "a") . mastodon-profile--follow-request-accept) - ;; ((kbd "r") . mastodon-profile--follow-request-reject) :group 'mastodon :global nil) @@ -406,7 +401,7 @@ If toot is a boost, opens the profile of the booster." (mastodon-media--get-media-link-rendering url)))) (defun mastodon-profile--show-user (user-handle) - "Query user for USER-HANDLE from current status and show that user's profile." + "Query for USER-HANDLE from current status and show that user's profile." (interactive (list (let ((user-handles (mastodon-profile--extract-users-handles @@ -454,7 +449,7 @@ FIELD is used to identify regions under 'account" tootv))) (defun mastodon-profile--search-account-by-handle (handle) - "Return an account based on a users HANDLE. + "Return an account based on a user's HANDLE. If the handle does not match a search return then retun NIL." (let* ((handle (if (string= "@" (substring handle 0 1)) @@ -462,7 +457,8 @@ If the handle does not match a search return then retun NIL." handle)) (matching-account (seq-remove - (lambda(x) (not (string= (alist-get 'acct x) handle))) + (lambda (x) + (not (string= (alist-get 'acct x) handle))) (mastodon-http--get-json (mastodon-http--api (format "accounts/search?q=%s" handle)))))) (when (equal 1 (length matching-account)) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7e9eb60..b2b8026 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -987,7 +987,7 @@ webapp" "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. -This can be called to toggle NOTIFY on users already being followed." +Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "follow"))) @@ -1077,15 +1077,16 @@ Action must be either \"unblock\" or \"mute\"." t)))) (defun mastodon-tl--do-user-action-and-response (user-handle action &optional negp notify) - "Do ACTION on user NAME/USER-HANDLE. + "Do ACTION on user USER-HANDLE. NEGP is whether the action involves un-doing something. If NOTIFY is \"true\", enable notifications when that user posts. If NOTIFY is \"false\", disable notifications when that user posts. NOTIFY is only non-nil when called by `mastodon-tl--follow-user'." (let* ((account (if negp - ;; TODO check if both are actually needed + ;; if unmuting/unblocking, we got handle from mute/block list (mastodon-profile--search-account-by-handle user-handle) + ;; if muting/blocking, we select from handles in current status (mastodon-profile--lookup-account-in-status user-handle (mastodon-profile--toot-json)))) (user-id (mastodon-profile--account-field account 'id)) @@ -1102,7 +1103,9 @@ NOTIFY is only non-nil when called by `mastodon-tl--follow-user'." (message "Cannot find a user with handle %S" user-handle)))) (defun mastodon-tl--do-user-action-function (url name user-handle action &optional notify) - "Post ACTION on user NAME/USER-HANDLE to URL." + "Post ACTION on user NAME/USER-HANDLE to URL. +NOTIFY is either \"true\" or \"false\", and used when we have been called +by `mastodon-tl--follow-user' to enable or disable notifications." (let ((response (mastodon-http--post url nil nil))) (mastodon-http--triage response (lambda () @@ -1112,6 +1115,8 @@ NOTIFY is only non-nil when called by `mastodon-tl--follow-user'." ((string-equal notify "false") (message "Not receiving notifications for user %s (@%s)!" name user-handle)) + ((string-equal action "mute") + (message "User %s (@%s) %sd!" name user-handle action)) ((eq notify nil) (message "User %s (@%s) %sed!" name user-handle action))))))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 31613d0..ec1ba49 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -46,6 +46,7 @@ (defvar company-backends)) (defvar mastodon-instance-url) +(defvar mastodon-tl--buffer-spec) (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--delete "mastodon-http") @@ -187,7 +188,8 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (propertize marker 'face 'success))))))) (defun mastodon-toot--action (action callback) - "Take ACTION on toot at point, then execute CALLBACK." + "Take ACTION on toot at point, then execute CALLBACK. +Makes a POST request to the server." (let* ((id (mastodon-tl--property 'base-toot-id)) (url (mastodon-http--api (concat "statuses/" (mastodon-tl--as-string id) @@ -247,15 +249,27 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (message (format "%s #%s" action id)))) (message "Nothing to favorite here?!?")))) +(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) + (alist-get 'url (alist-get 'reblog toot)) + (alist-get 'url toot)))) + (kill-new url) + (message "Toot URL copied to the clipboard."))) + +(defun mastodon-toot--own-toot-p (toot) + "Check if TOOT is user's own, e.g. for deleting it." + (and (not (alist-get 'reblog toot)) + (equal (alist-get 'acct (alist-get 'account toot)) + (mastodon-auth--user-acct)))) + (defun mastodon-toot--pin-toot-toggle () "Pin or unpin user's toot at point." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - (pinnable-p (and - (not (alist-get 'reblog toot)) - (equal (alist-get 'acct - (alist-get 'account toot)) - (mastodon-auth--user-acct)))) + (pinnable-p (mastodon-toot--own-toot-p toot)) (pinned-p (equal (alist-get 'pinned toot) t)) (action (if pinned-p "unpin" "pin")) (msg (if pinned-p "unpinned" "pinned")) @@ -267,37 +281,15 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (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) - (alist-get 'url (alist-get 'reblog toot)) - (alist-get 'url toot)))) - (kill-new url) - (message "Toot URL copied to the clipboard."))) - (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 (alist-get 'reblog toot) - (not (equal (alist-get 'acct - (alist-get '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 () - (mastodon-tl--reload-timeline-or-profile) - (message "Toot deleted!")))))))) + (mastodon-toot--delete-and-redraft-toot t)) ;; TODO: handle media/poll for redrafting toots -(defun mastodon-toot--delete-and-redraft-toot () - "Delete and redraft user's toot at point synchronously." +(defun mastodon-toot--delete-and-redraft-toot (&optional no-redraft) + "Delete and redraft user's toot at point synchronously. +NO-REDRAFT means delete toot only." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) @@ -305,31 +297,42 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (toot-cw (alist-get 'spoiler_text toot)) (toot-visibility (alist-get 'visibility toot)) (reply-id (alist-get 'in_reply_to_id toot))) - (if (or (alist-get 'reblog toot) - (not (equal (alist-get 'acct - (alist-get 'account toot)) - (mastodon-auth--user-acct)))) - (message "You can only delete and redraft your own toots.") - (if (y-or-n-p (format "Delete and redraft this toot? ")) + (if (not (mastodon-toot--own-toot-p toot)) + (message "You can only delete (and redraft) your own toots.") + (if (y-or-n-p (if no-redraft + (format "Delete this toot? ") + (format "Delete and redraft this toot? "))) (let* ((response (mastodon-http--delete url))) (mastodon-http--triage response (lambda () - (with-current-buffer response - (let* ((json-response (mastodon-http--process-json)) - (content (alist-get 'text json-response))) - ;; (media (alist-get 'media_attachments json-response))) - (mastodon-toot--compose-buffer nil nil) - (goto-char (point-max)) - (insert content) - ;; adopt reply-to-id, visibility and CW from deleted toot: - (when reply-id - (setq mastodon-toot--reply-to-id reply-id)) - (setq mastodon-toot--visibility toot-visibility) - (when (not (equal toot-cw "")) - (setq mastodon-toot--content-warning t) - (setq mastodon-toot--content-warning-from-reply-or-redraft toot-cw)) - (mastodon-toot--update-status-fields)))))))))) + (if no-redraft + (progn + (when mastodon-tl--buffer-spec + (mastodon-tl--reload-timeline-or-profile)) + (message "Toot deleted!")) + (mastodon-toot--redraft response + reply-id + toot-visibility + toot-cw))))))))) + +(defun mastodon-toot--redraft (response &optional reply-id toot-visibility toot-cw) + "Opens a new toot compose buffer using values from RESPONSE buffer. +REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." + (with-current-buffer response + (let* ((json-response (mastodon-http--process-json)) + (content (alist-get 'text json-response))) + (mastodon-toot--compose-buffer nil nil) + (goto-char (point-max)) + (insert content) + ;; adopt reply-to-id, visibility and CW from deleted toot: + (when reply-id + (setq mastodon-toot--reply-to-id reply-id)) + (setq mastodon-toot--visibility toot-visibility) + (when (not (equal toot-cw "")) + (setq mastodon-toot--content-warning t) + (setq mastodon-toot--content-warning-from-reply-or-redraft toot-cw)) + (mastodon-toot--update-status-fields)))) (defun mastodon-toot--bookmark-toot-toggle () "Bookmark or unbookmark toot at point synchronously." |