diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-09-10 18:22:29 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-09-10 18:22:29 +0200 |
commit | b2b33d85ef21b82059ecf97518795cd94221c576 (patch) | |
tree | 0b12c1bfd5bb073e50527f34540105551f4d4a74 /lisp/mastodon-profile.el | |
parent | bb257ae3cc0feae1f7bf8be03c1abf35800ce962 (diff) |
`mastodon-profile-account-settings` fetch on enter major mode
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r-- | lisp/mastodon-profile.el | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index cf27732..3065621 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -35,6 +35,7 @@ ;;; Code: (require 'seq) (require 'cl-lib) +(require 'persist) (autoload 'mastodon-http--api "mastodon-http.el") (autoload 'mastodon-http--get-json "mastodon-http.el") @@ -67,10 +68,12 @@ (autoload 'mastodon-toot "mastodon") (autoload 'mastodon-search--insert-users-propertized "mastodon-search") (autoload 'mastodon-tl--get-endpoint "mastodon-tl.el") +(autoload 'mastodon-toot--get-max-toot-chars "mastodon-toot") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) (defvar mastodon-mode-map) +(defvar mastodon-toot--max-toot-chars) (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") @@ -116,6 +119,9 @@ extra keybindings." map) "Keymap for `mastodon-profile-update-mode'.") +(persist-defvar mastodon-profile-account-settings nil + "An alist of account settings saved from the server.") + (define-minor-mode mastodon-profile-update-mode "Minor mode to update Mastodon user profile." :group 'mastodon-profile @@ -267,8 +273,38 @@ SOURCE means that the preference is in the 'source' part of the account json." (response (mastodon-http--patch url `((,pref-formatted ,val))))) (mastodon-http--triage response (lambda () + (mastodon-profile-update-preference-alist pref val) (message "Account setting %s updated to %s!" pref val))))) +(defun mastodon-profile-update-preference-alist (pref val) + "Set local account preference plist preference PREF to VAL. +This is done after changing the setting on the server." + (setf (plist-get mastodon-profile-account-settings pref) val)) + +(defun mastodon-profile-fetch-server-account-settings () + "Fetch basic account settings from the server. +Store the values in `mastodon-profile-account-settings'. +Run in `mastodon-mode-hook'." + ;; TODO: add some server settings like max_chars + (let ((keys '(locked discoverable display_name)) + (source-keys '(privacy))) + ;; (instance-keys '(max_toot_chars))) + (mapc (lambda (k) + (mastodon-profile-update-preference-alist + k + (mastodon-profile--get-json-value k))) + keys) + (mapc (lambda (sk) + (mastodon-profile-update-preference-alist + sk + (mastodon-profile--get-source-pref sk))) + source-keys) + ;; hack for max toot chars: + (mastodon-toot--get-max-toot-chars :no-toot) + (mastodon-profile-update-preference-alist 'max_toot_chars + mastodon-toot--max-toot-chars) + mastodon-profile-account-settings)) + (defun mastodon-profile-account-locked-toggle () "Toggle the locked status of your account. Locked accounts mean follow requests have to be manually approved." |