aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-10 13:05:18 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-10 13:05:18 +0100
commit1a7ba4adbc5c593de562cf2e320e82b32e66b7ad (patch)
tree1325fd08e4c2c5ea6f18de1c74ae5234d1971e7f
parenta02c22a6e1602eaf72422c06d1c772377c9a129d (diff)
parent3ca11d498d1bf386ce302972c202a6222128534d (diff)
Merge branch 'fetch-acc-settings-maybe' into develop
-rw-r--r--lisp/mastodon-profile.el52
-rw-r--r--lisp/mastodon-toot.el3
2 files changed, 32 insertions, 23 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 4aa9310..99af63a 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -296,30 +296,38 @@ This is done after changing the setting on the server."
(setq mastodon-profile-account-settings
(plist-put mastodon-profile-account-settings pref val)))
-(defun mastodon-profile-fetch-server-account-settings ()
+(defun mastodon-profile-fetch-server-account-settings-maybe ()
+ "Fetch account settings from the server if `mastodon-profile-account-settings' is nil."
+ (mastodon-profile-fetch-server-account-settings :no-force))
+
+(defun mastodon-profile-fetch-server-account-settings (&optional no-force)
"Fetch basic account settings from the server.
Store the values in `mastodon-profile-account-settings'.
-Run in `mastodon-mode-hook'."
- (let ((keys '(locked discoverable display_name bot))
- (source-keys '(privacy sensitive language)))
- (mapc (lambda (k)
- (mastodon-profile-update-preference-plist
- k
- (mastodon-profile--get-json-value k)))
- keys)
- (mapc (lambda (sk)
- (mastodon-profile-update-preference-plist
- sk
- (mastodon-profile--get-source-value sk)))
- source-keys)
- ;; hack for max toot chars:
- (mastodon-toot--get-max-toot-chars :no-toot)
- (mastodon-profile-update-preference-plist 'max_toot_chars
- mastodon-toot--max-toot-chars)
- ;; TODO: remove now redundant vars, replace with fetchers from the plist
- (setq mastodon-toot--visibility (mastodon-profile--get-pref 'privacy)
- mastodon-toot--content-nsfw (mastodon-profile--get-pref 'sensitive))
- mastodon-profile-account-settings))
+Run in `mastodon-mode-hook'.
+If NO-FORCE is non-nil, only fetch if `mastodon-profile-account-settings' is nil."
+ (unless
+ (and no-force
+ mastodon-profile-account-settings)
+ (let ((keys '(locked discoverable display_name bot))
+ (source-keys '(privacy sensitive language)))
+ (mapc (lambda (k)
+ (mastodon-profile-update-preference-plist
+ k
+ (mastodon-profile--get-json-value k)))
+ keys)
+ (mapc (lambda (sk)
+ (mastodon-profile-update-preference-plist
+ sk
+ (mastodon-profile--get-source-value sk)))
+ source-keys)
+ ;; hack for max toot chars:
+ (mastodon-toot--get-max-toot-chars :no-toot)
+ (mastodon-profile-update-preference-plist 'max_toot_chars
+ mastodon-toot--max-toot-chars)
+ ;; TODO: remove now redundant vars, replace with fetchers from the plist
+ (setq mastodon-toot--visibility (mastodon-profile--get-pref 'privacy)
+ mastodon-toot--content-nsfw (mastodon-profile--get-pref 'sensitive))
+ mastodon-profile-account-settings)))
(defun mastodon-profile-account-locked-toggle ()
"Toggle the locked status of your account.
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 7a40354..30f4a25 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -78,6 +78,7 @@
(autoload 'mastodon-profile--update-preference "mastodon-profile")
(autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile")
(autoload 'mastodon-tl--render-text "mastodon-tl")
+(autoload 'mastodon-profile-fetch-server-account-settings-maybe "mastodon-profile")
;; for mastodon-toot--translate-toot-text
(autoload 'mastodon-tl--content "mastodon-tl")
@@ -1284,7 +1285,7 @@ a draft into the buffer."
(insert initial-text))))
;;;###autoload
-(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings)
+(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings-maybe)
(define-minor-mode mastodon-toot-mode
"Minor mode to capture Mastodon toots."