branch: elpa/mastodon
commit 096494056bdb832f9707f3011bffb80fcf8a6d7c
Merge: edea11cc69 24cb8a4ca5
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>

    Merge branch 'develop'
---
 lisp/mastodon-notifications.el |  3 +++
 lisp/mastodon-tl.el            |  1 +
 lisp/mastodon-toot.el          | 33 ++++++++++++++++++++++++++++-----
 lisp/mastodon.el               | 32 ++++++++++++++++++++------------
 4 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 5ca14ad1e2..0bb2cacd30 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -35,6 +35,9 @@
 (require 'mastodon-widget)
 (require 'map)
 
+(declare-function alert-add-rule "alert")
+(declare-function alert "alert")
+
 (autoload 'mastodon-http--api "mastodon-http")
 (autoload 'mastodon-http--get-params-async-json "mastodon-http")
 (autoload 'mastodon-http--post "mastodon-http")
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 2ee37e8c53..c23ad79df5 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1521,6 +1521,7 @@ SENSITIVE is a flag from the item's JSON data."
               'image-url (or full-remote-url media-url) ; for shr-browse-image
               'keymap mastodon-tl--shr-image-map-replacement
               'image-description caption
+              'shr-alt caption ; for shr-show-alt-text
               'sensitive sensitive
               'help-echo (if (or (string= type "image")
                                  (string= type nil)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 34bdccb5c1..1023272198 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -681,14 +681,20 @@ NO-REDRAFT means delete toot only."
   (mastodon-toot--with-toot-item
    (let* ((toot (mastodon-toot--base-toot-or-item-json))
           (url (mastodon-http--api (format "statuses/%s" id)))
+          (attachmentsp (mastodon-tl--field 'media_attachments toot))
           (pos (point)))
      (let-alist toot
        (if (not (mastodon-toot--own-toot-p toot))
            (user-error "You can only delete (and redraft) your own toots")
          (when (y-or-n-p (if no-redraft
-                             (format "Delete this toot? ")
-                           (format "Delete and redraft this toot? ")))
-           (let* ((response (mastodon-http--delete url)))
+                             "Delete this toot? "
+                           "Delete and redraft this toot? "))
+           (let* ((params
+                   (when (and attachmentsp
+                              no-redraft
+                              (y-or-n-p "Also delete toot's attachments?"))
+                     `(("delete_media" . "true"))))
+                  (response (mastodon-http--delete url params)))
              (mastodon-http--triage
               response
               (lambda (_)
@@ -1325,11 +1331,28 @@ Return its two letter ISO 639 1 code."
 
 ;;; ATTACHMENTS
 
+(defun mastodon-toot--delete-attachments ()
+  "Delete each attachment on the server.
+Makes a DELETE request for each item in
+`mastodon-toot--media-attachment-ids'."
+  (while mastodon-toot--media-attachment-ids
+    (let* ((id (pop mastodon-toot--media-attachment-ids))
+           (url (mastodon-http--api
+                 (format "media/%s"
+                         id)))
+           (resp (mastodon-http--delete url)))
+      (mastodon-http--triage resp
+                             (lambda (_resp)
+                               (message "File %s deleted!" id))))))
+
 (defun mastodon-toot-clear-all-attachments ()
-  "Remove all attachments from a toot draft."
+  "Remove all attachments from a toot draft.
+If user so chooses, also delete the files on the server."
   (interactive)
   (setq mastodon-toot--media-attachments nil)
-  (setq mastodon-toot--media-attachment-ids nil)
+  (if (not (y-or-n-p "Also delete attachments on the server?"))
+      (setq mastodon-toot--media-attachment-ids nil)
+    (mastodon-toot--delete-attachments))
   (mastodon-toot--refresh-attachments-display)
   (mastodon-toot--update-status-fields))
 
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index c4fce67f5a..96d3dbeb74 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -6,7 +6,7 @@
 ;; Author: Johnson Denen <[email protected]>
 ;;         Marty Hiatt <[email protected]>
 ;; Maintainer: Marty Hiatt <[email protected]>
-;; Version: 2.0.11
+;; Version: 2.0.12
 ;; Package-Requires: ((emacs "29.1") (persist "0.8") (tp "0.8"))
 ;; Homepage: https://codeberg.org/martianh/mastodon.el
 
@@ -40,7 +40,6 @@
 (eval-when-compile (require 'subr-x))
 (require 'url)
 (require 'thingatpt)
-(require 'alert)
 (require 'shr)
 
 (require 'mastodon-http)
@@ -51,7 +50,6 @@
 
 (declare-function discover-add-context-menu "discover")
 (declare-function emojify-mode "emojify")
-(declare-function request "request")
 
 (autoload 'mastodon-auth--get-account-name "mastodon-auth")
 (autoload 'mastodon-auth--user-acct "mastodon-auth")
@@ -113,6 +111,9 @@
 (defvar mastodon-notifications--map)
 (defvar mastodon-client--token-file)
 
+(defvar alert-default-style)
+(defvar alert-styles)
+
 (defvar mastodon-notifications-grouped-types
   '("reblog" "favourite") ;; TODO: implement follow!
   "List of notification types for which grouping is implemented.
@@ -213,19 +214,25 @@ shown using `message'.
 Alerts are only checked for when at least 1 mastodon.el buffer is open."
   :type '(boolean))
 
-(defcustom mastodon-notifications-alert-style alert-default-style
+(defcustom mastodon-notifications-alert-style
+  (when (require 'alert nil :noerror) alert-default-style)
   "The type of alert.el style to use for mastodon.el notification alerts.
 Currently, if you customize this variable, you need to restart Emacs for
 it to take effect, or if you don't have any other alert.el rules set up,
-you can nil `alert-internal-configuration' and reload mastodon.el"
+you can nil `alert-internal-configuration' and reload mastodon.el. This
+only applies to alert.el alerts, if you don't use alert.el, you should
+not set this variable and mastodon.el will message for notification
+alerts."
   :type
   `(choice
-    ,@(append
-       '((const :tag "alert.el default"
-                :value alert-default-style))
-       (cl-loop for x in alert-styles
-                collect (list 'const :tag (plist-get (cdr x) :title)
-                              :value (car x))))))
+    ,@(if (not (require 'alert nil :noerror))
+          '(const nil)
+        (append
+         '((const :tag "alert.el default"
+                  :value alert-default-style))
+         (cl-loop for x in alert-styles
+                  collect (list 'const :tag (plist-get (cdr x) :title)
+                                :value (car x)))))))
 
 (defun mastodon-kill-window ()
   "Quit window and delete helper."
@@ -455,7 +462,8 @@ FORCE means to fetch from the server in any case and update
   "Update instance with new toot. Content is captured in a new buffer.
 If USER is non-nil, insert after @ symbol to begin new toot.
 If REPLY-TO-ID is non-nil, attach new toot to a conversation.
-If REPLY-JSON is the json of the toot being replied to."
+If REPLY-JSON is the json of the toot being replied to.
+QUOTE-ID is the id of a toot being quoted, QUOTE-JSON is its data."
   (interactive)
   (mastodon-toot--compose-buffer user reply-to-id reply-json
                                  nil nil quote-id quote-json visibility))

Reply via email to