From f3c05b9e17c43edc5ab0f7f7e06f87aeeca9283b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 11 Sep 2022 12:12:43 +0200 Subject: add 'sensitive' 'bot' and 'language' settings --- lisp/mastodon-profile.el | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 3065621..8b19863 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -216,7 +216,7 @@ JSON is the data returned by the server." (mastodon-search--insert-users-propertized json :note))) ;; (mastodon-profile--add-author-bylines json))) -;;; account preferences +;;; ACCOUNT PREFERENCES (defun mastodon-profile--get-json-value (val) "Fetch current VAL ue from account." @@ -285,10 +285,8 @@ This is done after changing the setting on the server." "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))) + (let ((keys '(locked discoverable display_name bot)) + (source-keys '(privacy sensitive language))) (mapc (lambda (k) (mastodon-profile-update-preference-alist k @@ -307,7 +305,7 @@ Run in `mastodon-mode-hook'." (defun mastodon-profile-account-locked-toggle () "Toggle the locked status of your account. -Locked accounts mean follow requests have to be manually approved." +Locked means follow requests have to be approved." (interactive) (mastodon-profile--toggle-account-key 'locked)) @@ -317,9 +315,24 @@ Discoverable means the account is listed in the server directory." (interactive) (mastodon-profile--toggle-account-key 'discoverable)) -(defun mastodon-profile--toggle-account-key (key) - "Toggle the boolean account setting KEY." - (let* ((val (mastodon-profile--get-json-value key)) +(defun mastodon-profile-account-bot-toggle () + "Toggle the bot status of your account." + (interactive) + (mastodon-profile--toggle-account-key 'bot)) + +;; TODO: actually respect "sensitive" account setting +(defun mastodon-profile-account-sensitive-toggle () + "Toggle the sensitive status of your account. +When enabled, statuses are marked as sensitive by default." + (interactive) + (mastodon-profile--toggle-account-key 'sensitive)) + +(defun mastodon-profile--toggle-account-key (key &optional source) + "Toggle the boolean account setting KEY. +SOURCE means the setting is located under \"source\" in the account JSON." + (let* ((val (if source + (mastodon-profile--get-source-pref key) + (mastodon-profile--get-json-value key))) (prompt (format "Account setting %s is %s. Toggle?" key val))) (if (not (equal val :json-false)) (when (y-or-n-p prompt) @@ -360,6 +373,8 @@ Discoverable means the account is listed in the server directory." "\n\n")))) (goto-char (point-min))))) +;; PROFILE VIEW DETAILS + (defun mastodon-profile--relationships-get (id) "Fetch info about logged-in user's relationship to user with id ID." (let* ((their-id id) -- cgit v1.2.3 From 5f9c329d6b8a8e309490b21c768cbfa8083d654e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 11 Sep 2022 12:37:45 +0200 Subject: set nsfw and visibility vars from our account-prefs plist - we cd remove these vars entirely and just use the plis + accessor fun --- lisp/mastodon-profile.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8b19863..87e00a4 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -273,12 +273,18 @@ 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) + (mastodon-profile-update-preference-plist pref val) (message "Account setting %s updated to %s!" pref val))))) -(defun mastodon-profile-update-preference-alist (pref val) +(defun mastodon-profile--get-pref (pref) + "Return PREF from `mastodon-profile-account-settings'." + (plist-get mastodon-profile-account-settings pref)) + +(defun mastodon-profile-update-preference-plist (pref val) "Set local account preference plist preference PREF to VAL. This is done after changing the setting on the server." + ;; TODO: convert all :json-false to nil and back again on sending + ;; (let ((val (if (eql :json-false val) nil val))) (setf (plist-get mastodon-profile-account-settings pref) val)) (defun mastodon-profile-fetch-server-account-settings () @@ -288,19 +294,22 @@ Run in `mastodon-mode-hook'." (let ((keys '(locked discoverable display_name bot)) (source-keys '(privacy sensitive language))) (mapc (lambda (k) - (mastodon-profile-update-preference-alist + (mastodon-profile-update-preference-plist k (mastodon-profile--get-json-value k))) keys) (mapc (lambda (sk) - (mastodon-profile-update-preference-alist + (mastodon-profile-update-preference-plist 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-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 () -- cgit v1.2.3 From a986ec502a305a9a55311bec8956b1f0331d2b16 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 11 Sep 2022 13:47:27 +0200 Subject: re-fetch acc settings from server after toggle --- lisp/mastodon-profile.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 87e00a4..e8b8622 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -273,7 +273,7 @@ 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-plist pref val) + (mastodon-profile-fetch-server-account-settings) (message "Account setting %s updated to %s!" pref val))))) (defun mastodon-profile--get-pref (pref) @@ -284,8 +284,8 @@ SOURCE means that the preference is in the 'source' part of the account json." "Set local account preference plist preference PREF to VAL. This is done after changing the setting on the server." ;; TODO: convert all :json-false to nil and back again on sending - ;; (let ((val (if (eql :json-false val) nil val))) - (setf (plist-get mastodon-profile-account-settings pref) val)) + (setq mastodon-profile-account-settings + (plist-put mastodon-profile-account-settings pref val))) (defun mastodon-profile-fetch-server-account-settings () "Fetch basic account settings from the server. -- cgit v1.2.3