From 6305a5b809fc9185626c2cbcdf43ba4416efeb11 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 20:15:28 +0530 Subject: 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. --- lisp/mastodon-client.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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'. -- cgit v1.2.3