diff options
| author | mousebot <mousebot@riseup.net> | 2022-01-11 19:10:51 +0100 | 
|---|---|---|
| committer | mousebot <mousebot@riseup.net> | 2022-01-11 19:10:51 +0100 | 
| commit | 5011f6634c66d0f803d60a13a471f17f0f307291 (patch) | |
| tree | 55ceeb0cf231aa2f1487aa1930aa73ea85bac169 | |
| parent | 4eb0b578b5e4ba920999427c137b98043b41c9d4 (diff) | |
FIX fetching max toot length from server
some servers have 'max_toot_chars, but others seem to have 'max_characters,
under statuses, under configuation.
we allow for both types, but also we check our var isn't nil before trying to
check it's length, which broke toot--send in some cases.
| -rw-r--r-- | lisp/mastodon-toot.el | 16 | 
1 files changed, 12 insertions, 4 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index befffee..22699f1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -162,11 +162,18 @@ Valid values are \"direct\", \"private\" (followers-only),  (defun mastodon-toot--get-max-toot-chars-callback (json-response)    "Set max_toot_chars returned in JSON-RESPONSE and display in new toot buffer." +  (let ((max-chars +         (or +          (alist-get 'max_toot_chars json-response) +          ;; some servers have this instead: +          (alist-get 'max_characters +                     (alist-get 'statuses +                                (alist-get 'configuration +                                           json-response))))))    (setq mastodon-toot--max-toot-chars -        (number-to-string -         (alist-get 'max_toot_chars json-response))) +        (number-to-string max-chars))    (with-current-buffer "*new toot*" -    (mastodon-toot--update-status-fields))) +    (mastodon-toot--update-status-fields))))  (defun mastodon-toot--action-success (marker byline-region remove)    "Insert/remove the text MARKER with 'success face in byline. @@ -493,7 +500,8 @@ If media items have been attached and uploaded with                      (not (= (length mastodon-toot--media-attachments)                              (length mastodon-toot--media-attachment-ids)))))             (message "Something is wrong with your uploads. Wait for them to complete or try again.")) -          ((> (length toot) (string-to-number mastodon-toot--max-toot-chars)) +          ((and mastodon-toot--max-toot-chars +                (> (length toot) (string-to-number mastodon-toot--max-toot-chars)))             (message "Looks like your toot is longer than that maximum allowed length."))            (empty-toot-p             (message "Empty toot. Cowardly refusing to post this."))  | 
