aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el16
-rw-r--r--lisp/mastodon-media.el5
-rw-r--r--lisp/mastodon-tl.el3
-rw-r--r--lisp/mastodon-toot.el48
-rw-r--r--lisp/mastodon.el3
5 files changed, 37 insertions, 38 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index f092a2d..4f4cc3f 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -90,6 +90,12 @@ Message status and JSON error from RESPONSE if unsuccessful."
(let ((json-response (mastodon-http--process-json)))
(message "Error %s: %s" status (cdr (assoc 'error json-response))))))))
+(defun mastodon-http--read-file-as-string (filename)
+ "Read a file FILENAME as a string. Used to generate image preview."
+ (with-temp-buffer
+ (insert-file-contents filename)
+ (string-to-unibyte (buffer-string))))
+
(defun mastodon-http--post (url args headers &optional unauthenticed-p)
"POST synchronously to URL with ARGS and HEADERS.
@@ -113,12 +119,6 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
(url-retrieve-synchronously url)
(url-retrieve-synchronously url nil nil mastodon-http--timeout)))))
-(defun mastodon-http--read-file-as-string (filename)
- "Read a file FILENAME as a string. Used to generate image preview."
- (with-temp-buffer
- (insert-file-contents filename)
- (string-to-unibyte (buffer-string))))
-
(defun mastodon-http--get (url)
"Make synchronous GET request to URL.
@@ -223,7 +223,7 @@ Pass response buffer to CALLBACK function with args CBARGS."
(url-request-extra-headers
`(("Authorization" . ,(concat "Bearer "
(mastodon-auth--access-token))))))
- (url-retrieve url callback cbargs mastodon-http--timeout)))
+ (url-retrieve url callback cbargs)))
(defun mastodon-http--get-json-async (url &optional callback &rest args)
"Make GET request to URL. Call CALLBACK with json-vector and ARGS."
@@ -251,7 +251,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
(append `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token))))
headers)))
(with-temp-buffer
- (url-retrieve url callback cbargs mastodon-http--timeout))))
+ (url-retrieve url callback cbargs))))
;; TODO: test for curl first?
(defun mastodon-http--post-media-attachment (url filename caption)
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el
index 28fbd19..fcef218 100644
--- a/lisp/mastodon-media.el
+++ b/lisp/mastodon-media.el
@@ -51,11 +51,6 @@
:group 'mastodon-media
:type 'integer)
-(defcustom mastodon-media--attachment-height 80
- "Height of the attached images preview in the toot draft buffer."
- :group 'mastodon-media
- :type 'integer)
-
(defvar mastodon-media--generic-avatar-data
(base64-decode-string
"iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 904d850..7f9538b 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -149,6 +149,9 @@ types of mastodon links and not just shr.el-generated ones.")
;; browse-url loads the preview only, we want browse-image
;; on RET to browse full sized image URL
(define-key map [remap shr-browse-url] 'shr-browse-image)
+ ;; remove shr's u binding, as it the maybe-probe-and-copy-url
+ ;; is already bound to w also
+ (define-key map (kbd "u") 'mastodon-tl--update)
(keymap-canonicalize map))
"The keymap to be set for shr.el generated image links.
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 0153c9b..983515e 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -29,9 +29,6 @@
;;; Code:
-(defvar mastodon-instance-url)
-(defvar mastodon-media--attachment-height)
-(defvar mastodon-toot--enable-completion-for-mentions)
(when (require 'emojify nil :noerror)
(declare-function emojify-insert-emoji "emojify"))
@@ -39,6 +36,7 @@
(require 'cl-lib)
(require 'company nil :noerror)
+(defvar mastodon-instance-url)
(autoload 'mastodon-auth--user-acct "mastodon-auth")
(autoload 'mastodon-http--api "mastodon-http")
(autoload 'mastodon-http--post "mastodon-http")
@@ -81,6 +79,11 @@ Must be one of \"public\", \"unlisted\", \"private\" (for followers-only), or \"
:group 'mastodon-toot
:type 'string)
+(defcustom mastodon-toot--attachment-height 80
+ "Height of the attached images preview in the toot draft buffer."
+ :group 'mastodon-media
+ :type 'integer)
+
(when (require 'company nil :noerror)
(defcustom mastodon-toot--enable-completion-for-mentions "followers"
"Whether to enable company completion for mentions in toot compose buffer."
@@ -320,29 +323,26 @@ Remove MARKER if REMOVE is non-nil, otherwise add it."
(setq mastodon-toot--content-warning-from-reply-or-redraft toot-cw))
(mastodon-toot--update-status-fields))))))))))
-(defun mastodon-toot--bookmark-toot ()
- "Bookmark 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/bookmark" id))))
- (if (y-or-n-p (format "Bookmark this toot? "))
- (let ((response (mastodon-http--post url nil nil)))
- (mastodon-http--triage response
- (lambda ()
- (message "Toot bookmarked!")))))))
-
-(defun mastodon-toot--unbookmark-toot ()
- "Bookmark toot at point synchronously."
+(defun mastodon-toot--bookmark-toot-toggle ()
+ "Bookmark or unbookmark 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/unbookmark" id))))
- (if (y-or-n-p (format "Remove this toot from your bookmarks? "))
- (let ((response (mastodon-http--post url nil nil)))
- (mastodon-http--triage response
- (lambda ()
- (message "Toot unbookmarked!")))))))
+ (bookmarked (cdr (assoc 'bookmarked toot)))
+ (url (mastodon-http--api (if (equal bookmarked t)
+ (format "statuses/%s/unbookmark" id)
+ (format "statuses/%s/bookmark" id))))
+ (prompt (if (equal bookmarked t)
+ (format "Toot already bookmarked. Remove? ")
+ (format "Bookmark this toot? ")))
+ (message (if (equal bookmarked t)
+ "Bookmark removed!"
+ "Toot bookmarked!")))
+ (when (y-or-n-p prompt)
+ (let ((response (mastodon-http--post url nil nil)))
+ (mastodon-http--triage response
+ (lambda ()
+ (message message)))))))
(defun mastodon-toot--kill ()
"Kill `mastodon-toot-mode' buffer and window."
@@ -584,7 +584,7 @@ It adds the items' ids to `mastodon-toot--media-attachment-ids', which is used t
(or (let ((counter 0)
(image-options (when (or (image-type-available-p 'imagemagick)
(image-transforms-p))
- `(:height ,mastodon-media--attachment-height))))
+ `(:height ,mastodon-toot--attachment-height))))
(mapcan (lambda (attachment)
(let* ((data (cdr (assoc :contents attachment)))
(image (apply #'create-image data
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 57f5721..7f4b773 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -82,6 +82,7 @@
(autoload 'mastodon-tl--poll-vote "mastodon-http")
(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot")
(autoload 'mastodon-profile--view-bookmarks "mastodon-profile")
+(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot")
(defgroup mastodon nil
"Interface with Mastodon."
@@ -158,7 +159,7 @@ Use. e.g. \"%c\" for your locale's date and time format."
(define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs)
(define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs)
(define-key map (kbd "v") #'mastodon-tl--poll-vote)
- (define-key map (kbd "k") #'mastodon-toot--bookmark-toot)
+ (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle)
(define-key map (kbd "K") #'mastodon-profile--view-bookmarks)
map)