aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-profile.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r--lisp/mastodon-profile.el63
1 files changed, 56 insertions, 7 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 516059e..0c91556 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -70,6 +70,7 @@
(defvar mastodon-tl--buffer-spec)
(defvar mastodon-tl--update-point)
(defvar mastodon-mode-map)
+(defvar mastodon-toot-visibility-list)
(defvar-local mastodon-profile--account nil
"The data for the account being described in the current profile buffer.")
@@ -207,14 +208,25 @@ JSON is the data returned by the server."
'byline t
'toot-id "0"))
(mastodon-search--insert-users-propertized json :note)))
- ;; (mastodon-profile--add-author-bylines json)))
+;; (mastodon-profile--add-author-bylines json)))
+
+;;; account preferences
+
+(defun mastodon-profile--get-source-prefs ()
+ "Return the \"source\" preferences from the server."
+ (let* ((url (mastodon-http--api "accounts/verify_credentials"))
+ (response (mastodon-http--get-json url)))
+ (alist-get 'source response)))
+
+(defun mastodon-profile--get-source-pref (pref)
+ "Return account PREF erence from the \"source\" section on the server."
+ (let ((source (mastodon-profile--get-source-prefs)))
+ (alist-get pref source)))
(defun mastodon-profile--update-user-profile-note ()
"Fetch user's profile note and display for editing."
(interactive)
- (let* ((url (concat mastodon-instance-url
- "/api/v1/accounts/update_credentials"))
- ;; (buffer (mastodon-http--patch url))
+ (let* ((url (mastodon-http--api "accounts/update_credentials"))
(json (mastodon-http--patch-json url))
(source (alist-get 'source json))
(note (alist-get 'note source))
@@ -236,13 +248,50 @@ JSON is the data returned by the server."
"Send PATCH request with the updated profile note."
(interactive)
(let* ((note (buffer-substring-no-properties (point-min) (point-max)))
- (url (concat mastodon-instance-url
- "/api/v1/accounts/update_credentials")))
+ (url (mastodon-http--api "accounts/update_credentials")))
(kill-buffer-and-window)
- (let ((response (mastodon-http--patch url note)))
+ (let ((response (mastodon-http--patch url `((note ,note)))))
(mastodon-http--triage response
(lambda () (message "Profile note updated!"))))))
+(defun mastodon-profile--update-preference (pref val &optional source)
+ "Update a single acount PREF erence to setting VAL.
+SOURCE means that the preference is in the 'source' part of the account json."
+ (let* ((url (mastodon-http--api "accounts/update_credentials"))
+ (pref (if source (concat "source[" pref "]") pref))
+ (response (mastodon-http--patch url `((,pref ,val)))))
+ (mastodon-http--triage response
+ (lambda ()
+ (message "Account setting %s updated!" pref)))))
+
+(defun mastodon-profile-set-default-toot-visibility ()
+ "Set the default visibility for toots."
+ (interactive)
+ (let ((vis (completing-read "Set default visibility to:"
+ mastodon-toot-visibility-list
+ nil t)))
+ (mastodon-profile--update-preference "privacy" vis :source)))
+
+(defun mastodon-profile-view-preferences ()
+ "View user preferences in another window."
+ (interactive)
+ (let* ((url (mastodon-http--api "preferences"))
+ (response (mastodon-http--get-json url))
+ (buf (get-buffer-create "*mastodon-preferences*")))
+ (with-current-buffer buf
+ (switch-to-buffer-other-window buf)
+ (erase-buffer)
+ (special-mode)
+ (let ((inhibit-read-only t))
+ (while response
+ (let ((el (pop response)))
+ (insert
+ (format "%-30s %s"
+ (prin1-to-string (car el))
+ (prin1-to-string (cdr el)))
+ "\n\n"))))
+ (goto-char (point-min)))))
+
(defun mastodon-profile--relationships-get (id)
"Fetch info about logged-in user's relationship to user with id ID."
(let* ((their-id id)