aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhiseck Paira <abhiseckpaira@disroot.org>2022-01-17 20:15:28 +0530
committerAbhiseck Paira <abhiseckpaira@disroot.org>2022-01-17 20:15:28 +0530
commit6305a5b809fc9185626c2cbcdf43ba4416efeb11 (patch)
treee1c68ce675734d8bde5f2563328b08e3f44faa8b
parentebb4bfcee21020cec5cae08955cf2a8c57d3532c (diff)
functions for making/checking active users
Define functions for like: * mastodon-client-make-user-active: Take one argument USER-DETAILS and make it the user details of the active user. * mastodon-client--make-current-user-active: Make the user details specified in the init file the current user. * mastodon-client--current-user-active-p: Return user-details if the current user is active, otherwise return nil.
-rw-r--r--lisp/mastodon-client.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el
index 1c3b2e1..d622e52 100644
--- a/lisp/mastodon-client.el
+++ b/lisp/mastodon-client.el
@@ -138,6 +138,15 @@ Return the plist after the operation."
(plstore-close plstore)
plstore-value))
+(defun mastodon-client-make-user-active (user-details)
+ "USER-DETAILS is a plist consisting of user details."
+ (let ((plstore (plstore-open (mastodon-client--token-file)))
+ (print-length nil)
+ (print-level nil))
+ (plstore-put plstore "active-user" user-details nil)
+ (plstore-save plstore)
+ (plstore-close plstore)))
+
(defun mastodon-client-form-user-from-vars ()
"Create a username from user variable. Return that username.
@@ -147,6 +156,24 @@ variables `mastodon-instance-url' and `mastodon-active-user'."
"@"
(url-host (url-generic-parse-url mastodon-instance-url))))
+(defun mastodon-client--make-current-user-active ()
+ "Make the user specified by user variables active user.
+Return the details (plist)."
+ (let ((username (mastodon-client-form-user-from-vars))
+ user-plist)
+ (when (setq user-plist
+ (mastodon-client--general-read (concat "user-" username)))
+ (mastodon-client-make-user-active user-plist))
+ user-plist))
+
+(defun mastodon-client--current-user-active-p ()
+ "Return user-details if the current user is active.
+Otherwise return nil."
+ (let ((username (mastodon-client-form-user-from-vars))
+ (user-details (mastodon-client--general-read "active-user")))
+ (when (and user-details
+ (equal (plist-get user-details :username) username))
+ user-details)))
(defun mastodon-client ()
"Return variable client secrets to use for `mastodon-instance-url'.