From 20db4e11f54e324af9e7e6c8f96a75589445629b Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Thu, 13 Jan 2022 16:03:11 +0530 Subject: mastodon.el: introduce new defcustom `mastodon-active-user' Use `mastodon-active-user' and `mastodon-instance-url' to determine which mastodon account the user wants to be active for the current session of Emacs. See the documentation string of this variable for details on how to use it. This new variable becomes necessary to prevent conflict when a user has two accounts on the same instance, that is same value of `mastodon-instance-url'. --- lisp/mastodon.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f65a86d..c7fcccf 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -95,6 +95,19 @@ (defcustom mastodon-instance-url "https://mastodon.social" "Base URL for the Masto instance from which you toot." +(defcustom mastodon-active-user "user" + "Username of the active user. + +For example, if your mastodon username is +\"example_user@social.instance.org\", and you want this account +to be active, the value of this variable should be +\"example_user\". + +Also for completeness, the value of `mastodon-instance-url' +should be \"https://social.instance.org\". + +After setting these variables you should restart Emacs for these +changes to take effect." :group 'mastodon :type 'string) -- cgit v1.2.3 From 2349750b607388a1a665c5e68b5708d9563ecaff Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Thu, 13 Jan 2022 16:22:10 +0530 Subject: mastodon.el: update `mastodon-instance-url' docstring Update the docstring for the defcustom `mastodon-instance-url' to clarify what it's value should be to reflect the changes introduced in the previous commit. --- lisp/mastodon.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index c7fcccf..2758f9d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -94,7 +94,21 @@ :group 'external) (defcustom mastodon-instance-url "https://mastodon.social" - "Base URL for the Masto instance from which you toot." + "Base URL for the Mastodon instance you want to be active. + +For example, if your mastodon username is +\"example_user@social.instance.org\", and you want this account +to be active, the value of this variable should be +\"https://social.instance.org\". + +Also for completeness, the value of `mastodon-active-user' should +be \"example_user\". + +After setting these variables you should restart Emacs for these +changes to take effect." + :group 'mastodon + :type 'string) + (defcustom mastodon-active-user "user" "Username of the active user. -- cgit v1.2.3 From 89add914c9e10979c271cdbb5f4af076ecbe41db Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 14:46:46 +0530 Subject: add helper function `mastodon-http-append-query-string' Add helper function `mastodon-http-append-query-string' which create URLs with query strings appended to its end. (see doc string for details.) --- lisp/mastodon-http.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f988e39..8e96b39 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -32,6 +32,7 @@ (require 'json) (require 'request) ; for attachments upload +(require 'url) (defvar mastodon-instance-url) (defvar mastodon-toot--media-attachment-ids) @@ -156,6 +157,13 @@ Pass response buffer to CALLBACK function." (with-temp-buffer (mastodon-http--url-retrieve-synchronously url)))) +(defun mastodon-http-append-query-string (url params) + "Append PARAMS to URL as query strings and return it. + +PARAMS should be an alist as required `url-build-query-string'." + (let ((query-string (url-build-query-string params))) + (concat url "?" query-string))) + ;; search functions: (defun mastodon-http--process-json-search () "Process JSON returned by a search query to the server." -- cgit v1.2.3 From 03365c8fbaac2c71e6bbfed731ae88d551175c2c Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 14:58:44 +0530 Subject: abstract Mastodon API request info Mastodon API requires some info that needs to be passed during app registration and user authentication. Those info were hard coded into various functions. Introduce three variables (defvars): 1. mastodon-client-scopes 2. mastodon-client-website 3. mastodon-client-redirect-uri use them to abstract those info. Also refactor `mastodon-client--register' function in terms of these variables. --- lisp/mastodon-client.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index b27d434..9fb45f7 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -46,14 +46,23 @@ (defvar mastodon-client--client-details-alist nil "An alist of Client id and secrets keyed by the instance url.") +(defvar mastodon-client-scopes "read write follow" + "Scopes to pass to oauth during registration.") + +(defvar mastodon-client-website "https://codeberg.org/martianh/mastodon.el" + "Website of mastodon.el.") + +(defvar mastodon-client-redirect-uri "urn:ietf:wg:oauth:2.0:oob" + "Redirect_uri as required by oauth.") + (defun mastodon-client--register () "POST client to Mastodon." (mastodon-http--post (mastodon-http--api "apps") - '(("client_name" . "mastodon.el") - ("redirect_uris" . "urn:ietf:wg:oauth:2.0:oob") - ("scopes" . "read write follow") - ("website" . "https://github.com/jdenen/mastodon.el")) + `(("client_name" . "mastodon.el") + ("redirect_uris" . ,mastodon-client-redirect-uri) + ("scopes" . ,mastodon-client-scopes) + ("website" . ,mastodon-client-website)) nil :unauthenticated)) -- cgit v1.2.3 From 9ca02d048fdb70c1edec189ddf87265dfb4c80b2 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Thu, 13 Jan 2022 20:07:42 +0530 Subject: re-implement user auth and token generation mechanism Refactor `mastodon-auth--generate-token' to work with new user authentication and token generation mechanism. This enables mastodon.el to work with 2FA and also not to handle password directly. In this implementation mastodon-auth--generate-token gets authorization code from the user and sends post request to mastodon server. Ask for authorization code from the user using two helper functions: * mastodon-auth--ask-authorization-code: Explain to the user what the user needs to do to get the authorization code. Store this explanation message in variable `mastodon-auth--explanation'. * mastodon-auth--get-browser-login-url: Return a appropriate query string appended to url to the caller, which is needed by the user to access the authorization code. --- lisp/mastodon-auth.el | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 74d4404..8a058f3 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -61,17 +61,32 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (defvar mastodon-auth--acct-alist nil "Alist of account accts (name@domain) keyed by instance url.") -(defun mastodon-auth--generate-token () - "Make POST to generate auth token. +(defun mastodon-auth--get-browser-login-url () + "Return properly formed browser login url." + (mastodon-http-append-query-string + (concat mastodon-instance-url "/oauth/authorize/") + `(("response_type" "code") + ("redirect_uri" ,mastodon-client-redirect-uri) + ("scope" ,mastodon-client-scopes) + ("client_id" ,(plist-get (mastodon-client) :client_id))))) + +(defvar mastodon-auth--explanation + (format + (concat "A URL has been copied to your clipboard.\n" + "Open this URL in a javascript capable browser.\n" + "Login to your account (%s) and authorize \"mastodon.el\".\n" + "Paste Authorization Code here: ") + (mastodon-client-form-user-from-vars))) + +(defun mastodon-auth--ask-authorization-code () + "Ask authorization code and return it." + (let ((url (mastodon-auth--get-browser-login-url)) + authorization-code) + (kill-new url) + (setq authorization-code (read-string mastodon-auth--explanation)) + authorization-code)) -If no auth-sources file, runs -`mastodon-auth--generate-token-no-storing-credentials'. If -auth-sources file exists, runs -`mastodon-auth--generate-token-and-store'." - (if (or (null mastodon-auth-source-file) - (string= "" mastodon-auth-source-file)) - (mastodon-auth--generate-token-no-storing-credentials) - (mastodon-auth--generate-token-and-store))) +(defun mastodon-auth--generate-token () (defun mastodon-auth--generate-token-no-storing-credentials () "Make POST to generate auth token, without using auth-sources file." @@ -115,6 +130,17 @@ Reads and/or stores secrets in `MASTODON-AUTH-SOURCE-FILE'." :unauthenticated) (when (functionp (plist-get credentials-plist :save-function)) (funcall (plist-get credentials-plist :save-function)))))) + "Generate access_token for the user. Return response buffer." + (let ((authorization-code (mastodon-auth--ask-authorization-code))) + (mastodon-http--post + (concat mastodon-instance-url "/oauth/token") + `(("grant_type" . "authorization_code") + ("client_secret" . ,(plist-get (mastodon-client) :client_secret)) + ("client_id" . ,(plist-get (mastodon-client) :client_id)) + ("code" . ,authorization-code) + ("redirect_uri" . ,mastodon-client-redirect-uri)) + nil + :unauthenticated))) (defun mastodon-auth--get-token () "Make a request to generate an auth token and return JSON response." -- cgit v1.2.3 From e18a2d541fca4c5f08f35d1de72d3a3ee9cfe011 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Thu, 13 Jan 2022 20:22:48 +0530 Subject: remove functions no longer needed Remove `mastodon-auth--generate-token-no-storing-credentials' and 'mastodon-auth--generate-token-and-store' as these two are no longer needed. --- lisp/mastodon-auth.el | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 8a058f3..55db0c0 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -87,49 +87,6 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." authorization-code)) (defun mastodon-auth--generate-token () - -(defun mastodon-auth--generate-token-no-storing-credentials () - "Make POST to generate auth token, without using auth-sources file." - (mastodon-http--post - (concat mastodon-instance-url "/oauth/token") - `(("client_id" . ,(plist-get (mastodon-client) :client_id)) - ("client_secret" . ,(plist-get (mastodon-client) :client_secret)) - ("grant_type" . "password") - ("username" . ,(read-string "Email: " user-mail-address)) - ("password" . ,(read-passwd "Password: ")) - ("scope" . "read write follow")) - nil - :unauthenticated)) - -(defun mastodon-auth--generate-token-and-store () - "Make POST to generate auth token. - -Reads and/or stores secrets in `MASTODON-AUTH-SOURCE-FILE'." - (let* ((auth-sources (list mastodon-auth-source-file)) - (auth-source-creation-prompts - '((user . "Enter email for %h: ") - (secret . "Password: "))) - (credentials-plist (nth 0 (auth-source-search - :create t - :host mastodon-instance-url - :port 443 - :require '(:user :secret))))) - (prog1 - (mastodon-http--post - (concat mastodon-instance-url "/oauth/token") - `(("client_id" . ,(plist-get (mastodon-client) :client_id)) - ("client_secret" . ,(plist-get (mastodon-client) :client_secret)) - ("grant_type" . "password") - ("username" . ,(plist-get credentials-plist :user)) - ("password" . ,(let ((secret (plist-get credentials-plist :secret))) - (if (functionp secret) - (funcall secret) - secret))) - ("scope" . "read write follow")) - nil - :unauthenticated) - (when (functionp (plist-get credentials-plist :save-function)) - (funcall (plist-get credentials-plist :save-function)))))) "Generate access_token for the user. Return response buffer." (let ((authorization-code (mastodon-auth--ask-authorization-code))) (mastodon-http--post -- cgit v1.2.3 From 2d5717faf83d59d11a4f89ce96eb326a39a5ee56 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 18:40:53 +0530 Subject: refactor *-access-token and *-handle-token-response Refactor `mastodon-auth--access-token' and `mastodon-auth--handle-token-response' to work with the new authentication mechanism. --- lisp/mastodon-auth.el | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 55db0c0..71f790a 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -111,16 +111,26 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (json-read-from-string json-string)))) (defun mastodon-auth--access-token () - "Return exiting or generate new access token. - -If an access token for `mastodon-instance-url' is in -`mastodon-auth--token-alist', return it. - -Otherwise, generate a token and pass it to -`mastodon-auth--handle-token-reponse'." - (if-let ((token (cdr (assoc mastodon-instance-url mastodon-auth--token-alist)))) - token - (mastodon-auth--handle-token-response (mastodon-auth--get-token)))) + "Return the access token to use with `mastodon-instance-url'. + +Generate/save token if none known yet." + (cond (mastodon-auth--token-alist + ;; user variables are known and + ;; initialised already. + (alist-get mastodon-instance-url mastodon-auth--token-alist + nil nil 'equal)) + ((plist-get (mastodon-client-active-user) :access_token) + ;; user variables needs to initialised by reading from + ;; plstore. + (push (cons mastodon-instance-url + (plist-get (mastodon-client-active-user) :access_token)) + mastodon-auth--token-alist) + (alist-get mastodon-instance-url mastodon-auth--token-alist + nil nil 'equal)) + (t + ;; user access-token needs to fetched from the server and + ;; stored and variables initialised. + (mastodon-auth--handle-token-response (mastodon-auth--get-token))))) (defun mastodon-auth--handle-token-response (response) "Add token RESPONSE to `mastodon-auth--token-alist'. @@ -131,6 +141,8 @@ Handle any errors from the server." (pcase response ((and (let token (plist-get response :access_token)) (guard token)) + (mastodon-client-make-user-active + (mastodon-client-store-access-token token)) (cdar (push (cons mastodon-instance-url token) mastodon-auth--token-alist))) -- cgit v1.2.3 From cd03ff5319dc60b4aa4f6d42f57b737e002cd923 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 19:31:55 +0530 Subject: abstract plstore implementation details of getting value Introduce a new function `mastodon-client--remove-key-from-plstore' which removes "key" part from a plstore item. Refactor `mastodon-client--read' to use `mastodon-client--remove-key-from-plstore'. --- lisp/mastodon-client.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 9fb45f7..04a26ce 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -97,11 +97,17 @@ Make `mastodon-client--fetch' call to determine client values." (plstore-close plstore) client)) +(defun mastodon-client--remove-key-from-plstore (plstore) + "Remove KEY from PLSTORE." + (cdr plstore)) + +;; Actually it returns a plist with client-details if such details are +;; already stored in mastodon.plstore (defun mastodon-client--read () "Retrieve client_id and client_secret from `mastodon-client--token-file'." (let* ((plstore (plstore-open (mastodon-client--token-file))) (mastodon (plstore-get plstore (concat "mastodon-" mastodon-instance-url)))) - (cdr mastodon))) + (mastodon-client--remove-key-from-plstore mastodon))) (defun mastodon-client () "Return variable client secrets to use for `mastodon-instance-url'. -- cgit v1.2.3 From 8e36abecbb8fa0df1aba30b1100130e5e382b92b Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 19:40:59 +0530 Subject: introduce a general plstore reading function Introduce a general version of `mastodon-client--read'[1] with the name `mastodon-client--general-read'[2] as [1] is too specific. [2] can be called with with a plstore "key" to retrieve the item keyed by that KEY. --- lisp/mastodon-client.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 04a26ce..7a857a2 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -109,6 +109,13 @@ Make `mastodon-client--fetch' call to determine client values." (mastodon (plstore-get plstore (concat "mastodon-" mastodon-instance-url)))) (mastodon-client--remove-key-from-plstore mastodon))) +(defun mastodon-client--general-read (key) + "Retrieve the plstore item keyed by KEY. +Return plist without the KEY." + (let* ((plstore (plstore-open (mastodon-client--token-file))) + (plstore-item (plstore-get plstore key))) + (mastodon-client--remove-key-from-plstore plstore-item))) + (defun mastodon-client () "Return variable client secrets to use for `mastodon-instance-url'. -- cgit v1.2.3 From a80bd14c4c22bf5aeda7b37e6f0631a9f4912384 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 19:55:33 +0530 Subject: get account ID from user variables specified in the init file Get user account ID from the mastodon variables specified in the init file by introducing the function `mastodon-client-form-user-from-vars'. Return user account ID in the form "user@instance.com" when the values of `mastodon-active-user' and `mastodon-instance-url' are "user" and "https://instance.com" respectively. --- lisp/mastodon-client.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 7a857a2..f7d06a5 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -116,6 +116,15 @@ Return plist without the KEY." (plstore-item (plstore-get plstore key))) (mastodon-client--remove-key-from-plstore plstore-item))) +(defun mastodon-client-form-user-from-vars () + "Create a username from user variable. Return that username. + +Username in the form user@instance.com is formed from the +variables `mastodon-instance-url' and `mastodon-active-user'." + (concat mastodon-active-user + "@" + (url-host (url-generic-parse-url mastodon-instance-url)))) + (defun mastodon-client () "Return variable client secrets to use for `mastodon-instance-url'. -- cgit v1.2.3 From ebb4bfcee21020cec5cae08955cf2a8c57d3532c Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 20:03:01 +0530 Subject: store access token in plstore of the current user Store access token in the plstore of the current user. To do that introduce the function `mastodon-client-store-access-token' of one argument TOKEN. Also define a helper function `mastodon-client--make-user-details-plist' which creates a plist with current users details and returns it. --- lisp/mastodon-client.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index f7d06a5..1c3b2e1 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -116,6 +116,28 @@ Return plist without the KEY." (plstore-item (plstore-get plstore key))) (mastodon-client--remove-key-from-plstore plstore-item))) +(defun mastodon-client--make-user-details-plist () + "Make a plist with current user details. Return it." + `(:username ,(mastodon-client-form-user-from-vars) + :instance ,mastodon-instance-url + :client_id ,(plist-get (mastodon-client) :client_id) + :client_secret ,(plist-get (mastodon-client) :client_secret))) + +(defun mastodon-client-store-access-token (token) + "Save TOKEN as :access_token in plstore of the current user. +Return the plist after the operation." + (let* ((user-details (mastodon-client--make-user-details-plist)) + (plstore (plstore-open (mastodon-client--token-file))) + (username (plist-get user-details :username)) + (plstore-value (setq user-details + (plist-put user-details :access_token token))) + (print-length nil) + (print-level nil)) + (plstore-put plstore (concat "user-" username) plstore-value nil) + (plstore-save plstore) + (plstore-close plstore) + plstore-value)) + (defun mastodon-client-form-user-from-vars () "Create a username from user variable. Return that username. -- cgit v1.2.3 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 From 639f89eb714efea5062bdbf21995033f57ea5207 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 20:23:22 +0530 Subject: make a public interface for accessing user details Introduce the function `mastodon-client-active-user' for public use which returns the details of the currently active users. It performs similar function as that of the function `mastodon-client'. --- lisp/mastodon-client.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index d622e52..e0ae34c 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -46,6 +46,9 @@ (defvar mastodon-client--client-details-alist nil "An alist of Client id and secrets keyed by the instance url.") +(defvar mastodon-client--active-user-details-plist nil + "A plist of active user details.") + (defvar mastodon-client-scopes "read write follow" "Scopes to pass to oauth during registration.") @@ -174,6 +177,20 @@ Otherwise return nil." (when (and user-details (equal (plist-get user-details :username) username)) user-details))) + +(defun mastodon-client-active-user () + "Return the details of the currently active user. + +Details is a plist." + (let ((active-user-details mastodon-client--active-user-details-plist)) + (unless active-user-details + (setq active-user-details + (or (mastodon-client--current-user-active-p) + (mastodon-client--make-current-user-active))) + (setq mastodon-client--active-user-details-plist + active-user-details)) + active-user-details)) + (defun mastodon-client () "Return variable client secrets to use for `mastodon-instance-url'. -- cgit v1.2.3 From 257209846e30e9ad7ac410e7dc7c72ecddb0b6ad Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 18:51:39 +0530 Subject: define autoloads and defvars to silence the byte compiler --- lisp/mastodon-auth.el | 7 +++++++ lisp/mastodon-client.el | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 71f790a..72c0333 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -39,7 +39,14 @@ (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") +(autoload 'mastodon-http-append-query-string "mastodon-http") +(autoload 'mastodon-client-store-access-token "mastodon-client") +(autoload 'mastodon-client-active-user "mastodon-client") +(autoload 'mastodon-client-make-user-active "mastodon-client") +(autoload 'mastodon-client-form-user-from-vars "mastodon-client") (defvar mastodon-instance-url) +(defvar mastodon-client-scopes) +(defvar mastodon-client-redirect-uri) (defgroup mastodon-auth nil "Authenticate with Mastodon." diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index e0ae34c..13e0150 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -32,8 +32,10 @@ (require 'plstore) (require 'json) +(require 'url) (defvar mastodon-instance-url) +(defvar mastodon-active-user) (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") -- cgit v1.2.3 From f037340225fecb16ed7bb92c26a56e0a96c8aee6 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 19:29:40 +0530 Subject: update copyright holder info Update Copyright holder info for files that have undergone non trivial changes. --- lisp/mastodon-auth.el | 1 + lisp/mastodon-client.el | 1 + lisp/mastodon.el | 1 + 3 files changed, 3 insertions(+) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 72c0333..c09dfdf 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -1,6 +1,7 @@ ;;; mastodon-auth.el --- Auth functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 13e0150..c577fec 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -1,6 +1,7 @@ ;;; mastodon-client.el --- Client functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2758f9d..d22c842 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -1,6 +1,7 @@ ;;; mastodon.el --- Client for Mastodon -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 -- cgit v1.2.3 From e9e09b44cf2e194f317073f7db192e6eb79759e7 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Tue, 28 Dec 2021 20:21:49 +0530 Subject: update README update the README to inform about the new changes. --- README.org | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/README.org b/README.org index 88e8c41..22b2531 100644 --- a/README.org +++ b/README.org @@ -75,10 +75,6 @@ This repo also incorporates fixes for two bugs that were never merged into the u - https://github.com/jdenen/mastodon.el/issues/227 (and https://github.com/jdenen/mastodon.el/issues/234) - https://github.com/jdenen/mastodon.el/issues/228 -** 2FA - -It looks like 2-factor auth was never completed in the original repo. It's not a priority for me, auth ain't my thing. If you want to hack on it, its on the develop branch in the original repo. - ** contributing Contributions are welcome. Registration is disabled by default on the gitea instance, but if you are interested, get in touch with me on mastodon: @@ -147,21 +143,31 @@ Or, with =use-package=: #+END_SRC ** Usage -*** 2 Factor Auth -2FA is not supported yet. It is in the [[https://github.com/jdenen/mastodon.el/milestone/2][plans]] for the =1.0.0= release. - -If you have 2FA enabled and try to use mastodon.el, your Emacs client will hang until you `C-g` your way out. *** Instance -Set =mastodon-instance-url= in your =.emacs= or =customize=. Defaults to the [[https://mastodon.social][flagship]]. +You need to set 2 variables in your init file to get started: + +1. mastodon-instance-url +2. mastodon-active-user + +(see their doc strings for details). For example If you want to post +toots as "example_user@social.instance.org", then put this in your init +file: #+BEGIN_SRC emacs-lisp - (setq mastodon-instance-url "https://my.instance.url") + (setq mastodon-instance-url "https://social.instance.org" + mastodon-active-user "example_user") #+END_SRC -There is an option to have your user credentials (email address and password) saved to disk so you don't have to re-enter them on every restart. -The default is not to do this because if not properly configured it would save these unencrypted which is not a good default to have. -Customize the variable =mastodon-auth-source-file= if you want to enable this feature. +Then *restart* Emacs and run =M-x mastodon=. Make sure you are connected +to internet before you do this. If you have multiple mastodon accounts +you can activate one at a time by changing those two variables and +restarting Emacs. + +If you have been using mastodon.el before this change and the above +steps do not work it's advisable that you delete the old file specified +by =mastodon-client--token-file= and restart Emacs and follow the steps +again. *** Timelines -- cgit v1.2.3 From 2cc711a12307b2f61d42233d0d3619ccd8f434ea Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 26 Jan 2022 21:18:21 +0530 Subject: test: change mastodon files loading order Before tests start test/ert-helper.el file is loaded which in turn loads other lisp/* files so that required functions and variables are defined during tests. Load lisp/mastodon.el file first before loading other files this solves the complain during tests that `mastodon-active-user' is not defined. --- test/ert-helper.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ert-helper.el b/test/ert-helper.el index a6d6692..fc4da2d 100644 --- a/test/ert-helper.el +++ b/test/ert-helper.el @@ -1,3 +1,4 @@ +(load-file "lisp/mastodon.el") (load-file "lisp/mastodon-search.el") (load-file "lisp/mastodon-async.el") (load-file "lisp/mastodon-http.el") @@ -11,4 +12,3 @@ (load-file "lisp/mastodon-search.el") (load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-toot.el") -(load-file "lisp/mastodon.el") -- cgit v1.2.3 From 6ff4416b809b7e8f2e7aab4e701633234dee8c1a Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 26 Jan 2022 21:05:51 +0530 Subject: test: update client website in mastodon-client--register The test `mastodon-client--register' specifies that the `mastodon-http--post' be called with a specific value. The value it specified is outdated since mastodon.el's current website has changed. So update the value with URL of the current website. --- test/mastodon-client-tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index 9123286..3f6cc29 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -10,7 +10,7 @@ '(("client_name" . "mastodon.el") ("redirect_uris" . "urn:ietf:wg:oauth:2.0:oob") ("scopes" . "read write follow") - ("website" . "https://github.com/jdenen/mastodon.el")) + ("website" . "https://codeberg.org/martianh/mastodon.el")) nil :unauthenticated)) (mastodon-client--register))) -- cgit v1.2.3 From 5071c96ad8b5af942eef5bf6c92d57929eb63188 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 26 Jan 2022 21:14:05 +0530 Subject: test: remove tests for non existent functions Remove the tests `mastodon-auth--generate-token--no-storing-credentials' and `mastodon-auth--generate-token--storing-credentials' as functions with similar names no longer exist (due to implementation of the new login mechanism) --- test/mastodon-auth-tests.el | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 6a090b7..5039bef 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -32,47 +32,6 @@ `(:error "invalid_grant" :error_description ,error-message)) (t error)))))) -(ert-deftest mastodon-auth--generate-token--no-storing-credentials () - "Should make `mastdon-http--post' request to generate auth token." - (with-mock - (let ((mastodon-auth-source-file "") - (mastodon-instance-url "https://instance.url")) - (mock (mastodon-client) => '(:client_id "id" :client_secret "secret")) - (mock (read-string "Email: " user-mail-address) => "foo@bar.com") - (mock (read-passwd "Password: ") => "password") - (mock (mastodon-http--post "https://instance.url/oauth/token" - '(("client_id" . "id") - ("client_secret" . "secret") - ("grant_type" . "password") - ("username" . "foo@bar.com") - ("password" . "password") - ("scope" . "read write follow")) - nil - :unauthenticated)) - (mastodon-auth--generate-token)))) - -(ert-deftest mastodon-auth--generate-token--storing-credentials () - "Should make `mastdon-http--post' request to generate auth token." - (with-mock - (let ((mastodon-auth-source-file "~/.authinfo") - (mastodon-instance-url "https://instance.url")) - (mock (mastodon-client) => '(:client_id "id" :client_secret "secret")) - (mock (auth-source-search :create t - :host "https://instance.url" - :port 443 - :require '(:user :secret)) - => '((:user "foo@bar.com" :secret (lambda () "password")))) - (mock (mastodon-http--post "https://instance.url/oauth/token" - '(("client_id" . "id") - ("client_secret" . "secret") - ("grant_type" . "password") - ("username" . "foo@bar.com") - ("password" . "password") - ("scope" . "read write follow")) - nil - :unauthenticated)) - (mastodon-auth--generate-token)))) - (ert-deftest mastodon-auth--get-token () "Should generate token and return JSON response." (with-temp-buffer -- cgit v1.2.3 From 7f6102b2ac7ba8b520b3ae53717dd064e0eebee8 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Thu, 27 Jan 2022 20:14:23 +0530 Subject: test: fix mastodon-auth--access-token-not-found Since the function `mastodon-auth--handle-token-response' now calls `mastodon-client-store-access-token' and `mastodon-client-make-user-active', define mock and stub for them respectively. --- test/mastodon-auth-tests.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 5039bef..3ff745f 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -56,6 +56,8 @@ (mastodon-auth--token-alist nil)) (with-mock (mock (mastodon-auth--get-token) => '(:access_token "foobaz")) + (mock (mastodon-client-store-access-token "foobaz")) + (stub mastodon-client-make-user-active) (should (string= (mastodon-auth--access-token) "foobaz")) -- cgit v1.2.3 From c6591296f2c2d65037fbf703d2b4ede197dcda15 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 19:52:35 +0100 Subject: add go to next toot to tl--thread --- lisp/mastodon-tl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 13c6729..c110fb2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -989,7 +989,8 @@ webapp" (mastodon-tl--timeline (vconcat (alist-get 'ancestors context) `(,toot) - (alist-get 'descendants context))))) + (alist-get 'descendants context))) + (mastodon-tl--goto-next-toot))) (message "No Thread!")))) (defun mastodon-tl--get-follow-suggestions () -- cgit v1.2.3 From 0a530ebd926fbc5feefc426eda2225a22bef4615 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 19:53:42 +0100 Subject: --search-accounts-query use http--api --- lisp/mastodon-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 6c85965..8c654cc 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -57,7 +57,7 @@ "Prompt for a search QUERY and return accounts synchronously. Returns a nested list containing user handle, display name, and URL." (interactive "sSearch mastodon for: ") - (let* ((url (format "%s/api/v1/accounts/search" mastodon-instance-url)) + (let* ((url (mastodon-http--api "accounts/search")) ;; (buffer (format "*mastodon-search-%s*" query)) (response (if (equal mastodon-toot--enable-completion-for-mentions "following") (mastodon-http--get-search-json url query "following=true") -- cgit v1.2.3 From aa6044e06b1a5bb332ac565528adc87bc19c8d42 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 19:56:43 +0100 Subject: create filter first crack --- lisp/mastodon-tl.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c110fb2..84df69f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -993,6 +993,24 @@ webapp" (mastodon-tl--goto-next-toot))) (message "No Thread!")))) +(defun mastodon-tl--create-filter (word contexts) + "Create a filter for WORD. +CONTEXTS must be a list containting at least one of \"home\", +\"notifications\", \"public\", \"thread\". " + (interactive) + (let* ((url (mastodon-http--api "filters")) + (contexts-processed + (mapcar (lambda (x) + (cons "context[]" x)) + contexts)) + (response + (mastodon-http--post url (push + `("phrase" . ,word) + contexts-processed) + nil))) + (with-current-buffer response + (switch-to-buffer (current-buffer))))) + (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." (interactive) -- cgit v1.2.3 From 918d34782ae3dba7a891825104affa0160b61b2c Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 20:42:22 +0100 Subject: fix go to first toot on thread load --- lisp/mastodon-tl.el | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 84df69f..67047a3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -962,7 +962,6 @@ webapp" (reblog (alist-get 'reblog json))) (if reblog (alist-get 'id reblog) id))) - (defun mastodon-tl--thread () "Open thread buffer for toot under `point'." (interactive) @@ -977,20 +976,21 @@ webapp" (if (> (+ (length (alist-get 'ancestors context)) (length (alist-get 'descendants context))) 0) - (with-output-to-temp-buffer buffer - (switch-to-buffer buffer) - (mastodon-mode) - (setq mastodon-tl--buffer-spec - `(buffer-name ,buffer - endpoint ,(format "statuses/%s/context" id) - update-function - (lambda(toot) (message "END of thread.")))) - (let ((inhibit-read-only t)) - (mastodon-tl--timeline (vconcat - (alist-get 'ancestors context) - `(,toot) - (alist-get 'descendants context))) - (mastodon-tl--goto-next-toot))) + (progn + (with-output-to-temp-buffer buffer + (switch-to-buffer buffer) + (mastodon-mode) + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,(format "statuses/%s/context" id) + update-function + (lambda (toot) (message "END of thread.")))) + (let ((inhibit-read-only t)) + (mastodon-tl--timeline (vconcat + (alist-get 'ancestors context) + `(,toot) + (alist-get 'descendants context))))) + (mastodon-tl--goto-next-toot)) (message "No Thread!")))) (defun mastodon-tl--create-filter (word contexts) -- cgit v1.2.3 From 2c75ce23691b885574c37fe84ab35015c12d4e19 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 20:43:08 +0100 Subject: second crack at create filter --- lisp/mastodon-tl.el | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 67047a3..2fbc889 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -993,23 +993,29 @@ webapp" (mastodon-tl--goto-next-toot)) (message "No Thread!")))) -(defun mastodon-tl--create-filter (word contexts) - "Create a filter for WORD. -CONTEXTS must be a list containting at least one of \"home\", -\"notifications\", \"public\", \"thread\". " +(defun mastodon-tl--create-filter () + "Create a filter for a word. +Prompt for a context, must be a list containting at least one of \"home\", +\"notifications\", \"public\", \"thread\"." (interactive) (let* ((url (mastodon-http--api "filters")) + (word (read-string + (format "Word to filter (%s): " (current-word)) + nil nil (current-word))) + (contexts (completing-read-multiple + "Contexts to filter [TAB for options]:" + '("home" "notifications" "public" "thread"))) (contexts-processed (mapcar (lambda (x) (cons "context[]" x)) contexts)) - (response - (mastodon-http--post url (push - `("phrase" . ,word) - contexts-processed) - nil))) - (with-current-buffer response - (switch-to-buffer (current-buffer))))) + (response (mastodon-http--post url (push + `("phrase" . ,word) + contexts-processed) + nil))) + (mastodon-http--triage response + (lambda () + (message "Filter created for %s!" word))))) (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." -- cgit v1.2.3 From ca740c747ae23370c2850b5df6262e366375d7e4 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 11 Feb 2022 00:48:00 +0530 Subject: test: merge mastodon-client--store1 and *store2 Merge `mastodon-client--store1' and `mastodon-client--store2' into a single test `mastodon-client--store' that test the function with the same name. --- test/mastodon-client-tests.el | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index 3f6cc29..6291d02 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -24,25 +24,22 @@ (current-buffer))) (should (equal (mastodon-client--fetch) '(:foo "bar")))))) -(ert-deftest mastodon-client--store-1 () - "Should return the client plist." +(ert-deftest mastodon-client--store () + "Test the value `mastodon-client--store' returns/stores." (let ((mastodon-instance-url "http://mastodon.example") (plist '(:client_id "id" :client_secret "secret"))) (with-mock (mock (mastodon-client--token-file) => "stubfile.plstore") - (mock (mastodon-client--fetch) => '(:client_id "id" :client_secret "secret")) - (let* ((plstore (plstore-open "stubfile.plstore")) - (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) - (should (equal (mastodon-client--store) plist)))))) + (mock (mastodon-client--fetch) => plist) + (should (equal (mastodon-client--store) plist))) + (let* ((plstore (plstore-open "stubfile.plstore")) + (client (mastodon-client--remove-key-from-plstore + (plstore-get plstore "mastodon-http://mastodon.example")))) + (plstore-close plstore) + (should (equal client plist)) + ;; clean up - delete the stubfile + (delete-file "stubfile.plstore")))) -(ert-deftest mastodon-client--store-2 () - "Should store client in `mastodon-client--token-file'." - (let* ((mastodon-instance-url "http://mastodon.example") - (plstore (plstore-open "stubfile.plstore")) - (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) - (plstore-close plstore) - (should (string= (plist-get client :client_id) "id")) - (should (string= (plist-get client :client_secret) "secret")))) (ert-deftest mastodon-client--read-finds-match () "Should return mastodon client from `mastodon-token-file' if it exists." -- cgit v1.2.3 From 949520069569b3b5397a00cca0d9671f3445ddea Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 14 Feb 2022 16:12:17 +0100 Subject: view and delete filters --- lisp/mastodon-tl.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2fbc889..a87fc2e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -162,6 +162,12 @@ types of mastodon links and not just shr.el-generated ones.") We need to override the keymap so tabbing will navigate to all types of mastodon links and not just shr.el-generated ones.") +(defvar mastodon-tl--view-filters-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "d") 'mastodon-tl--delete-filter) + (keymap-canonicalize map)) + "Keymap for viewing filters.") + (defun mastodon-tl--next-tab-item () "Move to the next interesting item. @@ -1015,7 +1021,58 @@ Prompt for a context, must be a list containting at least one of \"home\", nil))) (mastodon-http--triage response (lambda () - (message "Filter created for %s!" word))))) + (message "Filter created for %s!" word) + (when (string= (plist-get mastodon-tl--buffer-spec 'buffer-name) + "*mastodon-filters*") + (mastodon-tl--view-filters)))))) + +(defun mastodon-tl--view-filters () + "" + (interactive) + (let ((url (mastodon-http--api "filters"))) + (mastodon-tl--init-sync "*mastodon-filters*" + "filters" + 'mastodon-tl--insert-filters) + (mastodon-tl--goto-next-toot))) + +(defun mastodon-tl--insert-filters (json) + "" + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " CURRENT FILTERS\n" + " ------------\n\n") + 'success)) + (mapc (lambda (x) + (mastodon-tl--insert-filter-string x) + (insert "\n\n")) + json)) + +(defun mastodon-tl--insert-filter-string (filter) + "" + (let* ((phrase (alist-get 'phrase filter)) + (contexts (alist-get 'context filter)) + (id (alist-get 'id filter)) + (filter-string (concat "- \"" phrase "\" filtered in: " + (mapconcat #'identity contexts ", ")))) + (insert + (propertize filter-string + 'toot-id id ;for goto-next-toot compat + 'phrase phrase + 'help-echo "d to delete filter at point, n/p to go to next/prev filter." + 'keymap mastodon-tl--view-filters-keymap + 'byline t)))) ;for goto-next-toot compat + +(defun mastodon-tl--delete-filter () + "" + (interactive) + (let* ((filter-id (mastodon-tl--property 'toot-id)) + (phrase (mastodon-tl--property 'phrase)) + (url (mastodon-http--api + (format "filters/%s" filter-id))) + (response (mastodon-http--delete url))) + (mastodon-http--triage response (lambda () + (message "Filter for \"%s\" deleted!" phrase) + (mastodon-tl--view-filters))))) (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." -- cgit v1.2.3 From 6e68b7051595bf99bade4d3052286f95d606a155 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 14 Feb 2022 16:13:50 +0100 Subject: autoload -search--get-user-info for follow suggestions --- lisp/mastodon-tl.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e33aadf..f3c3527 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -63,6 +63,7 @@ (autoload 'mastodon-notifications--get "mastodon-notifications" "Display NOTIFICATIONS in buffer." t) ; interactive (autoload 'mastodon-search--insert-users-propertized "mastodon-search") +(autoload 'mastodon-search--get-user-info "mastodon-search") (when (require 'mpv nil :no-error) (declare-function mpv-start "mpv")) (defvar mastodon-instance-url) -- cgit v1.2.3 From 51378f17d14ff877dfea29e496be64383b65da93 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 13:03:47 +0100 Subject: buffer local keymap, error handling, make filters nicer - separate goto-next/prev-filter commands - we use properties toot-id and byline so the navigation works, calqued on - goto-prev/next-toot - error handle no word or context supplied - reload filters view on create or delete --- README.org | 3 +- lisp/mastodon-tl.el | 115 ++++++++++++++++++++++++++++++++++++---------------- lisp/mastodon.el | 2 + 3 files changed, 83 insertions(+), 37 deletions(-) diff --git a/README.org b/README.org index a2ed08f..fff0b09 100644 --- a/README.org +++ b/README.org @@ -29,12 +29,13 @@ It adds the following features: | =D= | delete and redraft toot at point, preserving reply/CW/visibility | | =W=, =M=, =B= | (un)follow, (un)mute, (un)block author of toot at point | | =k=, =K= | toggle bookmark of toot at point, view bookmarked toots | +| =L= | view, create, and delete filters | | | display polls and vote on them | | | images are links to the full image, can be zoomed/rotated/saved (see image keymap) | | | images scale properly | | | toot visibility (direct, followers only) icon appears in toot bylines | | | display toot's number of favorites, boosts and replies | -| | play gifs and videos (requires =mpv= to be installed) | +| | play gifs and videos (requires =mpv= to be installed) | | | customize option to cache images | | Toots: | | | | mention booster in replies by default | diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d69cb1a..0423e2e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -64,6 +64,8 @@ "Display NOTIFICATIONS in buffer." t) ; interactive (autoload 'mastodon-search--insert-users-propertized "mastodon-search") (autoload 'mastodon-search--get-user-info "mastodon-search") +(autoload 'mastodon-http--delete "mastodon-http") + (when (require 'mpv nil :no-error) (declare-function mpv-start "mpv")) (defvar mastodon-instance-url) @@ -171,6 +173,14 @@ types of mastodon links and not just shr.el-generated ones.") (defvar mastodon-tl--view-filters-keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "d") 'mastodon-tl--delete-filter) + (define-key map (kbd "c") 'mastodon-tl--create-filter) + (define-key map (kbd "n") 'mastodon-tl--goto-next-filter) + (define-key map (kbd "p") 'mastodon-tl--goto-prev-filter) + (define-key map (kbd "TAB") 'mastodon-tl--goto-next-filter) + (define-key map (kbd "g") 'mastodon-tl--view-filters) + (define-key map (kbd "t") 'mastodon-toot) + (define-key map (kbd "q") 'kill-current-buffer) + (define-key map (kbd "Q") 'kill-buffer-and-window) (keymap-canonicalize map)) "Keymap for viewing filters.") @@ -1102,18 +1112,25 @@ Prompt for a context, must be a list containting at least one of \"home\", (interactive) (let* ((url (mastodon-http--api "filters")) (word (read-string - (format "Word to filter (%s): " (current-word)) - nil nil (current-word))) - (contexts (completing-read-multiple - "Contexts to filter [TAB for options]:" - '("home" "notifications" "public" "thread"))) + (format "Word(s) to filter (%s): " (or (current-word) "")) + nil nil (or (current-word) ""))) + (contexts + (if (equal "" word) + (error "You must select at least one word for a filter") + (completing-read-multiple + "Contexts to filter [TAB for options]:" + '("home" "notifications" "public" "thread") + nil ; no predicate + t))) ; require-match, as context is mandatory (contexts-processed - (mapcar (lambda (x) - (cons "context[]" x)) - contexts)) + (if (equal nil contexts) + (error "You must select at least one context for a filter") + (mapcar (lambda (x) + (cons "context[]" x)) + contexts))) (response (mastodon-http--post url (push - `("phrase" . ,word) - contexts-processed) + `("phrase" . ,word) + contexts-processed) nil))) (mastodon-http--triage response (lambda () @@ -1123,28 +1140,39 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-tl--view-filters)))))) (defun mastodon-tl--view-filters () - "" + "View the user's filters in a new buffer." (interactive) - (let ((url (mastodon-http--api "filters"))) - (mastodon-tl--init-sync "*mastodon-filters*" - "filters" - 'mastodon-tl--insert-filters) - (mastodon-tl--goto-next-toot))) + (mastodon-tl--init-sync "filters" + "filters" + 'mastodon-tl--insert-filters) + (use-local-map mastodon-tl--view-filters-keymap) + (mastodon-tl--goto-next-filter)) (defun mastodon-tl--insert-filters (json) - "" + "Insert the user's current filters. +JSON is what is returned by by the server." (insert (mastodon-tl--set-face (concat "\n ------------\n" " CURRENT FILTERS\n" " ------------\n\n") - 'success)) - (mapc (lambda (x) - (mastodon-tl--insert-filter-string x) - (insert "\n\n")) - json)) + 'success) + (mastodon-tl--set-face + "[c - create filter\n d - delete filter at point\n n/p - go to next/prev filter]\n\n" + 'font-lock-comment-face)) + (if (not (equal json '[])) + (progn + (mapc (lambda (x) + (mastodon-tl--insert-filter-string x) + (insert "\n\n")) + json)) + (insert (propertize + "Looks like you have no filters for now." + 'face font-lock-comment-face + 'byline t + 'toot-id "0")))) ; so point can move here when no filters (defun mastodon-tl--insert-filter-string (filter) - "" + "Insert a single FILTER." (let* ((phrase (alist-get 'phrase filter)) (contexts (alist-get 'context filter)) (id (alist-get 'id filter)) @@ -1152,23 +1180,38 @@ Prompt for a context, must be a list containting at least one of \"home\", (mapconcat #'identity contexts ", ")))) (insert (propertize filter-string - 'toot-id id ;for goto-next-toot compat + 'toot-id id ;for goto-next-filter compat 'phrase phrase - 'help-echo "d to delete filter at point, n/p to go to next/prev filter." - 'keymap mastodon-tl--view-filters-keymap - 'byline t)))) ;for goto-next-toot compat + ;'help-echo "n/p to go to next/prev filter, c to create new filter, d to delete filter at point." + ;'keymap mastodon-tl--view-filters-keymap + 'byline t)))) ;for goto-next-filter compat (defun mastodon-tl--delete-filter () - "" + "Delete filter at point." (interactive) - (let* ((filter-id (mastodon-tl--property 'toot-id)) - (phrase (mastodon-tl--property 'phrase)) - (url (mastodon-http--api - (format "filters/%s" filter-id))) - (response (mastodon-http--delete url))) - (mastodon-http--triage response (lambda () - (message "Filter for \"%s\" deleted!" phrase) - (mastodon-tl--view-filters))))) + (let* ((filter-id (get-text-property (point) 'toot-id)) + (phrase (get-text-property (point) 'phrase)) + (url (mastodon-http--api + (format "filters/%s" filter-id)))) + (if (equal nil filter-id) + (error "No filter at point?") + (when (y-or-n-p (format "Delete this filter? "))) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response (lambda () + (mastodon-tl--view-filters) + (message "Filter for \"%s\" deleted!" phrase))))))) + +(defun mastodon-tl--goto-next-filter () + "Jump to next filter." + (interactive) + (mastodon-tl--goto-toot-pos 'next-single-property-change + 'next-line)) + +(defun mastodon-tl--goto-prev-filter () + "Jump to previous filter." + (interactive) + (mastodon-tl--goto-toot-pos 'previous-single-property-change + 'previous-line)) (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a52bf41..180674e 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -85,6 +85,7 @@ (autoload 'mastodon-tl--poll-vote "mastodon-http") ;; (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") +(autoload 'mastoton-tl--view-filters "mastodon-tl") ;; (autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") (defgroup mastodon nil @@ -164,6 +165,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "v") #'mastodon-tl--poll-vote) (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) + (define-key map (kbd "L") #'mastodon-tl--view-filters) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 0b01efc1187ca5d40839c8eed2d9ae7ddef144f7 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 14:03:22 +0100 Subject: make accept/reject foll reqs cmds avail in foll reqs view! --- lisp/mastodon-profile.el | 13 +++++++++++++ lisp/mastodon-tl.el | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5811a4a..d632e5e 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -57,6 +57,8 @@ (autoload 'mastodon-tl--init "mastodon-tl.el") (autoload 'mastodon-http--patch "mastodon-http") (autoload 'mastodon-http--patch-json "mastodon-http") +(autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") +(autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -72,6 +74,17 @@ map) "Keymap for `mastodon-profile-mode'.") +(defvar mastodon-profile--view-follow-requests-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "r") #'mastodon-notifications--follow-request-reject) + (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept) + ;; (define-key map (kbd "g") 'mastodon-notifications--view-follow-requests + ;; (define-key map (kbd "t") #'mastodon-toot) + (define-key map (kbd "q") #'kill-current-buffer) + (define-key map (kbd "Q") #'kill-buffer-and-window) + map) + "Keymap for viewing follow requests.") + (define-minor-mode mastodon-profile-mode "Toggle mastodon profile minor mode. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f3c3527..32bb73e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1462,7 +1462,8 @@ JSON is the data returned from the server." (mastodon-tl--goto-next-toot) (mastodon-mode) (when (equal endpoint "follow_requests") - (mastodon-profile-mode)) + (mastodon-profile-mode) + (use-local-map mastodon-profile--view-follow-requests-keymap)) (with-current-buffer buffer (setq mastodon-tl--buffer-spec `(buffer-name ,buffer -- cgit v1.2.3 From 907991314d0f4e2b88eeb093a6222468e77c9068 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 15:06:39 +0100 Subject: improve use of goto-next-toot on timeline loading --- lisp/mastodon-tl.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 32bb73e..efccc21 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1459,7 +1459,6 @@ JSON is the data returned from the server." mastodon-tl--timestamp-next-update (time-add (current-time) (seconds-to-time 300))) (funcall update-function json)) - (mastodon-tl--goto-next-toot) (mastodon-mode) (when (equal endpoint "follow_requests") (mastodon-profile-mode) @@ -1477,7 +1476,11 @@ JSON is the data returned from the server." nil ;; don't repeat #'mastodon-tl--update-timestamps-callback (current-buffer) - nil))))) + nil))) + (when (or (equal endpoint "notifications") + (string-prefix-p "timelines" endpoint) + (string-prefix-p "statuses" endpoint)) + (mastodon-tl--goto-next-toot)))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -1509,7 +1512,11 @@ Runs synchronously." nil ;; don't repeat #'mastodon-tl--update-timestamps-callback (current-buffer) - nil)))) + nil))) + (when (or (equal endpoint "notifications") + (string-prefix-p "timelines" endpoint) + (string-prefix-p "statuses" endpoint)) + (mastodon-tl--goto-next-toot))) buffer)) (provide 'mastodon-tl) -- cgit v1.2.3 From 53e522f84c7308b53eca606b52e4080e99cff035 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 15:28:02 +0100 Subject: fix view filters binding --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 180674e..c8ceee7 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -165,7 +165,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "v") #'mastodon-tl--poll-vote) (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) - (define-key map (kbd "L") #'mastodon-tl--view-filters) + (define-key map (kbd "I") #'mastodon-tl--view-filters) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 787f18dcff2ee7a4c5a5cbf331f4e2d26997e1cc Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 15:30:58 +0100 Subject: replace all calls to mastodon-search--insert-users-propertized with calls to mastodon-profile--add-author-bylines. --- lisp/mastodon-profile.el | 3 +-- lisp/mastodon-search.el | 24 ++---------------------- lisp/mastodon-tl.el | 3 ++- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index d632e5e..8ac0b67 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -398,8 +398,7 @@ FIELD is used to identify regions under 'account" (defun mastodon-profile--add-author-bylines (tootv) "Convert TOOTV into a author-bylines and insert." (let ((inhibit-read-only t)) - (if (equal tootv '[]) - (message "Looks like you have no follow requests for the moment.") + (when (not (equal tootv '[])) (mapc (lambda (toot) (let ((start-pos (point))) (insert "\n" diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index d17b054..2f8054a 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -98,7 +98,8 @@ Returns a nested list containing user handle, display name, and URL." " USERS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized user-ids :note) + (mastodon-profile--add-author-bylines accts) + ;; (mastodon-search--insert-users-propertized user-ids :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -124,27 +125,6 @@ Returns a nested list containing user handle, display name, and URL." (mapc 'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) -(defun mastodon-search--insert-users-propertized (users &optional note) - "Insert USERS list into the buffer. -If NOTE is non-nil, include user's profile note. -This is also called by `mastodon-tl--get-follow-suggestions'." - (mapc (lambda (el) - (insert (propertize (car el) 'face 'mastodon-display-name-face) - " : \n : " - (propertize (concat "@" (car (cdr el))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (car (cdr el))) - 'help-echo (concat "Browse user profile of @" (car (cdr el)))) - " : \n" - (if note - (mastodon-tl--render-text (cadddr el) nil) - "") - "\n")) - users)) - (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." (list (alist-get 'display_name account) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index efccc21..26364a6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1107,7 +1107,8 @@ webapp" " SUGGESTED ACCOUNTS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized users :note))))) + (mastodon-profile--add-author-bylines response))))) + ;; (mastodon-search--insert-users-propertized users :note))))) (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. -- cgit v1.2.3 From f10b33b7a6a9975a4627a4e4e9adc118c0a49a92 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 15:31:55 +0100 Subject: factor out a decent insert-follow-requests fun --- lisp/mastodon-profile.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8ac0b67..f779648 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -161,7 +161,21 @@ extra keybindings." (interactive) (mastodon-tl--init "follow-requests" "follow_requests" - 'mastodon-profile--add-author-bylines)) + 'mastodon-profile--insert-follow-requests)) + +(defun mastodon-profile--insert-follow-requests (json) + "Insert the user's current follow requests. +JSON is the data returned by the server." + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " FOLLOW REQUESTS\n" + " ------------\n\n") + 'success)) + (if (equal json '[]) + (insert (propertize + "Looks like you have no follow requests for now." + 'face font-lock-comment-face)) + (mastodon-profile--add-author-bylines json))) (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." -- cgit v1.2.3 From b26b4f835aee9317c13e98922342994e26a54078 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 16:21:00 +0100 Subject: more robust goto-first-toot on timeline/thread load rather than using goto-next-toot, which loops when we have no items in buffer --- lisp/mastodon-tl.el | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c059de8..deaa196 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -290,6 +290,15 @@ Optionally start from POS." (mastodon-tl--goto-toot-pos 'next-single-property-change 'mastodon-tl--more)) +(defun mastodon-tl--goto-first-toot () + "Jump to first toot or item in buffer. +Used on initializing a timeline or thread." + ;; goto-next-toot assumes we already have toots, and is therefore + ;; incompatible with any view where it is possible to have no items. + ;; when that is the case the call to goto-toot-pos loops infinitely + (mastodon-tl--goto-toot-pos 'next-single-property-change + 'next-line)) ;dummy function as we need to feed it something + (defun mastodon-tl--goto-prev-toot () "Jump to last toot header." (interactive) @@ -1604,7 +1613,7 @@ JSON is the data returned from the server." (when (or (equal endpoint "notifications") (string-prefix-p "timelines" endpoint) (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-next-toot)))) + (mastodon-tl--goto-first-toot)))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -1637,11 +1646,12 @@ Runs synchronously." #'mastodon-tl--update-timestamps-callback (current-buffer) nil))) - (when (or (equal endpoint "notifications") - (string-prefix-p "timelines" endpoint) - (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-next-toot))) - buffer)) + (when (and (not (equal json '[])) + (or (equal endpoint "notifications") + (string-prefix-p "timelines" endpoint) + (string-prefix-p "statuses" endpoint)) + (mastodon-tl--goto-first-toot)))) + buffer)) (provide 'mastodon-tl) ;;; mastodon-tl.el ends here -- cgit v1.2.3 From b2302027969ec305969c4024296b05f50e4f1846 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 17:04:35 +0100 Subject: make profile--extract-user-handles compat with foll req view this allows following users directly from foll req views made extract-users-handles work with follwers/following in profile view --- lisp/mastodon-profile.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index f779648..857c349 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -454,7 +454,12 @@ If the handle does not match a search return then retun NIL." These include the author, author of reblogged entries and any user mentioned." (when status - (let ((this-account (alist-get 'account status)) + (let ((this-account + ;; follow suggestions view compat: + (if (or (equal (buffer-name) "*mastodon-follow-suggestions*") + (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) + (mastodon-tl--property 'toot-json) + (alist-get 'account status))) (mentions (alist-get 'mentions status)) (reblog (alist-get 'reblog status))) (seq-filter -- cgit v1.2.3 From 7058db5848987df4c089bd0c0e34813f830d372c Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 17:06:03 +0100 Subject: add generic goto-next/prev-item funs for filters/foll reqs fix remnant call to goto-next-filter --- lisp/mastodon-profile.el | 6 ++++-- lisp/mastodon-tl.el | 14 +++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 857c349..c7f8963 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -78,8 +78,10 @@ (let ((map (make-sparse-keymap))) (define-key map (kbd "r") #'mastodon-notifications--follow-request-reject) (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept) - ;; (define-key map (kbd "g") 'mastodon-notifications--view-follow-requests - ;; (define-key map (kbd "t") #'mastodon-toot) + (define-key map (kbd "n") #'mastodon-tl--goto-next-item) + (define-key map (kbd "p") #'mastodon-tl--goto-prev-item) + (define-key map (kbd "g") 'mastodon-notifications--view-follow-requests) + (define-key map (kbd "t") #'mastodon-toot) (define-key map (kbd "q") #'kill-current-buffer) (define-key map (kbd "Q") #'kill-buffer-and-window) map) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index deaa196..34b2881 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -174,8 +174,8 @@ types of mastodon links and not just shr.el-generated ones.") (let ((map (make-sparse-keymap))) (define-key map (kbd "d") 'mastodon-tl--delete-filter) (define-key map (kbd "c") 'mastodon-tl--create-filter) - (define-key map (kbd "n") 'mastodon-tl--goto-next-filter) - (define-key map (kbd "p") 'mastodon-tl--goto-prev-filter) + (define-key map (kbd "n") 'mastodon-tl--goto-next-item) + (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) (define-key map (kbd "TAB") 'mastodon-tl--goto-next-filter) (define-key map (kbd "g") 'mastodon-tl--view-filters) (define-key map (kbd "t") 'mastodon-toot) @@ -1155,7 +1155,7 @@ Prompt for a context, must be a list containting at least one of \"home\", "filters" 'mastodon-tl--insert-filters) (use-local-map mastodon-tl--view-filters-keymap) - (mastodon-tl--goto-next-filter)) + (mastodon-tl--goto-next-item)) (defun mastodon-tl--insert-filters (json) "Insert the user's current filters. @@ -1210,14 +1210,14 @@ JSON is what is returned by by the server." (mastodon-tl--view-filters) (message "Filter for \"%s\" deleted!" phrase))))))) -(defun mastodon-tl--goto-next-filter () - "Jump to next filter." +(defun mastodon-tl--goto-next-item () + "Jump to next item, e.g. filter or follow request." (interactive) (mastodon-tl--goto-toot-pos 'next-single-property-change 'next-line)) -(defun mastodon-tl--goto-prev-filter () - "Jump to previous filter." +(defun mastodon-tl--goto-prev-item () + "Jump to previous item, e.g. filter or follow request." (interactive) (mastodon-tl--goto-toot-pos 'previous-single-property-change 'previous-line)) -- cgit v1.2.3 From 0be1c740ba3f4f3f86a3d81567fcb5cd1b9683a9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 17:07:01 +0100 Subject: invert if call in filters insert --- lisp/mastodon-tl.el | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 34b2881..e8634dd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1168,17 +1168,16 @@ JSON is what is returned by by the server." (mastodon-tl--set-face "[c - create filter\n d - delete filter at point\n n/p - go to next/prev filter]\n\n" 'font-lock-comment-face)) - (if (not (equal json '[])) - (progn - (mapc (lambda (x) - (mastodon-tl--insert-filter-string x) - (insert "\n\n")) - json)) - (insert (propertize - "Looks like you have no filters for now." - 'face font-lock-comment-face - 'byline t - 'toot-id "0")))) ; so point can move here when no filters + (if (equal json '[]) + (insert (propertize + "Looks like you have no filters for now." + 'face font-lock-comment-face + 'byline t + 'toot-id "0")) ; so point can move here when no filters + (mapc (lambda (x) + (mastodon-tl--insert-filter-string x) + (insert "\n\n")) + json))) (defun mastodon-tl--insert-filter-string (filter) "Insert a single FILTER." -- cgit v1.2.3 From a6a9c5201e51b07af2be5e4e581c364e28108947 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 17:07:26 +0100 Subject: add mini docs for foll reqs view reload foll reqs view on accept/reject --- lisp/mastodon-notifications.el | 3 ++- lisp/mastodon-profile.el | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 5e3305a..40f9c04 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -109,7 +109,8 @@ follow-requests view." nil nil))) (mastodon-http--triage response (lambda () - (unless f-reqs-view-p + (if f-reqs-view-p + (mastodon-profile--view-follow-requests) (mastodon-notifications--get)) (message "Follow request of %s (@%s) %s!" name handle (if reject diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c7f8963..e15a891 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -172,7 +172,10 @@ JSON is the data returned by the server." (concat "\n ------------\n" " FOLLOW REQUESTS\n" " ------------\n\n") - 'success)) + 'success) + (mastodon-tl--set-face + "[a/r - accept/reject request at point\n n/p - go to next/prev request]\n\n" + 'font-lock-comment-face)) (if (equal json '[]) (insert (propertize "Looks like you have no follow requests for now." -- cgit v1.2.3 From 48a89e518d0a84d4b81c223c9e8cf151df619b1f Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 19:13:23 +0100 Subject: move faves count help-echo propertize into tl--byline this means that we only do the propertizing when we are actually doing an author byline, docstring for add-author-bylines it also needs renaming --- lisp/mastodon-profile.el | 6 ++++- lisp/mastodon-tl.el | 63 ++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index e15a891..8388d05 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -415,7 +415,11 @@ FIELD is used to identify regions under 'account" (cdr (assoc field account))) (defun mastodon-profile--add-author-bylines (tootv) - "Convert TOOTV into a author-bylines and insert." + "Convert TOOTV into a author-bylines and insert. +Also insert their profile note. +Used to view a user's followers and those they're following, as +well as the list of suggested followers and for search results." + ;;FIXME change the name of this fun now that we've edited what it does! (let ((inhibit-read-only t)) (when (not (equal tootv '[])) (mapc (lambda (toot) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e8634dd..327b682 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -333,11 +333,10 @@ Used on initializing a timeline or thread." 'face 'mastodon-display-name-face ;; enable playing of videos when point is on byline: 'attachments (mastodon-tl--get-attachments-for-byline toot) - 'keymap mastodon-tl--byline-link-keymap - ;; echo faves count when point on post author name: - ;; which is where --goto-next-toot puts point. - 'help-echo - (mastodon-tl--format-faves-count toot)) + 'keymap mastodon-tl--byline-link-keymap) + ;; help-echo propertized moved to `mastodon-tl--byline + ;; 'help-echo + ;; (mastodon-tl--format-faves-count toot)) " (" (propertize (concat "@" handle) 'face 'mastodon-handle-face @@ -505,32 +504,34 @@ By default it is `mastodon-tl--byline-boosted'" (when faved (mastodon-tl--format-faved-or-boosted-byline "F"))) (propertize - (concat - ;; we propertize help-echo format faves for author name - ;; in `mastodon-tl--byline-author' - (funcall author-byline toot) - (cond ((equal visibility "direct") - (if (fontp (char-displayable-p #10r128274)) - " ✉" - " [direct]")) - ((equal visibility "private") - (if (fontp (char-displayable-p #10r9993)) - " 🔒" - " [followers]"))) - (funcall action-byline toot) - " " - ;; TODO: Once we have a view for toot (responses etc.) make - ;; this a tab stop and attach an action. - (propertize - (format-time-string mastodon-toot-timestamp-format parsed-time) - 'timestamp parsed-time - 'display (if mastodon-tl--enable-relative-timestamps - (mastodon-tl--relative-time-description parsed-time) - parsed-time)) - (propertize "\n ------------\n" 'face 'default)) - 'favourited-p faved - 'boosted-p boosted - 'byline t)))) + ;; echo faves count when point on + ;; author byline, which is where --goto-next-toot puts + ;; point. + (concat (propertize + (funcall author-byline toot) + 'help-echo (mastodon-tl--format-faves-count toot)) + (cond ((equal visibility "direct") + (if (fontp (char-displayable-p #10r128274)) + " ✉" + " [direct]")) + ((equal visibility "private") + (if (fontp (char-displayable-p #10r9993)) + " 🔒" + " [followers]"))) + (funcall action-byline toot) + " " + ;; TODO: Once we have a view for toot (responses etc.) make + ;; this a tab stop and attach an action. + (propertize + (format-time-string mastodon-toot-timestamp-format parsed-time) + 'timestamp parsed-time + 'display (if mastodon-tl--enable-relative-timestamps + (mastodon-tl--relative-time-description parsed-time) + parsed-time)) + (propertize "\n ------------\n" 'face 'default)) + 'favourited-p faved + 'boosted-p boosted + 'byline t)))) (defun mastodon-tl--format-faved-or-boosted-byline (letter) "Format the byline marker for a boosted or favorited status. -- cgit v1.2.3 From c589a9451a9b9b6e942fa8de9ece41ce9e8bd174 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 16 Feb 2022 21:54:09 +0530 Subject: test: fixture: update client.plstore file update the sample data in fixture/client.plstore file. --- fixture/client.plstore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fixture/client.plstore b/fixture/client.plstore index e050018..48d951c 100644 --- a/fixture/client.plstore +++ b/fixture/client.plstore @@ -1,3 +1,6 @@ ;;; public entries -*- mode: plstore -*- (("mastodon-http://other.example" :client_id "id1" :client_secret "secret1") - ("mastodon-http://mastodon.example" :client_id "id2" :client_secret "secret2")) + ("mastodon-http://mastodon.example" :client_id "id2" :client_secret "secret2") + ("user-test8000@mastodon.example" :username "test8000@mastodon.example" :instance "http://mastodon.example" :client_id "id2" :client_secret "secret2" :access_token "token2") + ("active-user" :username "test9000@other.example" :instance "http://other.example" :client_id "id1" :client_secret "secret1" :access_token "token1") + ("user-test9000@other.example" :username "test9000@other.example" :instance "http://other.example" :client_id "id1" :client_secret "secret1" :access_token "token1")) -- cgit v1.2.3 From f1ef6f7c8accc7ce3fd44373776727afe3d8957c Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 16 Feb 2022 21:57:04 +0530 Subject: test: add test for mastodon-client--general-read --- test/mastodon-client-tests.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index 6291d02..3c667b1 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -49,6 +49,27 @@ (should (equal (mastodon-client--read) '(:client_id "id2" :client_secret "secret2")))))) +(ert-deftest mastodon-client--general-read-finds-match () + (with-mock + (mock (mastodon-client--token-file) => "fixture/client.plstore") + (should (equal (mastodon-client--general-read "user-test8000@mastodon.example") + '(:username "test8000@mastodon.example" + :instance "http://mastodon.example" + :client_id "id2" :client_secret "secret2" + :access_token "token2"))))) + +(ert-deftest mastodon-client--general-read-finds-no-match () + (with-mock + (mock (mastodon-client--token-file) => "fixture/client.plstore") + (should (equal (mastodon-client--general-read "nonexistant-key") + nil)))) + +(ert-deftest mastodon-client--general-read-empty-store () + (with-mock + (mock (mastodon-client--token-file) => "fixture/empty.plstore") + (should (equal (mastodon-client--general-read "something") + nil)))) + (ert-deftest mastodon-client--read-finds-no-match () "Should return mastodon client from `mastodon-token-file' if it exists." (let ((mastodon-instance-url "http://mastodon.social")) -- cgit v1.2.3 From 77c173afc1f24fa371c41d0c59b94a8650eb4f61 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 16 Feb 2022 21:59:15 +0530 Subject: test: add more test Add the following tests: * mastodon-client--current-user-active-p * mastodon-client-store-access-token * mastodon-client-make-user-active * mastodon-client-form-user-from-vars --- test/mastodon-client-tests.el | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index 3c667b1..c2ec50c 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -121,3 +121,54 @@ (should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz"))) (should (equal mastodon-client--client-details-alist '(("http://mastodon.example" :client_id "foo" :client_secret "baz"))))))) + +(ert-deftest mastodon-client-form-user-from-vars () + (let ((mastodon-active-user "test9000") + (mastodon-instance-url "https://mastodon.example")) + (should + (equal (mastodon-client-form-user-from-vars) + "test9000@mastodon.example")))) + +(ert-deftest mastodon-client--current-user-active-p () + (let ((mastodon-active-user "test9000") + (mastodon-instance-url "https://mastodon.example")) + ;; when the current user /is/ the active user + (with-mock + (mock (mastodon-client--general-read "active-user") => '(:username "test9000@mastodon.example" :client_id "id1")) + (should (equal (mastodon-client--current-user-active-p) + '(:username "test9000@mastodon.example" :client_id "id1")))) + ;; when the current user is /not/ the active user + (with-mock + (mock (mastodon-client--general-read "active-user") => '(:username "user@other.example" :client_id "id1")) + (should (null (mastodon-client--current-user-active-p)))))) + +(ert-deftest mastodon-client-store-access-token () + (let ((mastodon-instance-url "https://mastodon.example") + (mastodon-active-user "test8000") + (user-details + '(:username "test8000@mastodon.example" + :instance "https://mastodon.example" + :client_id "id" :client_secret "secret" + :access_token "token"))) + ;; test if mastodon-client-store-access-token /returns/ right + ;; value + (with-mock + (mock (mastodon-client) => '(:client_id "id" :client_secret "secret")) + (mock (mastodon-client--token-file) => "stubfile.plstore") + (should (equal (mastodon-client-store-access-token "token") + user-details))) + ;; test if mastodon-client-store-access-token /stores/ right value + (with-mock + (mock (mastodon-client--token-file) => "stubfile.plstore") + (should (equal (mastodon-client--general-read + "user-test8000@mastodon.example") + user-details))) + (delete-file "stubfile.plstore"))) + +(ert-deftest mastodon-client-make-user-active () + (let ((user-details '(:username "test@mastodon.example"))) + (with-mock + (mock (mastodon-client--token-file) => "stubfile.plstore") + (mastodon-client-make-user-active user-details) + (should (equal (mastodon-client--general-read "active-user") + user-details))))) -- cgit v1.2.3 From 79790bad6b6d0bb5a43459e3d2f8da9701ed8908 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 19:23:25 +0100 Subject: improve follow suggestions suggestions fix fun names(!) --- lisp/mastodon-tl.el | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 327b682..6c6f4e1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -184,6 +184,19 @@ types of mastodon links and not just shr.el-generated ones.") (keymap-canonicalize map)) "Keymap for viewing filters.") +(defvar mastodon-tl--view-suggestions-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "W") 'mastodon-tl--follow-user) + (define-key map (kbd "n") 'mastodon-tl--goto-next-item) + (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) + (define-key map (kbd "TAB") 'mastodon-tl--goto-next-item) + (define-key map (kbd "g") 'mastodon-tl--get-follow-suggestions) + (define-key map (kbd "t") 'mastodon-toot) + (define-key map (kbd "q") 'kill-current-buffer) + (define-key map (kbd "Q") 'kill-buffer-and-window) + (keymap-canonicalize map)) + "Keymap for viewing follow suggestions.") + (defvar mastodon-tl--byline-link-keymap (when (require 'mpv nil :no-error) (let ((map (make-sparse-keymap))) @@ -1223,24 +1236,25 @@ JSON is what is returned by by the server." 'previous-line)) (defun mastodon-tl--get-follow-suggestions () -"Display a buffer of suggested accounts to follow." + "Display a buffer of suggested accounts to follow." (interactive) - (let* ((buffer (format "*mastodon-follow-suggestions*")) - (response - (mastodon-http--get-json - (mastodon-http--api "suggestions"))) - (users (mapcar 'mastodon-search--get-user-info response))) - (with-output-to-temp-buffer buffer - (let ((inhibit-read-only t)) - (switch-to-buffer buffer) - (mastodon-mode) - (insert (mastodon-tl--set-face - (concat "\n ------------\n" - " SUGGESTED ACCOUNTS\n" - " ------------\n\n") - 'success)) - (mastodon-profile--add-author-bylines response))))) - ;; (mastodon-search--insert-users-propertized users :note))))) + (mastodon-tl--init-sync "follow-suggestions" + "suggestions" + 'mastodon-tl--insert-follow-suggestions) + (use-local-map mastodon-tl--view-suggestions-keymap) + (mastodon-tl--goto-next-item)) + +(defun mastodon-tl--insert-follow-suggestions (response) + "Insert follow suggestions into buffer. +RESPONSE is the JSON returned by the server." + (let* ((users (mapcar 'mastodon-search--get-user-info response))) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " SUGGESTED ACCOUNTS\n" + " ------------\n\n") + 'success)) + (mastodon-profile--add-author-bylines response) + (goto-char (point-min)))) (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. -- cgit v1.2.3 From 5ae600a4431f7d3f0b2b6c93999465f1c75391e2 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 19:33:44 +0100 Subject: fix reload on filter create in filter view --- lisp/mastodon-tl.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6c6f4e1..8fa4813 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1158,8 +1158,9 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-http--triage response (lambda () (message "Filter created for %s!" word) - (when (string= (plist-get mastodon-tl--buffer-spec 'buffer-name) - "*mastodon-filters*") + ;; reload if we are in filters view: + (when (string= (mastodon-tl--get-endpoint) + "filters") (mastodon-tl--view-filters)))))) (defun mastodon-tl--view-filters () -- cgit v1.2.3 From f37c97de8b192caf68d4b39c3830e85b5aa09d2e Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 19:49:28 +0100 Subject: Revert "move faves count help-echo propertize into tl--byline" This reverts commit 48a89e518d0a84d4b81c223c9e8cf151df619b1f. --- lisp/mastodon-tl.el | 63 ++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8fa4813..d82a0a5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -346,10 +346,11 @@ Used on initializing a timeline or thread." 'face 'mastodon-display-name-face ;; enable playing of videos when point is on byline: 'attachments (mastodon-tl--get-attachments-for-byline toot) - 'keymap mastodon-tl--byline-link-keymap) - ;; help-echo propertized moved to `mastodon-tl--byline - ;; 'help-echo - ;; (mastodon-tl--format-faves-count toot)) + 'keymap mastodon-tl--byline-link-keymap + ;; echo faves count when point on post author name: + ;; which is where --goto-next-toot puts point. + 'help-echo + (mastodon-tl--format-faves-count toot)) " (" (propertize (concat "@" handle) 'face 'mastodon-handle-face @@ -517,34 +518,32 @@ By default it is `mastodon-tl--byline-boosted'" (when faved (mastodon-tl--format-faved-or-boosted-byline "F"))) (propertize - ;; echo faves count when point on - ;; author byline, which is where --goto-next-toot puts - ;; point. - (concat (propertize - (funcall author-byline toot) - 'help-echo (mastodon-tl--format-faves-count toot)) - (cond ((equal visibility "direct") - (if (fontp (char-displayable-p #10r128274)) - " ✉" - " [direct]")) - ((equal visibility "private") - (if (fontp (char-displayable-p #10r9993)) - " 🔒" - " [followers]"))) - (funcall action-byline toot) - " " - ;; TODO: Once we have a view for toot (responses etc.) make - ;; this a tab stop and attach an action. - (propertize - (format-time-string mastodon-toot-timestamp-format parsed-time) - 'timestamp parsed-time - 'display (if mastodon-tl--enable-relative-timestamps - (mastodon-tl--relative-time-description parsed-time) - parsed-time)) - (propertize "\n ------------\n" 'face 'default)) - 'favourited-p faved - 'boosted-p boosted - 'byline t)))) + (concat + ;; we propertize help-echo format faves for author name + ;; in `mastodon-tl--byline-author' + (funcall author-byline toot) + (cond ((equal visibility "direct") + (if (fontp (char-displayable-p #10r128274)) + " ✉" + " [direct]")) + ((equal visibility "private") + (if (fontp (char-displayable-p #10r9993)) + " 🔒" + " [followers]"))) + (funcall action-byline toot) + " " + ;; TODO: Once we have a view for toot (responses etc.) make + ;; this a tab stop and attach an action. + (propertize + (format-time-string mastodon-toot-timestamp-format parsed-time) + 'timestamp parsed-time + 'display (if mastodon-tl--enable-relative-timestamps + (mastodon-tl--relative-time-description parsed-time) + parsed-time)) + (propertize "\n ------------\n" 'face 'default)) + 'favourited-p faved + 'boosted-p boosted + 'byline t)))) (defun mastodon-tl--format-faved-or-boosted-byline (letter) "Format the byline marker for a boosted or favorited status. -- cgit v1.2.3 From 5c6fa1b6aae1c0b1bf09b2be700958351feb1861 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 20:28:44 +0100 Subject: Revert "replace all calls to mastodon-search--insert-users-propertized" This reverts commit 787f18dcff2ee7a4c5a5cbf331f4e2d26997e1cc. --- lisp/mastodon-search.el | 24 ++++++++++++++++++++++-- lisp/mastodon-tl.el | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 2f8054a..d17b054 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -98,8 +98,7 @@ Returns a nested list containing user handle, display name, and URL." " USERS\n" " ------------\n\n") 'success)) - (mastodon-profile--add-author-bylines accts) - ;; (mastodon-search--insert-users-propertized user-ids :note) + (mastodon-search--insert-users-propertized user-ids :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -125,6 +124,27 @@ Returns a nested list containing user handle, display name, and URL." (mapc 'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) +(defun mastodon-search--insert-users-propertized (users &optional note) + "Insert USERS list into the buffer. +If NOTE is non-nil, include user's profile note. +This is also called by `mastodon-tl--get-follow-suggestions'." + (mapc (lambda (el) + (insert (propertize (car el) 'face 'mastodon-display-name-face) + " : \n : " + (propertize (concat "@" (car (cdr el))) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (car (cdr el))) + 'help-echo (concat "Browse user profile of @" (car (cdr el)))) + " : \n" + (if note + (mastodon-tl--render-text (cadddr el) nil) + "") + "\n")) + users)) + (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." (list (alist-get 'display_name account) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d82a0a5..3167f9c 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1253,7 +1253,7 @@ RESPONSE is the JSON returned by the server." " SUGGESTED ACCOUNTS\n" " ------------\n\n") 'success)) - (mastodon-profile--add-author-bylines response) + (mastodon-search--insert-users-propertized users :note) (goto-char (point-min)))) (defun mastodon-tl--follow-user (user-handle &optional notify) -- cgit v1.2.3 From f545d8c1d65e3e2256f8b769bfdb87a5b6a1e3ea Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 20:30:34 +0100 Subject: move next/prev item funs --- lisp/mastodon-tl.el | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3167f9c..ec9c033 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -303,6 +303,12 @@ Optionally start from POS." (mastodon-tl--goto-toot-pos 'next-single-property-change 'mastodon-tl--more)) +(defun mastodon-tl--goto-prev-toot () + "Jump to last toot header." + (interactive) + (mastodon-tl--goto-toot-pos 'previous-single-property-change + 'mastodon-tl--update)) + (defun mastodon-tl--goto-first-toot () "Jump to first toot or item in buffer. Used on initializing a timeline or thread." @@ -312,11 +318,17 @@ Used on initializing a timeline or thread." (mastodon-tl--goto-toot-pos 'next-single-property-change 'next-line)) ;dummy function as we need to feed it something -(defun mastodon-tl--goto-prev-toot () - "Jump to last toot header." +(defun mastodon-tl--goto-next-item () + "Jump to next item, e.g. filter or follow request." + (interactive) + (mastodon-tl--goto-toot-pos 'next-single-property-change + 'next-line)) + +(defun mastodon-tl--goto-prev-item () + "Jump to previous item, e.g. filter or follow request." (interactive) (mastodon-tl--goto-toot-pos 'previous-single-property-change - 'mastodon-tl--update)) + 'previous-line)) (defun mastodon-tl--remove-html (toot) "Remove unrendered tags from TOOT." @@ -1223,18 +1235,6 @@ JSON is what is returned by by the server." (mastodon-tl--view-filters) (message "Filter for \"%s\" deleted!" phrase))))))) -(defun mastodon-tl--goto-next-item () - "Jump to next item, e.g. filter or follow request." - (interactive) - (mastodon-tl--goto-toot-pos 'next-single-property-change - 'next-line)) - -(defun mastodon-tl--goto-prev-item () - "Jump to previous item, e.g. filter or follow request." - (interactive) - (mastodon-tl--goto-toot-pos 'previous-single-property-change - 'previous-line)) - (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." (interactive) -- cgit v1.2.3 From 1c0328ced821b152e3da911592a6acd12d8598dd Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 21:55:10 +0100 Subject: re-factor follow-user functions for various views - revert profile--extract-users-handles - rewrite search--insert-users-propertized to handle raw account JSON, and to call search--get-user-info itself, so we can add full acct JSON to each user displayed and use it for follow-user etc. - and to choose how we want to follow users, we edit tl--interactive-user-handles-get to work differently depending on context: - poss contexts are "follow suggestions" view, search results, and profiles displaying a user's followers/followed users. --- lisp/mastodon-profile.el | 11 +++-------- lisp/mastodon-search.el | 48 ++++++++++++++++++++++++++++-------------------- lisp/mastodon-tl.el | 15 ++++++++++++--- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8388d05..5504065 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -463,14 +463,9 @@ If the handle does not match a search return then retun NIL." These include the author, author of reblogged entries and any user mentioned." (when status - (let ((this-account - ;; follow suggestions view compat: - (if (or (equal (buffer-name) "*mastodon-follow-suggestions*") - (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) - (mastodon-tl--property 'toot-json) - (alist-get 'account status))) - (mentions (alist-get 'mentions status)) - (reblog (alist-get 'reblog status))) + (let ((this-account (alist-get 'account status)) + (mentions (alist-get 'mentions status)) + (reblog (alist-get 'reblog status))) (seq-filter 'stringp (seq-uniq diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index d17b054..726b76e 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -89,16 +89,16 @@ Returns a nested list containing user handle, display name, and URL." status-ids-list))) (with-current-buffer (get-buffer-create buffer) (switch-to-buffer buffer) - (erase-buffer) (mastodon-mode) (let ((inhibit-read-only t)) + (erase-buffer) ;; user results: (insert (mastodon-tl--set-face (concat "\n ------------\n" " USERS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized user-ids :note) + (mastodon-search--insert-users-propertized accts :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -124,26 +124,34 @@ Returns a nested list containing user handle, display name, and URL." (mapc 'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) -(defun mastodon-search--insert-users-propertized (users &optional note) - "Insert USERS list into the buffer. +(defun mastodon-search--insert-users-propertized (json &optional note) + "Insert users list into the buffer. +JSON is the data from the server.. If NOTE is non-nil, include user's profile note. This is also called by `mastodon-tl--get-follow-suggestions'." - (mapc (lambda (el) - (insert (propertize (car el) 'face 'mastodon-display-name-face) - " : \n : " - (propertize (concat "@" (car (cdr el))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (car (cdr el))) - 'help-echo (concat "Browse user profile of @" (car (cdr el)))) - " : \n" - (if note - (mastodon-tl--render-text (cadddr el) nil) - "") - "\n")) - users)) + (mapc (lambda (acct) + (let ((user (mastodon-search--get-user-info acct))) + (insert + (propertize + (concat (propertize (car user) + 'face 'mastodon-display-name-face + 'byline t + 'toot-id "0") + " : \n : " + (propertize (concat "@" (cadr user)) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (cadr user)) + 'help-echo (concat "Browse user profile of @" (cadr user))) + " : \n" + (if note + (mastodon-tl--render-text (cadddr user) nil) + "") + "\n") + 'user-json acct)))) + json)) (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ec9c033..6bb5656 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1253,7 +1253,7 @@ RESPONSE is the JSON returned by the server." " SUGGESTED ACCOUNTS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized users :note) + (mastodon-search--insert-users-propertized response :note) (goto-char (point-min)))) (defun mastodon-tl--follow-user (user-handle &optional notify) @@ -1321,8 +1321,17 @@ Can be called to toggle NOTIFY on users already being followed." (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." - (let ((user-handles (mastodon-profile--extract-users-handles - (mastodon-profile--toot-json)))) + (let ((user-handles + ;; follow suggests / search compat: + (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") + (string-prefix-p "*mastodon-search" (buffer-name))) + (list (alist-get 'acct (mastodon-tl--property 'user-json)))) + ;; profile view follows/followers compat: + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (list (alist-get 'acct (mastodon-tl--property 'toot-json)))) + (t + (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))))) (completing-read (if (or (equal action "disable") (equal action "enable")) (format "%s notifications when user posts: " action) -- cgit v1.2.3 From 507a1a00541863fc2a1e7c9a56176aa98167e791 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 22:38:09 +0100 Subject: rename goto-first-toot to goto-first-item and enable it in "favourites" buffer --- lisp/mastodon-tl.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6bb5656..923ad79 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -309,14 +309,14 @@ Optionally start from POS." (mastodon-tl--goto-toot-pos 'previous-single-property-change 'mastodon-tl--update)) -(defun mastodon-tl--goto-first-toot () +(defun mastodon-tl--goto-first-item () "Jump to first toot or item in buffer. Used on initializing a timeline or thread." ;; goto-next-toot assumes we already have toots, and is therefore ;; incompatible with any view where it is possible to have no items. ;; when that is the case the call to goto-toot-pos loops infinitely - (mastodon-tl--goto-toot-pos 'next-single-property-change - 'next-line)) ;dummy function as we need to feed it something + (goto-char (point-min)) + (mastodon-tl--goto-next-item)) (defun mastodon-tl--goto-next-item () "Jump to next item, e.g. filter or follow request." @@ -1635,8 +1635,9 @@ JSON is the data returned from the server." nil))) (when (or (equal endpoint "notifications") (string-prefix-p "timelines" endpoint) + (string-prefix-p "favourites" endpoint) (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-first-toot)))) + (mastodon-tl--goto-first-item)))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -1672,8 +1673,9 @@ Runs synchronously." (when (and (not (equal json '[])) (or (equal endpoint "notifications") (string-prefix-p "timelines" endpoint) + (string-prefix-p "favourites" endpoint) (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-first-toot)))) + (mastodon-tl--goto-first-item)))) buffer)) (provide 'mastodon-tl) -- cgit v1.2.3 From 4a6dd954a999cd84198b56795795361bc492183a Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 10:29:59 +0100 Subject: remove unused let binding user-ids --- lisp/mastodon-search.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 726b76e..1c7f00e 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -77,8 +77,9 @@ Returns a nested list containing user handle, display name, and URL." (accts (alist-get 'accounts response)) (tags (alist-get 'hashtags response)) (statuses (alist-get 'statuses response)) - (user-ids (mapcar #'mastodon-search--get-user-info - accts)) ; returns a list of three-item lists + ;; this is now done in search--insert-users-propertized + ;; (user-ids (mapcar #'mastodon-search--get-user-info + ;; accts)) ; returns a list of three-item lists (tags-list (mapcar #'mastodon-search--get-hashtag-info tags)) ;; (status-list (mapcar #'mastodon-search--get-status-info -- cgit v1.2.3 From bc164b9eb3df4e4050d0c4a05fea7c9b5b368178 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 10:30:56 +0100 Subject: fix up follow requests view: own inheriting keymap uses init-sync now also --- lisp/mastodon-profile.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5504065..b5e1489 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -55,14 +55,20 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-tl--toot "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl.el") +(autoload 'mastodon-tl--init-sync "mastodon-tl") (autoload 'mastodon-http--patch "mastodon-http") (autoload 'mastodon-http--patch-json "mastodon-http") (autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") (autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") +(autoload 'mastodon-tl--goto-next-item "mastodon-tl") +(autoload 'mastodon-tl--goto-prev-item "mastodon-tl") +(autoload 'mastodon-tl--goto-first-item "mastodon-tl") +(autoload 'mastodon-toot "mastodon") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) +(defvar mastodon-mode-map) (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") @@ -75,15 +81,16 @@ "Keymap for `mastodon-profile-mode'.") (defvar mastodon-profile--view-follow-requests-keymap - (let ((map (make-sparse-keymap))) + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) (define-key map (kbd "r") #'mastodon-notifications--follow-request-reject) (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept) (define-key map (kbd "n") #'mastodon-tl--goto-next-item) (define-key map (kbd "p") #'mastodon-tl--goto-prev-item) - (define-key map (kbd "g") 'mastodon-notifications--view-follow-requests) - (define-key map (kbd "t") #'mastodon-toot) - (define-key map (kbd "q") #'kill-current-buffer) - (define-key map (kbd "Q") #'kill-buffer-and-window) + (define-key map (kbd "g") 'mastodon-profile--view-follow-requests) + ;; (define-key map (kbd "t") #'mastodon-toot) + ;; (define-key map (kbd "q") #'kill-current-buffer) + ;; (define-key map (kbd "Q") #'kill-buffer-and-window) map) "Keymap for viewing follow requests.") @@ -161,9 +168,11 @@ extra keybindings." (defun mastodon-profile--view-follow-requests () "Open a new buffer displaying the user's follow requests." (interactive) - (mastodon-tl--init "follow-requests" - "follow_requests" - 'mastodon-profile--insert-follow-requests)) + (mastodon-tl--init-sync "follow-requests" + "follow_requests" + 'mastodon-profile--insert-follow-requests) + (use-local-map mastodon-profile--view-follow-requests-keymap) + (mastodon-tl--goto-first-item)) (defun mastodon-profile--insert-follow-requests (json) "Insert the user's current follow requests. @@ -179,7 +188,9 @@ JSON is the data returned by the server." (if (equal json '[]) (insert (propertize "Looks like you have no follow requests for now." - 'face font-lock-comment-face)) + 'face font-lock-comment-face + 'byline t + 'toot-id "0")) (mastodon-profile--add-author-bylines json))) (defun mastodon-profile--update-user-profile-note () -- cgit v1.2.3 From 241aa9b35101e6e8814e4aab64597caf6a285f75 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 15 Feb 2022 21:54:30 +0100 Subject: fix view filters/foll suggests - they get keymaps that inherit and so override the main masto keymap, which allows them to still have the basic timeline/view nav functions. - but we give them next-item rather than next toot so that they never try to e.g. load for toots into the buffer, which wouldn't work. - also remove the reference to foll requests view in tl--init as it is not longer needed. binding for follow suggestions remove tab from foll suggests keymap makes tab work as default, which means you can n/p to next/prev user, while still being able to tab to user next handle, to visit profile squashed commit: remove foll suggestions keymap --- lisp/mastodon-tl.el | 45 ++++++++++++++++++--------------------------- lisp/mastodon.el | 1 + 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 923ad79..eaafd74 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -71,6 +71,7 @@ (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this +(defvar mastodon-mode-map) (defgroup mastodon-tl nil "Timelines in Mastodon." @@ -171,33 +172,27 @@ We need to override the keymap so tabbing will navigate to all types of mastodon links and not just shr.el-generated ones.") (defvar mastodon-tl--view-filters-keymap - (let ((map (make-sparse-keymap))) + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) (define-key map (kbd "d") 'mastodon-tl--delete-filter) (define-key map (kbd "c") 'mastodon-tl--create-filter) (define-key map (kbd "n") 'mastodon-tl--goto-next-item) (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) - (define-key map (kbd "TAB") 'mastodon-tl--goto-next-filter) + (define-key map (kbd "TAB") 'mastodon-tl--goto-next-item) (define-key map (kbd "g") 'mastodon-tl--view-filters) - (define-key map (kbd "t") 'mastodon-toot) - (define-key map (kbd "q") 'kill-current-buffer) - (define-key map (kbd "Q") 'kill-buffer-and-window) (keymap-canonicalize map)) - "Keymap for viewing filters.") + "Keymap for viewing filters.") -(defvar mastodon-tl--view-suggestions-keymap - (let ((map (make-sparse-keymap))) - (define-key map (kbd "W") 'mastodon-tl--follow-user) +(defvar mastodon-tl--follow-suggestions-map + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) (define-key map (kbd "n") 'mastodon-tl--goto-next-item) (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) - (define-key map (kbd "TAB") 'mastodon-tl--goto-next-item) (define-key map (kbd "g") 'mastodon-tl--get-follow-suggestions) - (define-key map (kbd "t") 'mastodon-toot) - (define-key map (kbd "q") 'kill-current-buffer) - (define-key map (kbd "Q") 'kill-buffer-and-window) (keymap-canonicalize map)) - "Keymap for viewing follow suggestions.") + "Keymap for viewing follow suggestions.") -(defvar mastodon-tl--byline-link-keymap + (defvar mastodon-tl--byline-link-keymap (when (require 'mpv nil :no-error) (let ((map (make-sparse-keymap))) (define-key map (kbd "") 'mastodon-tl--mpv-play-video-from-byline) @@ -1241,20 +1236,19 @@ JSON is what is returned by by the server." (mastodon-tl--init-sync "follow-suggestions" "suggestions" 'mastodon-tl--insert-follow-suggestions) - (use-local-map mastodon-tl--view-suggestions-keymap) + (use-local-map mastodon-tl--follow-suggestions-map) (mastodon-tl--goto-next-item)) (defun mastodon-tl--insert-follow-suggestions (response) "Insert follow suggestions into buffer. RESPONSE is the JSON returned by the server." - (let* ((users (mapcar 'mastodon-search--get-user-info response))) - (insert (mastodon-tl--set-face - (concat "\n ------------\n" - " SUGGESTED ACCOUNTS\n" - " ------------\n\n") - 'success)) - (mastodon-search--insert-users-propertized response :note) - (goto-char (point-min)))) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " SUGGESTED ACCOUNTS\n" + " ------------\n\n") + 'success)) + (mastodon-search--insert-users-propertized response :note) + (goto-char (point-min))) (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. @@ -1616,9 +1610,6 @@ JSON is the data returned from the server." (seconds-to-time 300))) (funcall update-function json)) (mastodon-mode) - (when (equal endpoint "follow_requests") - (mastodon-profile-mode) - (use-local-map mastodon-profile--view-follow-requests-keymap)) (with-current-buffer buffer (setq mastodon-tl--buffer-spec `(buffer-name ,buffer diff --git a/lisp/mastodon.el b/lisp/mastodon.el index c8ceee7..51e27ec 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -166,6 +166,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) (define-key map (kbd "I") #'mastodon-tl--view-filters) + (define-key map (kbd "G") #'mastodon-tl--get-follow-suggestions) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 7d12bfac3c9adfae63529cc2a9d10ab006fc7b5f Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 10:37:23 +0100 Subject: cleanup indentation in tl.el cleanup indents --- lisp/mastodon-profile.el | 4 +- lisp/mastodon-search.el | 46 ++++++++++----------- lisp/mastodon-tl.el | 102 +++++++++++++++++++++++------------------------ 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b5e1489..0119a36 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -475,8 +475,8 @@ If the handle does not match a search return then retun NIL." These include the author, author of reblogged entries and any user mentioned." (when status (let ((this-account (alist-get 'account status)) - (mentions (alist-get 'mentions status)) - (reblog (alist-get 'reblog status))) + (mentions (alist-get 'mentions status)) + (reblog (alist-get 'reblog status))) (seq-filter 'stringp (seq-uniq diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 1c7f00e..e1ca81a 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -130,29 +130,29 @@ Returns a nested list containing user handle, display name, and URL." JSON is the data from the server.. If NOTE is non-nil, include user's profile note. This is also called by `mastodon-tl--get-follow-suggestions'." - (mapc (lambda (acct) - (let ((user (mastodon-search--get-user-info acct))) - (insert - (propertize - (concat (propertize (car user) - 'face 'mastodon-display-name-face - 'byline t - 'toot-id "0") - " : \n : " - (propertize (concat "@" (cadr user)) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (cadr user)) - 'help-echo (concat "Browse user profile of @" (cadr user))) - " : \n" - (if note - (mastodon-tl--render-text (cadddr user) nil) - "") - "\n") - 'user-json acct)))) - json)) + (mapc (lambda (acct) + (let ((user (mastodon-search--get-user-info acct))) + (insert + (propertize + (concat (propertize (car user) + 'face 'mastodon-display-name-face + 'byline t + 'toot-id "0") + " : \n : " + (propertize (concat "@" (cadr user)) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (cadr user)) + 'help-echo (concat "Browse user profile of @" (cadr user))) + " : \n" + (if note + (mastodon-tl--render-text (cadddr user) nil) + "") + "\n") + 'user-json acct)))) + json)) (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index eaafd74..2c2c6ec 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -362,12 +362,12 @@ Used on initializing a timeline or thread." (propertize (concat "@" handle) 'face 'mastodon-handle-face 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle + 'mastodon-tab-stop 'user-handle 'account account - 'shr-url profile-url - 'keymap mastodon-tl--link-keymap + 'shr-url profile-url + 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" handle) - 'help-echo (concat "Browse user profile of @" handle)) + 'help-echo (concat "Browse user profile of @" handle)) ")"))) (defun mastodon-tl--format-faves-count (toot) @@ -520,34 +520,34 @@ By default it is `mastodon-tl--byline-boosted'" ;; this makes the behaviour of these markers consistent whether they are ;; displayed for an already boosted/favourited toot or as the result of ;; the toot having just been favourited/boosted. - (concat (when boosted - (mastodon-tl--format-faved-or-boosted-byline "B")) - (when faved - (mastodon-tl--format-faved-or-boosted-byline "F"))) - (propertize - (concat - ;; we propertize help-echo format faves for author name - ;; in `mastodon-tl--byline-author' - (funcall author-byline toot) - (cond ((equal visibility "direct") - (if (fontp (char-displayable-p #10r128274)) - " ✉" - " [direct]")) - ((equal visibility "private") - (if (fontp (char-displayable-p #10r9993)) - " 🔒" - " [followers]"))) - (funcall action-byline toot) - " " - ;; TODO: Once we have a view for toot (responses etc.) make - ;; this a tab stop and attach an action. - (propertize - (format-time-string mastodon-toot-timestamp-format parsed-time) - 'timestamp parsed-time - 'display (if mastodon-tl--enable-relative-timestamps - (mastodon-tl--relative-time-description parsed-time) - parsed-time)) - (propertize "\n ------------\n" 'face 'default)) + (concat (when boosted + (mastodon-tl--format-faved-or-boosted-byline "B")) + (when faved + (mastodon-tl--format-faved-or-boosted-byline "F"))) + (propertize + (concat + ;; we propertize help-echo format faves for author name + ;; in `mastodon-tl--byline-author' + (funcall author-byline toot) + (cond ((equal visibility "direct") + (if (fontp (char-displayable-p #10r128274)) + " ✉" + " [direct]")) + ((equal visibility "private") + (if (fontp (char-displayable-p #10r9993)) + " 🔒" + " [followers]"))) + (funcall action-byline toot) + " " + ;; TODO: Once we have a view for toot (responses etc.) make + ;; this a tab stop and attach an action. + (propertize + (format-time-string mastodon-toot-timestamp-format parsed-time) + 'timestamp parsed-time + 'display (if mastodon-tl--enable-relative-timestamps + (mastodon-tl--relative-time-description parsed-time) + parsed-time)) + (propertize "\n ------------\n" 'face 'default)) 'favourited-p faved 'boosted-p boosted 'byline t)))) @@ -947,11 +947,11 @@ a notification." (let ((attachments (mastodon-tl--property 'attachments)) vids) (mapc (lambda (x) - (let ((att-type (plist-get x :type))) - (when (or (string= "video" att-type) - (string= "gifv" att-type)) - (push x vids)))) - attachments) + (let ((att-type (plist-get x :type))) + (when (or (string= "video" att-type) + (string= "gifv" att-type)) + (push x vids)))) + attachments) (car vids))) (defun mastodon-tl--mpv-play-video-from-byline () @@ -975,7 +975,7 @@ in which case play first video or gif from current toot." (type (or ;; in byline: type ;; point in toot: - (mastodon-tl--property 'mastodon-media-type)))) + (mastodon-tl--property 'mastodon-media-type)))) (if url (if (or (equal type "gifv") (equal type "video")) @@ -1211,24 +1211,24 @@ JSON is what is returned by by the server." (propertize filter-string 'toot-id id ;for goto-next-filter compat 'phrase phrase - ;'help-echo "n/p to go to next/prev filter, c to create new filter, d to delete filter at point." - ;'keymap mastodon-tl--view-filters-keymap + ;;'help-echo "n/p to go to next/prev filter, c to create new filter, d to delete filter at point." + ;;'keymap mastodon-tl--view-filters-keymap 'byline t)))) ;for goto-next-filter compat (defun mastodon-tl--delete-filter () "Delete filter at point." (interactive) - (let* ((filter-id (get-text-property (point) 'toot-id)) - (phrase (get-text-property (point) 'phrase)) - (url (mastodon-http--api - (format "filters/%s" filter-id)))) - (if (equal nil filter-id) - (error "No filter at point?") - (when (y-or-n-p (format "Delete this filter? "))) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response (lambda () - (mastodon-tl--view-filters) - (message "Filter for \"%s\" deleted!" phrase))))))) + (let* ((filter-id (get-text-property (point) 'toot-id)) + (phrase (get-text-property (point) 'phrase)) + (url (mastodon-http--api + (format "filters/%s" filter-id)))) + (if (equal nil filter-id) + (error "No filter at point?") + (when (y-or-n-p (format "Delete this filter? "))) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response (lambda () + (mastodon-tl--view-filters) + (message "Filter for \"%s\" deleted!" phrase))))))) (defun mastodon-tl--get-follow-suggestions () "Display a buffer of suggested accounts to follow." -- cgit v1.2.3 From 121a09f5986dff508d713b772a54a4c8b4d446c4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 10:37:48 +0100 Subject: run goto-first-item in tl--init, unless profile view - remove call to goto-next-item from view filters and view foll suggests tweak init-sync goto-first-item behaviour remove call to goto-next-toot on profile load --- lisp/mastodon-profile.el | 1 - lisp/mastodon-tl.el | 31 +++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0119a36..7e78fd7 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -378,7 +378,6 @@ Returns a list of lists." (mastodon-profile--insert-statuses-pinned pinned) (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots (funcall update-function json))) - ;;(mastodon-tl--goto-next-toot) (goto-char (point-min)))) (defun mastodon-profile--get-toot-author () diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2c2c6ec..fef8a98 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1175,8 +1175,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-tl--init-sync "filters" "filters" 'mastodon-tl--insert-filters) - (use-local-map mastodon-tl--view-filters-keymap) - (mastodon-tl--goto-next-item)) + (use-local-map mastodon-tl--view-filters-keymap)) (defun mastodon-tl--insert-filters (json) "Insert the user's current filters. @@ -1236,8 +1235,7 @@ JSON is what is returned by by the server." (mastodon-tl--init-sync "follow-suggestions" "suggestions" 'mastodon-tl--insert-follow-suggestions) - (use-local-map mastodon-tl--follow-suggestions-map) - (mastodon-tl--goto-next-item)) + (use-local-map mastodon-tl--follow-suggestions-map)) (defun mastodon-tl--insert-follow-suggestions (response) "Insert follow suggestions into buffer. @@ -1624,11 +1622,14 @@ JSON is the data returned from the server." #'mastodon-tl--update-timestamps-callback (current-buffer) nil))) - (when (or (equal endpoint "notifications") - (string-prefix-p "timelines" endpoint) - (string-prefix-p "favourites" endpoint) - (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-first-item)))) + (unless + ;; for everything save profiles: + (string-prefix-p "accounts" endpoint)) + ;;(or (equal endpoint "notifications") + ;; (string-prefix-p "timelines" endpoint) + ;; (string-prefix-p "favourites" endpoint) + ;; (string-prefix-p "statuses" endpoint)) + (mastodon-tl--goto-first-item))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -1661,13 +1662,11 @@ Runs synchronously." #'mastodon-tl--update-timestamps-callback (current-buffer) nil))) - (when (and (not (equal json '[])) - (or (equal endpoint "notifications") - (string-prefix-p "timelines" endpoint) - (string-prefix-p "favourites" endpoint) - (string-prefix-p "statuses" endpoint)) - (mastodon-tl--goto-first-item)))) - buffer)) + (when ;(and (not (equal json '[])) + ;; for everything save profiles: + (not (string-prefix-p "accounts" endpoint)) + (mastodon-tl--goto-first-item))) + buffer)) (provide 'mastodon-tl) ;;; mastodon-tl.el ends here -- cgit v1.2.3 From 9384324d0848a06bea40d894350c0d224dd6388e Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 10:49:45 +0100 Subject: ert-helper: load mastodon.el before -profile so mastodon-mode-map is avail --- test/ert-helper.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ert-helper.el b/test/ert-helper.el index a6d6692..c2fd5a6 100644 --- a/test/ert-helper.el +++ b/test/ert-helper.el @@ -7,8 +7,8 @@ (load-file "lisp/mastodon-inspect.el") (load-file "lisp/mastodon-media.el") (load-file "lisp/mastodon-notifications.el") +(load-file "lisp/mastodon.el") (load-file "lisp/mastodon-profile.el") (load-file "lisp/mastodon-search.el") (load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-toot.el") -(load-file "lisp/mastodon.el") -- cgit v1.2.3 From 7ada5cb566568326627d9ec985b28142b1ddf220 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 11:52:58 +0100 Subject: make interactive-user-handles-get work for all profile views - profile statuses: leave as is - profile followers/following: we extract handle direct from toot-json without running mastodon-profile--extract-users-handles on the toot, as with user views there is no toot --- lisp/mastodon-tl.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fef8a98..c4b683d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1319,8 +1319,10 @@ Can be called to toggle NOTIFY on users already being followed." (string-prefix-p "*mastodon-search" (buffer-name))) (list (alist-get 'acct (mastodon-tl--property 'user-json)))) ;; profile view follows/followers compat: - ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (list (alist-get 'acct (mastodon-tl--property 'toot-json)))) + ;; but not for profile statuses: + ((when (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint)))) + (list (alist-get 'acct (mastodon-tl--property 'toot-json))))) (t (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))))) -- cgit v1.2.3 From d900cb6e73694be093f937e00f2c31486a130d16 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 12:06:02 +0100 Subject: readme update for foll reqs, foll suggests, filters readme follow req reject binding --- README.org | 88 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/README.org b/README.org index fff0b09..a7a8407 100644 --- a/README.org +++ b/README.org @@ -6,50 +6,50 @@ This is a fork of of the great but seemingly dormant https://github.com/jdenen/m It adds the following features: -| Profiles: | | -| | display profile metadata fields | -| | display pinned toots first | -| | display relationship (follows you/followed by you) | -| | display toots/follows/followers counts | -| | links/tags/mentions in profile bios are active links | -| | show a lock icon for locked accounts | -| =R=, =C-c a=, =C-c r= | view/accept/reject follow requests | -| =V= | view your favorited toots | -| =i= | toggle pinning of toots | -| =S-C-P= | jump to your profile | -| =U= | update your profile bio note | -| =O= | jump to own profile | -| Notifications: | | -| | follow requests now also appear in notifications | -| =a=, =r= | accept/reject follow request | -| | notifications for when a user posts (=mastodon-tl--enable-notify-user-posts=) | -| Timelines: | | -| =C= | copy url of toot at point | -| =d= | delete your toot at point, and reload current timeline | -| =D= | delete and redraft toot at point, preserving reply/CW/visibility | -| =W=, =M=, =B= | (un)follow, (un)mute, (un)block author of toot at point | -| =k=, =K= | toggle bookmark of toot at point, view bookmarked toots | -| =L= | view, create, and delete filters | -| | display polls and vote on them | -| | images are links to the full image, can be zoomed/rotated/saved (see image keymap) | -| | images scale properly | -| | toot visibility (direct, followers only) icon appears in toot bylines | -| | display toot's number of favorites, boosts and replies | -| | play gifs and videos (requires =mpv= to be installed) | -| | customize option to cache images | -| Toots: | | -| | mention booster in replies by default | -| | replies preserve visibility status/CW of original toot | -| | autocompletion of user mentions, via =company-mode= (must be installed to work) | -| =C-c C-a= | media uploads, asynchronous | -| | media upload previews displayed in toot compose buffer | -| =C-c C-n= | and sensitive media/nsfw flag | -| =C-c C-e= | add emoji (if =emojify= installed) | -| | download and use your instance's custom emoji | -| | server's maximum toot length shown in toot compose buffer | -| Search: | | -| =S= | search (posts, users, tags) (NB: only posts you have interacted with are searched) | -| | | +| Profiles: | | +| | display profile metadata fields | +| | display pinned toots first | +| | display relationship (follows you/followed by you) | +| | display toots/follows/followers counts | +| | links/tags/mentions in profile bios are active links | +| | show a lock icon for locked accounts | +| =G= | view follow suggestions | +| =R=, =a=, =r= | view/accept/reject follow requests | +| =V= | view your favorited toots | +| =i= | toggle pinning of toots | +| =U= | update your profile bio note | +| =O= | jump to own profile | +| Notifications: | | +| | follow requests now also appear in notifications | +| =a=, =j= | accept/reject follow request | +| | notifications for when a user posts (=mastodon-tl--enable-notify-user-posts=) | +| Timelines: | | +| =C= | copy url of toot at point | +| =d= | delete your toot at point, and reload current timeline | +| =D= | delete and redraft toot at point, preserving reply/CW/visibility | +| =W=, =M=, =B= | (un)follow, (un)mute, (un)block author of toot at point | +| =k=, =K= | toggle bookmark of toot at point, view bookmarked toots | +| =I=, =c=, =d= | view, create, and delete filters | +| | display polls and vote on them | +| | images are links to the full image, can be zoomed/rotated/saved (see image keymap) | +| | images scale properly | +| | toot visibility (direct, followers only) icon appears in toot bylines | +| | display toot's number of favorites, boosts and replies | +| | play gifs and videos (requires =mpv= to be installed) | +| | customize option to cache images | +| Toots: | | +| | mention booster in replies by default | +| | replies preserve visibility status/CW of original toot | +| | autocompletion of user mentions, via =company-mode= (must be installed to work) | +| =C-c C-a= | media uploads, asynchronous | +| | media upload previews displayed in toot compose buffer | +| =C-c C-n= | and sensitive media/nsfw flag | +| =C-c C-e= | add emoji (if =emojify= installed) | +| | download and use your instance's custom emoji | +| | server's maximum toot length shown in toot compose buffer | +| Search: | | +| =S= | search (posts, users, tags) (NB: only posts you have interacted with are searched) | +| | | It also makes some small cosmetic changes to make timelines easier to read, and makes some functions asynchronous, based on https://github.com/ieure/mastodon.el. -- cgit v1.2.3 From fce69f724310896f7bbb071e74c7a9c1663153de Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 20:30:13 +0100 Subject: no faves counts for following/followers in profile view --- lisp/mastodon-tl.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c4b683d..272ca15 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -357,7 +357,12 @@ Used on initializing a timeline or thread." ;; echo faves count when point on post author name: ;; which is where --goto-next-toot puts point. 'help-echo - (mastodon-tl--format-faves-count toot)) + ;; but don't add it to "following"/"follows" on profile views: + ;; we don't have a tl--buffer-spec yet: + (unless (or (string-suffix-p "-followers*" (buffer-name)) + (string-suffix-p "-following*" (buffer-name))) + ;; (mastodon-tl--get-endpoint))) + (mastodon-tl--format-faves-count toot))) " (" (propertize (concat "@" handle) 'face 'mastodon-handle-face -- cgit v1.2.3 From f71bf45d0aee94f360c10c6f121711386c55a457 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 16 Feb 2022 20:59:05 +0100 Subject: improve check for any existing masto buffers on mastodon load --- lisp/mastodon.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 51e27ec..6eddd3d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -204,12 +204,17 @@ Use. e.g. \"%c\" for your locale's date and time format." (let* ((tls (list "home" "local" "federated" - (concat (mastodon-auth--user-acct) "-statuses") ; profile + (concat (mastodon-auth--user-acct) "-statuses") ; own profile "favourites" "search")) - (buffer (cl-some (lambda (el) - (get-buffer (concat "*mastodon-" el "*"))) - tls))) ; return first buff that exists + (buffer (or (cl-some (lambda (el) + (get-buffer (concat "*mastodon-" el "*"))) + tls) ; return first buff that exists + (cl-some (lambda (x) + (when + (string-prefix-p "*mastodon-" (buffer-name x)) + (get-buffer x))) + (buffer-list))))) ; catch any other masto buffer (if buffer (switch-to-buffer buffer) (mastodon-tl--get-home-timeline) -- cgit v1.2.3 From 0efc846bed8443c1ed38bdb15f3afc4f052b7615 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 14:59:07 +0100 Subject: tl--init: aslo set tl-buffer-spec before update-function --- lisp/mastodon-tl.el | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 272ca15..f23fe67 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -192,7 +192,7 @@ types of mastodon links and not just shr.el-generated ones.") (keymap-canonicalize map)) "Keymap for viewing follow suggestions.") - (defvar mastodon-tl--byline-link-keymap +(defvar mastodon-tl--byline-link-keymap (when (require 'mpv nil :no-error) (let ((map (make-sparse-keymap))) (define-key map (kbd "") 'mastodon-tl--mpv-play-video-from-byline) @@ -1326,8 +1326,8 @@ Can be called to toggle NOTIFY on users already being followed." ;; profile view follows/followers compat: ;; but not for profile statuses: ((when (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint)))) - (list (alist-get 'acct (mastodon-tl--property 'toot-json))))) + (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint)))) + (list (alist-get 'acct (mastodon-tl--property 'toot-json))))) (t (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))))) @@ -1608,6 +1608,14 @@ UPDATE-FUNCTION is used to recieve more toots. JSON is the data returned from the server." (with-output-to-temp-buffer buffer (switch-to-buffer buffer) + ;; mastodon-mode wipes buffer-spec, so order must unforch be: + ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. + ;; which means we cannot use buffer-spec for update-function + ;; unless we set it both before and after the others + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,endpoint + update-function ,update-function)) (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed @@ -1648,6 +1656,14 @@ Runs synchronously." (json (mastodon-http--get-json url))) (with-output-to-temp-buffer buffer (switch-to-buffer buffer) + ;; mastodon-mode wipes buffer-spec, so order must unforch be: + ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. + ;; which means we cannot use buffer-spec for update-function + ;; unless we set it both before and after the others + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,endpoint + update-function ,update-function)) (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed @@ -1670,7 +1686,7 @@ Runs synchronously." (current-buffer) nil))) (when ;(and (not (equal json '[])) - ;; for everything save profiles: + ;; for everything save profiles: (not (string-prefix-p "accounts" endpoint)) (mastodon-tl--goto-first-item))) buffer)) -- cgit v1.2.3 From 678b572132df07265f4d745e579d23162a67cca0 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 15:20:05 +0100 Subject: handle empty display_name in search--get-user-info ensures we hever have an empty author name slot --- lisp/mastodon-search.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index e1ca81a..10500ad 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -156,7 +156,9 @@ This is also called by `mastodon-tl--get-follow-suggestions'." (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." - (list (alist-get 'display_name account) + (list (if (not (equal "" (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account)) (alist-get 'acct account) (alist-get 'url account) (alist-get 'note account))) -- cgit v1.2.3 From d9a31963c0b055f5ecf57f39b21575aa4bce3545 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 15:22:51 +0100 Subject: use search-insert-users-propertized for foll reqs not prifile--add-author-bylines autoload insert-users-propr in -profile --- lisp/mastodon-profile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7e78fd7..7a68e26 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -64,6 +64,7 @@ (autoload 'mastodon-tl--goto-prev-item "mastodon-tl") (autoload 'mastodon-tl--goto-first-item "mastodon-tl") (autoload 'mastodon-toot "mastodon") +(autoload 'mastodon-search--insert-users-propertized "mastodon-search") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -191,7 +192,8 @@ JSON is the data returned by the server." 'face font-lock-comment-face 'byline t 'toot-id "0")) - (mastodon-profile--add-author-bylines json))) + (mastodon-search--insert-users-propertized json :note))) + ;; (mastodon-profile--add-author-bylines json))) (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." -- cgit v1.2.3 From 8526e6c1cd25e9d060c15f1e11aa83450e5f0f01 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 16:02:21 +0100 Subject: search: use toot-json propertize not user-json, for compat --- lisp/mastodon-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 10500ad..2ebdd10 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -151,7 +151,7 @@ This is also called by `mastodon-tl--get-follow-suggestions'." (mastodon-tl--render-text (cadddr user) nil) "") "\n") - 'user-json acct)))) + 'toot-json acct)))) ; so named for compat w other processing functions json)) (defun mastodon-search--get-user-info (account) -- cgit v1.2.3 From 868a5680953d35f66cb64f92e940f55d579c74b2 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 16:02:46 +0100 Subject: handle empty display_name in mastodon-tl--do-user-action-and-response --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f23fe67..2fa3526 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1371,7 +1371,9 @@ NOTIFY is only non-nil when called by `mastodon-tl--follow-user'." (mastodon-profile--lookup-account-in-status user-handle (mastodon-profile--toot-json)))) (user-id (mastodon-profile--account-field account 'id)) - (name (mastodon-profile--account-field account 'display_name)) + (name (if (not (equal "" (mastodon-profile--account-field account 'display_name))) + (mastodon-profile--account-field account 'display_name) + (mastodon-profile--account-field account 'username))) (url (mastodon-http--api (if notify (format "accounts/%s/%s?notify=%s" user-id action notify) -- cgit v1.2.3 From 58e23171ef8883b08cbf6d33d9c41deaf66f87ff Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 16:03:26 +0100 Subject: FIX buffers that use alt acct fetch in interactive-user-handles-get --- lisp/mastodon-tl.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2fa3526..7ba78e4 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1319,15 +1319,15 @@ Can be called to toggle NOTIFY on users already being followed." (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." (let ((user-handles - ;; follow suggests / search compat: (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") - (string-prefix-p "*mastodon-search" (buffer-name))) - (list (alist-get 'acct (mastodon-tl--property 'user-json)))) - ;; profile view follows/followers compat: - ;; but not for profile statuses: - ((when (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint)))) - (list (alist-get 'acct (mastodon-tl--property 'toot-json))))) + ;; follow suggests / search / foll requests compat: + (string-prefix-p "*mastodon-search" (buffer-name)) + (equal (buffer-name) "*mastodon-follow-requests*") + ;; profile view follows/followers compat: + ;; but not for profile statuses: + (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint))))) + (list (alist-get 'acct (mastodon-tl--property 'toot-json)))) (t (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))))) -- cgit v1.2.3 From ab24ffe0ecdf9c9958c2ec527a23d0043babbf2c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 16:09:43 +0100 Subject: profile--add-author-bylines docstring --- lisp/mastodon-profile.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7a68e26..57fa080 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -429,8 +429,7 @@ FIELD is used to identify regions under 'account" (defun mastodon-profile--add-author-bylines (tootv) "Convert TOOTV into a author-bylines and insert. Also insert their profile note. -Used to view a user's followers and those they're following, as -well as the list of suggested followers and for search results." +Used to view a user's followers and those they're following." ;;FIXME change the name of this fun now that we've edited what it does! (let ((inhibit-read-only t)) (when (not (equal tootv '[])) -- cgit v1.2.3 From 25282eb0daa8edfeb777a2fe6c6e0538fdba08a5 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 16:28:18 +0100 Subject: docstring insert-users-prop --- lisp/mastodon-search.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 2ebdd10..cbb1fba 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -127,9 +127,10 @@ Returns a nested list containing user handle, display name, and URL." (defun mastodon-search--insert-users-propertized (json &optional note) "Insert users list into the buffer. -JSON is the data from the server.. -If NOTE is non-nil, include user's profile note. -This is also called by `mastodon-tl--get-follow-suggestions'." +JSON is the data from the server.. If NOTE is non-nil, include +user's profile note. This is also called by +`mastodon-tl--get-follow-suggestions' and +`mastodon-profile--insert-follow-requests'." (mapc (lambda (acct) (let ((user (mastodon-search--get-user-info acct))) (insert -- cgit v1.2.3 From 4f582388e0594753d15f0d386cbb1ab2eaad5a02 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 17:15:59 +0100 Subject: test for toot-json before following/muting/blocking etc this is more needed now that we have some other buffers like follow suggestions and follow requests, which want to be able to use these functions. previously, if any of them were called in these buffers when not on the correct item, the buffer would reload and duplicate. ultimately this was probably due to tl--property calls failing, which causes goto-next-toot to be called, which when it also fails calls tl--more. --- lisp/mastodon-tl.el | 70 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7ba78e4..7a346c1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1258,17 +1258,21 @@ RESPONSE is the JSON returned by the server." If NOTIFY is \"true\", enable notifications when that user posts. If NOTIFY is \"false\", disable notifications when that user posts. Can be called to toggle NOTIFY on users already being followed." - (interactive - (list - (mastodon-tl--interactive-user-handles-get "follow"))) - (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify)) + (interactive + (list + (mastodon-tl--interactive-user-handles-get "follow"))) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify))) (defun mastodon-tl--enable-notify-user-posts (user-handle) "Query for USER-HANDLE and enable notifications when they post." (interactive (list (mastodon-tl--interactive-user-handles-get "enable"))) - (mastodon-tl--follow-user user-handle "true")) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (mastodon-tl--follow-user user-handle "true"))) (defun mastodon-tl--disable-notify-user-posts (user-handle) "Query for USER-HANDLE and disable notifications when they post." @@ -1282,14 +1286,18 @@ Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "unfollow"))) - (mastodon-tl--do-user-action-and-response user-handle "unfollow" t)) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (mastodon-tl--do-user-action-and-response user-handle "unfollow" t))) (defun mastodon-tl--block-user (user-handle) "Query for USER-HANDLE from current status and block that user." (interactive (list (mastodon-tl--interactive-user-handles-get "block"))) - (mastodon-tl--do-user-action-and-response user-handle "block")) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (mastodon-tl--do-user-action-and-response user-handle "block"))) (defun mastodon-tl--unblock-user (user-handle) "Query for USER-HANDLE from list of blocked users and unblock that user." @@ -1305,7 +1313,9 @@ Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "mute"))) - (mastodon-tl--do-user-action-and-response user-handle "mute")) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (mastodon-tl--do-user-action-and-response user-handle "mute"))) (defun mastodon-tl--unmute-user (user-handle) "Query for USER-HANDLE from list of muted users and unmute that user." @@ -1318,26 +1328,30 @@ Can be called to toggle NOTIFY on users already being followed." (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." - (let ((user-handles - (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") - ;; follow suggests / search / foll requests compat: - (string-prefix-p "*mastodon-search" (buffer-name)) - (equal (buffer-name) "*mastodon-follow-requests*") - ;; profile view follows/followers compat: - ;; but not for profile statuses: - (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint))))) - (list (alist-get 'acct (mastodon-tl--property 'toot-json)))) - (t - (mastodon-profile--extract-users-handles - (mastodon-profile--toot-json)))))) - (completing-read (if (or (equal action "disable") - (equal action "enable")) - (format "%s notifications when user posts: " action) - (format "Handle of user to %s: " action)) - user-handles - nil ; predicate - 'confirm))) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (let ((user-handles + (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") + ;; follow suggests / search / foll requests compat: + (string-prefix-p "*mastodon-search" (buffer-name)) + (equal (buffer-name) "*mastodon-follow-requests*") + ;; profile view follows/followers compat: + ;; but not for profile statuses: + (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint))))) + ;; avoid tl--property here because it calls next-toot + ;; which breaks non-toot buffers like foll reqs etc.: + (list (alist-get 'acct (get-text-property (point) 'toot-json)))) + (t + (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))))) + (completing-read (if (or (equal action "disable") + (equal action "enable")) + (format "%s notifications when user posts: " action) + (format "Handle of user to %s: " action)) + user-handles + nil ; predicate + 'confirm)))) (defun mastodon-tl--interactive-blocks-or-mutes-list-get (action) "Fetch the list of accounts for ACTION from the server. -- cgit v1.2.3 From 34440b68ff6d3430428372d2968adc55ea9c6f03 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Feb 2022 17:26:18 +0100 Subject: test and message for foll reqs process just feedback for when we call it when not on anything --- lisp/mastodon-notifications.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 40f9c04..df4f9c0 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -86,7 +86,8 @@ With no argument, the request is accepted. Argument REJECT means reject the request. Can be called in notifications view or in follow-requests view." (interactive) - (when (mastodon-tl--find-property-range 'toot-json (point)) + (if (not (mastodon-tl--find-property-range 'toot-json (point))) + (message "No follow request at point?") (let* ((toot-json (mastodon-tl--property 'toot-json)) (f-reqs-view-p (string= "follow_requests" (plist-get mastodon-tl--buffer-spec 'endpoint))) -- cgit v1.2.3 From 13e1ebff3b73ba3e6ad522d91103f432ce96ff92 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 19 Feb 2022 13:43:24 +0100 Subject: add checks to profile--show-user for when its called on nothing - also make profile--extract-ysers-handles work on user listings as well as toots --- lisp/mastodon-profile.el | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 57fa080..9c1cd88 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -400,19 +400,23 @@ If toot is a boost, opens the profile of the booster." "Query for USER-HANDLE from current status and show that user's profile." (interactive (list - (let ((user-handles (mastodon-profile--extract-users-handles - (mastodon-profile--toot-json)))) - (completing-read "View profile of user [choose or enter any handle]: " - user-handles - nil ; predicate - 'confirm)))) - (let ((account (mastodon-profile--lookup-account-in-status - user-handle (mastodon-profile--toot-json)))) - (if account - (progn - (message "Loading profile of user %s..." user-handle) - (mastodon-profile--make-author-buffer account)) - (message "Cannot find a user with handle %S" user-handle)))) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "View profile of user [choose or enter any handle]: " + user-handles + nil ; predicate + 'confirm))))) + (if (not (get-text-property (point) 'toot-json)) + (message "Looks like there's no toot or user at point?") + (let ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json)))) + (if account + (progn + (message "Loading profile of user %s..." user-handle) + (mastodon-profile--make-author-buffer account)) + (message "Cannot find a user with handle %S" user-handle))))) (defun mastodon-profile--my-profile () "Show the profile of the currently signed in user." @@ -474,9 +478,11 @@ If the handle does not match a search return then retun NIL." These include the author, author of reblogged entries and any user mentioned." (when status - (let ((this-account (alist-get 'account status)) - (mentions (alist-get 'mentions status)) - (reblog (alist-get 'reblog status))) + (let ((this-account + (or (alist-get 'account status) ; status is a toot + status)) ; status is a user listing + (mentions (alist-get 'mentions status)) + (reblog (alist-get 'reblog status))) (seq-filter 'stringp (seq-uniq -- cgit v1.2.3 From a5fffb209d7bb2644741fd917768786628ec94b3 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 19 Feb 2022 13:44:19 +0100 Subject: add toot-json property to profile followers/following note in profile--add-author-bylines, which now prints profile notes --- lisp/mastodon-profile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 9c1cd88..cb449b6 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -448,7 +448,9 @@ Used to view a user's followers and those they're following." 'toot-json toot)) (mastodon-media--inline-images start-pos (point)) (insert "\n" - (mastodon-tl--render-text (alist-get 'note toot) nil) + (propertize + (mastodon-tl--render-text (alist-get 'note toot) nil) + 'toot-json toot) ' "\n"))) tootv)))) -- cgit v1.2.3 From 0af5b491d14d521c03ebc48d82608afd65166e90 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Wed, 23 Feb 2022 14:24:37 +0530 Subject: change '-' to '--' in between function and namespace names mastodon.el currently follows the convention where all function names should have two dashes (not one dash) in between function and namespace names. Update all function names to follow this convention. See issue #205 and pull request #255 --- lisp/mastodon-auth.el | 20 ++++++++++---------- lisp/mastodon-client.el | 16 ++++++++-------- lisp/mastodon-http.el | 2 +- test/mastodon-auth-tests.el | 4 ++-- test/mastodon-client-tests.el | 16 ++++++++-------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index c09dfdf..2540598 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -40,11 +40,11 @@ (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") -(autoload 'mastodon-http-append-query-string "mastodon-http") -(autoload 'mastodon-client-store-access-token "mastodon-client") -(autoload 'mastodon-client-active-user "mastodon-client") -(autoload 'mastodon-client-make-user-active "mastodon-client") -(autoload 'mastodon-client-form-user-from-vars "mastodon-client") +(autoload 'mastodon-http--append-query-string "mastodon-http") +(autoload 'mastodon-client--store-access-token "mastodon-client") +(autoload 'mastodon-client--active-user "mastodon-client") +(autoload 'mastodon-client--make-user-active "mastodon-client") +(autoload 'mastodon-client--form-user-from-vars "mastodon-client") (defvar mastodon-instance-url) (defvar mastodon-client-scopes) (defvar mastodon-client-redirect-uri) @@ -71,7 +71,7 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (defun mastodon-auth--get-browser-login-url () "Return properly formed browser login url." - (mastodon-http-append-query-string + (mastodon-http--append-query-string (concat mastodon-instance-url "/oauth/authorize/") `(("response_type" "code") ("redirect_uri" ,mastodon-client-redirect-uri) @@ -127,11 +127,11 @@ Generate/save token if none known yet." ;; initialised already. (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil 'equal)) - ((plist-get (mastodon-client-active-user) :access_token) + ((plist-get (mastodon-client--active-user) :access_token) ;; user variables needs to initialised by reading from ;; plstore. (push (cons mastodon-instance-url - (plist-get (mastodon-client-active-user) :access_token)) + (plist-get (mastodon-client--active-user) :access_token)) mastodon-auth--token-alist) (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil 'equal)) @@ -149,8 +149,8 @@ Handle any errors from the server." (pcase response ((and (let token (plist-get response :access_token)) (guard token)) - (mastodon-client-make-user-active - (mastodon-client-store-access-token token)) + (mastodon-client--make-user-active + (mastodon-client--store-access-token token)) (cdar (push (cons mastodon-instance-url token) mastodon-auth--token-alist))) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index c577fec..80338b1 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -124,12 +124,12 @@ Return plist without the KEY." (defun mastodon-client--make-user-details-plist () "Make a plist with current user details. Return it." - `(:username ,(mastodon-client-form-user-from-vars) + `(:username ,(mastodon-client--form-user-from-vars) :instance ,mastodon-instance-url :client_id ,(plist-get (mastodon-client) :client_id) :client_secret ,(plist-get (mastodon-client) :client_secret))) -(defun mastodon-client-store-access-token (token) +(defun mastodon-client--store-access-token (token) "Save TOKEN as :access_token in plstore of the current user. Return the plist after the operation." (let* ((user-details (mastodon-client--make-user-details-plist)) @@ -144,7 +144,7 @@ Return the plist after the operation." (plstore-close plstore) plstore-value)) -(defun mastodon-client-make-user-active (user-details) +(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) @@ -153,7 +153,7 @@ Return the plist after the operation." (plstore-save plstore) (plstore-close plstore))) -(defun mastodon-client-form-user-from-vars () +(defun mastodon-client--form-user-from-vars () "Create a username from user variable. Return that username. Username in the form user@instance.com is formed from the @@ -165,23 +165,23 @@ variables `mastodon-instance-url' and `mastodon-active-user'." (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)) + (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)) + (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)) + (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-active-user () +(defun mastodon-client--active-user () "Return the details of the currently active user. Details is a plist." diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 8e96b39..05c9d2e 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -157,7 +157,7 @@ Pass response buffer to CALLBACK function." (with-temp-buffer (mastodon-http--url-retrieve-synchronously url)))) -(defun mastodon-http-append-query-string (url params) +(defun mastodon-http--append-query-string (url params) "Append PARAMS to URL as query strings and return it. PARAMS should be an alist as required `url-build-query-string'." diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 3ff745f..3bf65b2 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -56,8 +56,8 @@ (mastodon-auth--token-alist nil)) (with-mock (mock (mastodon-auth--get-token) => '(:access_token "foobaz")) - (mock (mastodon-client-store-access-token "foobaz")) - (stub mastodon-client-make-user-active) + (mock (mastodon-client--store-access-token "foobaz")) + (stub mastodon-client--make-user-active) (should (string= (mastodon-auth--access-token) "foobaz")) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index c2ec50c..b302ed6 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -122,11 +122,11 @@ (should (equal mastodon-client--client-details-alist '(("http://mastodon.example" :client_id "foo" :client_secret "baz"))))))) -(ert-deftest mastodon-client-form-user-from-vars () +(ert-deftest mastodon-client--form-user-from-vars () (let ((mastodon-active-user "test9000") (mastodon-instance-url "https://mastodon.example")) (should - (equal (mastodon-client-form-user-from-vars) + (equal (mastodon-client--form-user-from-vars) "test9000@mastodon.example")))) (ert-deftest mastodon-client--current-user-active-p () @@ -142,7 +142,7 @@ (mock (mastodon-client--general-read "active-user") => '(:username "user@other.example" :client_id "id1")) (should (null (mastodon-client--current-user-active-p)))))) -(ert-deftest mastodon-client-store-access-token () +(ert-deftest mastodon-client--store-access-token () (let ((mastodon-instance-url "https://mastodon.example") (mastodon-active-user "test8000") (user-details @@ -150,14 +150,14 @@ :instance "https://mastodon.example" :client_id "id" :client_secret "secret" :access_token "token"))) - ;; test if mastodon-client-store-access-token /returns/ right + ;; test if mastodon-client--store-access-token /returns/ right ;; value (with-mock (mock (mastodon-client) => '(:client_id "id" :client_secret "secret")) (mock (mastodon-client--token-file) => "stubfile.plstore") - (should (equal (mastodon-client-store-access-token "token") + (should (equal (mastodon-client--store-access-token "token") user-details))) - ;; test if mastodon-client-store-access-token /stores/ right value + ;; test if mastodon-client--store-access-token /stores/ right value (with-mock (mock (mastodon-client--token-file) => "stubfile.plstore") (should (equal (mastodon-client--general-read @@ -165,10 +165,10 @@ user-details))) (delete-file "stubfile.plstore"))) -(ert-deftest mastodon-client-make-user-active () +(ert-deftest mastodon-client--make-user-active () (let ((user-details '(:username "test@mastodon.example"))) (with-mock (mock (mastodon-client--token-file) => "stubfile.plstore") - (mastodon-client-make-user-active user-details) + (mastodon-client--make-user-active user-details) (should (equal (mastodon-client--general-read "active-user") user-details))))) -- cgit v1.2.3 From 7ec5aea30e8ada9475e1199a084d468f0031002d Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 18:59:56 +0530 Subject: auth: change name to mastodon-auth--request-authorization-code Change the name of the function `mastodon-auth--ask-authorization-code' to `mastodon-auth--request-authorization-code'. Suggested-by: Marty Hiatt --- lisp/mastodon-auth.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 2540598..416e714 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -86,7 +86,7 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." "Paste Authorization Code here: ") (mastodon-client-form-user-from-vars))) -(defun mastodon-auth--ask-authorization-code () +(defun mastodon-auth--request-authorization-code () "Ask authorization code and return it." (let ((url (mastodon-auth--get-browser-login-url)) authorization-code) @@ -96,7 +96,7 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (defun mastodon-auth--generate-token () "Generate access_token for the user. Return response buffer." - (let ((authorization-code (mastodon-auth--ask-authorization-code))) + (let ((authorization-code (mastodon-auth--request-authorization-code))) (mastodon-http--post (concat mastodon-instance-url "/oauth/token") `(("grant_type" . "authorization_code") -- cgit v1.2.3 From 7a0d85b3f7c170ae930ea7ff5be948a6183ca513 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 19:16:07 +0530 Subject: auth: present auth code request in a nicer way Instead of using the minibuffer prompt to present the explanation what the user needs to do to get authorization code, use Emacs buffer and Window. The minibuffer prompt should have 2-3 words. This increases the readability of the explanation. Of course delete explanation buffer and restore the window configuration as it was after reading from minibuffer. --- lisp/mastodon-auth.el | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 416e714..ebbe86c 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -85,13 +85,44 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." "Login to your account (%s) and authorize \"mastodon.el\".\n" "Paste Authorization Code here: ") (mastodon-client-form-user-from-vars))) +(defun mastodon-auth--show-notice (notice buffer-name &optional ask) + "Display NOTICE to user. +NOTICE is displayed in vertical split occupying 50% of total +width. The buffer name of the buffer being displayed in the +window is BUFFER-NAME. + +When optional argument ASK is given which should be a string, use +ASK as the minibuffer prompt. Return whatever user types in +response to the prompt. + +When ASK is absent return nil." + (let ((buffer (get-buffer-create buffer-name)) + (inhibit-read-only t) + ask-value window) + (set-buffer buffer) + (erase-buffer) + (insert notice) + (fill-region (point-min) (point-max)) + (read-only-mode) + (setq window (select-window + (split-window (frame-root-window) nil 'left) + t)) + (switch-to-buffer buffer t) + (when ask + (setq ask-value (read-string ask)) + (kill-buffer buffer) + (delete-window window)) + ask-value)) (defun mastodon-auth--request-authorization-code () "Ask authorization code and return it." (let ((url (mastodon-auth--get-browser-login-url)) authorization-code) (kill-new url) - (setq authorization-code (read-string mastodon-auth--explanation)) + (setq authorization-code + (mastodon-auth--show-notice mastodon-auth--explanation + "*mastodon-notice*" + "Authorization Code: ")) authorization-code)) (defun mastodon-auth--generate-token () -- cgit v1.2.3 From 1e4ab751683d497243f719c70cccb0450c9cb451 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 19:36:43 +0530 Subject: auth: make the wording in mastodon-auth--explanation clearer --- lisp/mastodon-auth.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index ebbe86c..491d6ae 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -80,11 +80,17 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (defvar mastodon-auth--explanation (format - (concat "A URL has been copied to your clipboard.\n" - "Open this URL in a javascript capable browser.\n" - "Login to your account (%s) and authorize \"mastodon.el\".\n" - "Paste Authorization Code here: ") - (mastodon-client-form-user-from-vars))) + " +1. A URL has been copied to your clipboard. Open this URL in a +javascript capable browser and your browser will take you to your +Mastodon instance's login page. + +2. Login to your account (%s) and authorize \"mastodon.el\". + +3. After authorization you will be presented an authorization +code. Copy this code and paste it in the minibuffer prompt." + (mastodon-client--form-user-from-vars))) + (defun mastodon-auth--show-notice (notice buffer-name &optional ask) "Display NOTICE to user. NOTICE is displayed in vertical split occupying 50% of total -- cgit v1.2.3 From 6ac09ec8bc5f3011e59602b030d45ce3f3860e25 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 19:43:08 +0530 Subject: auth: make old mastodon.el users aware Most old users of the mastodon.el wouldn't know about the introduction of new variable `mastodon-active-user'[1]. Our goal is to make them aware. Set the default value of [1] to nil. This way we can know that the user hasn't set [1] properly because user is unaware of it. In the definition of `mastodon-auth--access-token', check [1]'s value and if it's null, explain to the user about the new situation. Finally signal the error "Variables not set properly". We have considered the possibility of automating the process but since the new login mechanism depends on setting [1] *in the init file*, the only way to automate it would be to write to user's init file which we consider to be very rude and shouldn't be done by this package. --- lisp/mastodon-auth.el | 8 ++++++++ lisp/mastodon.el | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 491d6ae..bad9e08 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -48,6 +48,7 @@ (defvar mastodon-instance-url) (defvar mastodon-client-scopes) (defvar mastodon-client-redirect-uri) +(defvar mastodon-active-user) (defgroup mastodon-auth nil "Authenticate with Mastodon." @@ -172,6 +173,13 @@ Generate/save token if none known yet." mastodon-auth--token-alist) (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil 'equal)) + ((null mastodon-active-user) + ;; user not aware of 2FA related changes and has not set the + ;; `mastodon-active-user' properly. Make user aware and error + ;; out. + (mastodon-auth--show-notice mastodon-auth--user-unaware + "*mastodon-notice*") + (error "Variables not set properly")) (t ;; user access-token needs to fetched from the server and ;; stored and variables initialised. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index d22c842..6daa755 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -110,7 +110,7 @@ changes to take effect." :group 'mastodon :type 'string) -(defcustom mastodon-active-user "user" +(defcustom mastodon-active-user nil "Username of the active user. For example, if your mastodon username is -- cgit v1.2.3 From fbb34e106b7164a9c1d47cf31d9803827540e228 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 20:15:48 +0530 Subject: auth: define variable mastodon-auth--user-unaware Hold the explanation string in the variable `mastodon-auth--user-unaware'. This explanation is provided to old mastodon.el users who are not aware of the 2FA related changes. --- lisp/mastodon-auth.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index bad9e08..ba7bebe 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -70,6 +70,21 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." (defvar mastodon-auth--acct-alist nil "Alist of account accts (name@domain) keyed by instance url.") +(defvar mastodon-auth--user-unaware + " ** MASTODON.EL - NOTICE ** + +It appears that you are not aware of the recent developments in +mastodon.el. In short we now require that you also set the +variable `mastodon-active-user' in your init file in addition to +`mastodon-instance-url'. + +Please see its documentation to understand what value it accepts +by running M-x describe-variable on it or visiting our web page: +https://codeberg.org/martianh/mastodon.el + +We apologize for the inconvenience. +") + (defun mastodon-auth--get-browser-login-url () "Return properly formed browser login url." (mastodon-http--append-query-string -- cgit v1.2.3 From 92f898f0a90760078a1bbfc843568e858891b6c9 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 20:42:48 +0530 Subject: test: add `mastodon-auth--user-unaware' Test for the situation when old mastodon.el users are unaware of the variable `mastodon-active-user'. --- test/mastodon-auth-tests.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 3bf65b2..3ecac30 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -64,3 +64,11 @@ (should (equal mastodon-auth--token-alist '(("https://instance.url" . "foobaz"))))))) + +(ert-deftest mastodon-auth--user-unaware () + (let ((mastodon-instance-url "https://instance.url") + (mastodon-active-user nil) + (mastodon-auth--token-alist nil)) + (with-mock + (mock (mastodon-client--active-user)) + (should-error (mastodon-auth--access-token))))) -- cgit v1.2.3 From 523ccea77d0968016973aefe55a92d9ebfd0b451 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 20:46:33 +0530 Subject: test: fix `mastodon-auth--access-token-not-found' --- test/mastodon-auth-tests.el | 1 + 1 file changed, 1 insertion(+) diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 3ecac30..2d9d6df 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -53,6 +53,7 @@ (ert-deftest mastodon-auth--access-token-not-found () "Should set and return `mastodon-auth--token' if nil." (let ((mastodon-instance-url "https://instance.url") + (mastodon-active-user "user") (mastodon-auth--token-alist nil)) (with-mock (mock (mastodon-auth--get-token) => '(:access_token "foobaz")) -- cgit v1.2.3 From 56fa25df379623e79261b535cd724db3ed979d44 Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Fri, 25 Feb 2022 21:11:30 +0530 Subject: auth: make mastodon-auth-source-file a defvar The variable `mastodon-auth-source-file' serves no purpose so change it from a defcustom to a defvar. Also update its docstring to document it. --- lisp/mastodon-auth.el | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index ba7bebe..f50f5ed 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -55,14 +55,10 @@ :prefix "mastodon-auth-" :group 'mastodon) -(defcustom mastodon-auth-source-file "" - "Filename to use to store user names and passwords. - -Leave empty to not permanently store any secrets. -Otherwise set to e.g. \"~/.authinfo.gpg\" to have encrypted storage, or -if you are happy with unencryped storage use e.g. \"~/authinfo\"." - :group 'mastodon-auth - :type 'string) +(defvar mastodon-auth-source-file nil + "This variable is obsolete. +This variable currently serves no purpose and will be removed in +the future.") (defvar mastodon-auth--token-alist nil "Alist of User access tokens keyed by instance url.") -- cgit v1.2.3 From d90c104299636f2525f8b77001b4374e5b0df72a Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 28 Feb 2022 15:21:40 +0100 Subject: add copy-toot-text function --- lisp/mastodon-toot.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 48e7d96..1d80e55 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -271,6 +271,13 @@ Makes a POST request to the server." (kill-new url) (message "Toot URL copied to the clipboard."))) +(defun mastodon-toot--copy-toot-text () + "Copy text of toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json))) + (kill-new (mastodon-tl--content toot)) + (message "Toot content copied to the clipboard."))) + (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." (and (not (alist-get 'reblog toot)) -- cgit v1.2.3 From a14ecfce170e82ae610247b8ed1854077deed8c0 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 10 Mar 2022 13:09:47 +0100 Subject: display image caption in help echo --- lisp/mastodon-media.el | 10 +++++++--- lisp/mastodon-tl.el | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 9441bdb..f79b1fa 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -307,12 +307,16 @@ Replace them with the referenced image." t image-options)) " "))) -(defun mastodon-media--get-media-link-rendering (media-url &optional full-remote-url type) +(defun mastodon-media--get-media-link-rendering (media-url &optional full-remote-url type caption) "Return the string to be written that renders the image at MEDIA-URL. FULL-REMOTE-URL is used for `shr-browse-image'. TYPE is the attachment's type field on the server." - (let ((help-echo - "RET/i: load full image (prefix: copy URL), +/-: zoom, r: rotate, o: save preview")) + (let* ((help-echo-base "RET/i: load full image (prefix: copy URL), +/-: zoom, r: rotate, o: save preview") + (help-echo (if caption + (concat help-echo-base + "\n\"" + caption "\"") + help-echo-base))) (concat (propertize "[img]" 'media-url media-url diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7a346c1..6cd3ff0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -817,10 +817,11 @@ message is a link which unhides/hides the main body." (or (alist-get 'remote_url media-attachement) ;; fallback b/c notifications don't have remote_url (alist-get 'url media-attachement))) - (type (alist-get 'type media-attachement))) + (type (alist-get 'type media-attachement)) + (caption (alist-get 'description media-attachement))) (if mastodon-tl--display-media-p (mastodon-media--get-media-link-rendering - preview-url remote-url type) ; 2nd arg for shr-browse-url + preview-url remote-url type caption) ; 2nd arg for shr-browse-url (concat "Media::" preview-url "\n")))) media-attachements ""))) (if (not (and mastodon-tl--display-media-p -- cgit v1.2.3 From b1318ba12165d59cc1b7ce21d3b77099a3ff78d3 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 10 Mar 2022 13:14:11 +0100 Subject: translate toot with lingva.el this could easily be made into a macro supporting any emacs translation pkg --- lisp/mastodon-toot.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1d80e55..9c09441 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -70,6 +70,11 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") +; for mastodon-toot--translate-toot-text +(autoload 'mastodon-tl--content "mastodon-tl") +(when (require 'lingva nil :no-error) + (declare-function lingva-translate "lingva")) + (defgroup mastodon-toot nil "Tooting in Mastodon." :prefix "mastodon-toot-" @@ -278,6 +283,18 @@ Makes a POST request to the server." (kill-new (mastodon-tl--content toot)) (message "Toot content copied to the clipboard."))) +(when (require 'lingva nil :no-error) + (defun mastodon-toot--translate-toot-text () + "Translate text of toot at point. +Uses `lingva.el'." + (interactive) + (if mastodon-tl--buffer-spec + (let* ((toot (mastodon-tl--property 'toot-json))) + (if toot + (lingva-translate nil (mastodon-tl--content toot)) + (message "No toot to translate?"))) + (message "No mastodon buffer?")))) + (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." (and (not (alist-get 'reblog toot)) -- cgit v1.2.3 From b7c7bc608a0650842c3479564b85ff91031ae2d7 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 10 Mar 2022 18:30:24 +0100 Subject: make follow etc work on boost/fave notifs to achieve this, in notifications--format-note, we run notifications--insert-status on 'note' rather than 'status' handle mentions/reblogs when following from a notif --- lisp/mastodon-notifications.el | 18 ++++++++++++------ lisp/mastodon-profile.el | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index df4f9c0..670105a 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -168,12 +168,18 @@ Status notifications are given when (status (mastodon-tl--field 'status note)) (follower (alist-get 'username (alist-get 'account note)))) (mastodon-notifications--insert-status - (if (or (equal type 'follow) - (equal type 'follow-request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - (cons '(reblog (id . nil)) note) - status) + (cond ((or (equal type 'follow) + (equal type 'follow-request)) + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + (cons '(reblog (id . nil)) note)) + ;; reblogs/faves use 'note' to process their own json + ;; not the toot's. this ensures following etc. work on such notifs + ((or (equal type 'favourite) + (equal type 'boost)) + note) + (t + status)) (if (or (equal type 'follow) (equal type 'follow-request)) (propertize (if (equal type 'follow) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index cb449b6..793d8f9 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -483,8 +483,10 @@ These include the author, author of reblogged entries and any user mentioned." (let ((this-account (or (alist-get 'account status) ; status is a toot status)) ; status is a user listing - (mentions (alist-get 'mentions status)) - (reblog (alist-get 'reblog status))) + (mentions (or (alist-get 'mentions (alist-get 'status status)) + (alist-get 'mentions status))) + (reblog (or (alist-get 'reblog (alist-get 'status status)) + (alist-get 'reblog status)))) (seq-filter 'stringp (seq-uniq -- cgit v1.2.3 From 55689d91d2d220d156775847a6c6375c90469a08 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 08:43:11 +0100 Subject: improve empty notifications json message --- lisp/mastodon-notifications.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 670105a..719a77b 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -247,7 +247,7 @@ ID is the notification's own id, which is attached as a property." (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." (if (equal json '[]) - (message "Looks like you have no notifications for the moment.") + (message "Looks like you have no (more) notifications for the moment.") (mapc #'mastodon-notifications--by-type json) (goto-char (point-min)))) -- cgit v1.2.3 From 56995a8c693cca194e3272d17fec092c3585a3f4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 09:26:19 +0100 Subject: favourite not favorite --- lisp/mastodon-notifications.el | 4 ++-- lisp/mastodon-tl.el | 4 ++-- lisp/mastodon-toot.el | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 719a77b..041918d 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -146,7 +146,7 @@ Can be called in notifications view or in follow-requests view." (defun mastodon-notifications--favourite (note) "Format for a `favourite' NOTE." - (mastodon-notifications--format-note note 'favorite)) + (mastodon-notifications--format-note note 'favourite)) (defun mastodon-notifications--reblog (note) "Format for a `boost' NOTE." @@ -202,7 +202,7 @@ Status notifications are given when (mastodon-notifications--byline-concat (cond ((equal type 'boost) "Boosted") - ((equal type 'favorite) + ((equal type 'favourite) "Favourited") ((equal type 'follow-request) "Requested to follow") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6cd3ff0..e517397 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -376,7 +376,7 @@ Used on initializing a timeline or thread." ")"))) (defun mastodon-tl--format-faves-count (toot) - "Format a favorites, boosts, replies count for a TOOT. + "Format a favourites, boosts, replies count for a TOOT. Used as a help-echo when point is at the start of a byline, i.e. where `mastodon-tl--goto-next-toot' leaves point. Also displays a toot's media types and optionally the binding to play moving @@ -558,7 +558,7 @@ By default it is `mastodon-tl--byline-boosted'" 'byline t)))) (defun mastodon-tl--format-faved-or-boosted-byline (letter) - "Format the byline marker for a boosted or favorited status. + "Format the byline marker for a boosted or favourited status. LETTER is a string, either F or B." (format "(%s) " (propertize letter 'face 'mastodon-boost-fave-face))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9c09441..76d7d41 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -264,7 +264,7 @@ Makes a POST request to the server." (mastodon-toot--action-success "F" byline-region remove)) (message (format "%s #%s" action id)))) - (message "Nothing to favorite here?!?")))) + (message "Nothing to favourite here?!?")))) (defun mastodon-toot--copy-toot-url () "Copy URL of toot at point." -- cgit v1.2.3 From bd9710c355093259ec8a8cad8572a2b387aa631a Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 12:16:13 +0100 Subject: fix follow etc user when point on profile header info we just modify the if test to not run in accounts buffers, which means we end up using the next-toot solution, as was originally the case. hopefully a profile view will always have a toot or user or sth. else we cd find a better solution --- lisp/mastodon-tl.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e517397..919bbbb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1262,16 +1262,18 @@ Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "follow"))) - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") - (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify))) + (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify))) (defun mastodon-tl--enable-notify-user-posts (user-handle) "Query for USER-HANDLE and enable notifications when they post." (interactive (list (mastodon-tl--interactive-user-handles-get "enable"))) - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") (mastodon-tl--follow-user user-handle "true"))) @@ -1287,18 +1289,20 @@ Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "unfollow"))) - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") - (mastodon-tl--do-user-action-and-response user-handle "unfollow" t))) + (mastodon-tl--do-user-action-and-response user-handle "unfollow" t))) (defun mastodon-tl--block-user (user-handle) "Query for USER-HANDLE from current status and block that user." (interactive (list (mastodon-tl--interactive-user-handles-get "block"))) - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") - (mastodon-tl--do-user-action-and-response user-handle "block"))) + (mastodon-tl--do-user-action-and-response user-handle "block"))) (defun mastodon-tl--unblock-user (user-handle) "Query for USER-HANDLE from list of blocked users and unblock that user." @@ -1314,9 +1318,10 @@ Can be called to toggle NOTIFY on users already being followed." (interactive (list (mastodon-tl--interactive-user-handles-get "mute"))) - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") - (mastodon-tl--do-user-action-and-response user-handle "mute"))) + (mastodon-tl--do-user-action-and-response user-handle "mute"))) (defun mastodon-tl--unmute-user (user-handle) "Query for USER-HANDLE from list of muted users and unmute that user." @@ -1329,7 +1334,8 @@ Can be called to toggle NOTIFY on users already being followed." (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") (let ((user-handles (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") -- cgit v1.2.3 From 5239dc08a361c98a484447b2848c4b2997e072c6 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 12:50:55 +0100 Subject: don't add play with mpv help-echo if media type is "unknown" "unknown" type is given when a media image fails to load or similar. nil is e.g. when a profile picture isn't given, and missing.png is used as a replacement --- lisp/mastodon-media.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index f79b1fa..383e062 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -328,7 +328,9 @@ TYPE is the attachment's type field on the server." 'mastodon-tab-stop 'image ; for do-link-action-at-point 'image-url full-remote-url ; for shr-browse-image 'keymap mastodon-tl--shr-image-map-replacement - 'help-echo (if (string= type "image") + 'help-echo (if (or (string= type "image") + (string= type nil) + (string= type "unknown")) ;handle borked images help-echo (concat help-echo "\nC-RET: play " type " with mpv"))) " "))) -- cgit v1.2.3 From 9bd49d3bbab945c625c935b9025dcd20c8e1e58d Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 13:11:48 +0100 Subject: make profile--show-user also work on profile headers --- lisp/mastodon-profile.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 793d8f9..89dd02d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -400,7 +400,8 @@ If toot is a boost, opens the profile of the booster." "Query for USER-HANDLE from current status and show that user's profile." (interactive (list - (if (not (get-text-property (point) 'toot-json)) + (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) -- cgit v1.2.3 From f0f77a42fbd1b74fc0936dd1895812a4bc23d617 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 12 Mar 2022 09:03:02 +0100 Subject: make timestamps for boost/fave notifs the time of orig toot do not use the time stamp of the boosting/faving. in other views, mastodon-tl--field already handles this by fetching from 'reblog if present, but in notifs, there's no reblog section, and instead there's a status section. so we fetch from status if present, else fallback to using --field. this became necessary when we started attaching the boost/fave json to such notifs, rather than the json of the boosed/faved toot. --- lisp/mastodon-tl.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 919bbbb..4833a3f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -513,10 +513,19 @@ the byline that takes one variable. ACTION-BYLINE is a function for adding an action, such as boosting, favouriting and following to the byline. It also takes a single function. By default it is `mastodon-tl--byline-boosted'" - (let ((parsed-time (date-to-time (mastodon-tl--field 'created_at toot))) - (faved (equal 't (mastodon-tl--field 'favourited toot))) - (boosted (equal 't (mastodon-tl--field 'reblogged toot))) - (visibility (mastodon-tl--field 'visibility toot))) + (let* ((created-time + ;; bosts and faves in notifs view + ;; (makes timestamps be for the original toot + ;; not the boost/fave): + (or (mastodon-tl--field 'created_at + (mastodon-tl--field 'status toot)) + ;; all other toots, inc. boosts/faves in timelines: + ;; (mastodon-tl--field auto fetches from reblogs if needed): + (mastodon-tl--field 'created_at toot))) + (parsed-time (date-to-time created-time)) + (faved (equal 't (mastodon-tl--field 'favourited toot))) + (boosted (equal 't (mastodon-tl--field 'reblogged toot))) + (visibility (mastodon-tl--field 'visibility toot))) (concat ;; Boosted/favourited markers are not technically part of the byline, so ;; we don't propertize them with 'byline t', as per the rest. This -- cgit v1.2.3 From 12153c2f8d6976b15bba9bd6c51e9ebf655a937d Mon Sep 17 00:00:00 2001 From: mousebot Date: Sun, 13 Mar 2022 17:34:30 +0100 Subject: autoload and binding for translate-toot-text --- lisp/mastodon.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6eddd3d..30fc2d3 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -88,6 +88,9 @@ (autoload 'mastoton-tl--view-filters "mastodon-tl") ;; (autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") +(when (require 'lingva nil :no-error) + (autoload 'mastodon-toot--translate-toot-text "mastodon-toot")) + (defgroup mastodon nil "Interface with Mastodon." :prefix "mastodon-" @@ -167,6 +170,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) (define-key map (kbd "I") #'mastodon-tl--view-filters) (define-key map (kbd "G") #'mastodon-tl--get-follow-suggestions) + (when (require 'lingva nil :no-error) + (define-key map (kbd "s") #'mastodon-toot--translate-toot-text)) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 262da506ae52c619ce76b83488920cf4ae4b8b1b Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 14 Mar 2022 12:50:23 +0100 Subject: add header line to update profile note buffer --- lisp/mastodon-profile.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 89dd02d..6065bdd 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -207,6 +207,10 @@ JSON is the data returned by the server." (buffer (get-buffer-create "*mastodon-update-profile*")) (inhibit-read-only t)) (switch-to-buffer-other-window buffer) + (setq-local header-line-format + (propertize + "Edit your profile note. C-c C-c to send, C-c C-k to cancel." + 'face font-lock-comment-face)) (mastodon-profile-update-mode t) (insert note) (goto-char (point-min)) -- cgit v1.2.3 From 722fe98364621673c06b48a2ee3ccbc25cf0fcc4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 14 Mar 2022 21:55:22 +0100 Subject: readme on translating toots, etc --- README.org | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index a7a8407..929f5ea 100644 --- a/README.org +++ b/README.org @@ -67,9 +67,26 @@ Works for federated, local, and home timelines and for notifications. It's prett To enable, it, add =(require 'mastodon-async)= to your =init.el=. Then you can view a timeline with one of the commands that begin with =mastodon-async--stream-=. +** translating toots + +You can translate toots with =mastodon-toot--translate-toot-text=. At the moment this requires [[https://codeberg.org/martianh/lingva.el][lingva.el]], a little interface I wrote to https://lingva.ml, to be installed to work. + +You could easily modify the simple function to use your emacs translator of choice (=google-translate=, =babel=, =go-translate=, etc.), you just need to fetch the toot's content with =(mastodon-tl--content toot)= and pass it to your translator function as its text argument. Here's what =mastodon-toot--translate-toot-text= looks like: + +#+begin_src emacs-lisp + (defun mastodon-toot--translate-toot-text () + "Translate text of toot at point. + Uses `lingva.el'." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json))) + (if toot + (lingva-translate nil (mastodon-tl--content toot)) + (message "No toot to translate?")))) +#+end_src + ** NB: dependency -This version depends on the library =request= (for uploading attachments). You can install it from MELPA, or https://github.com/tkf/emacs-request. +This version depends on the library =request= (for uploading attachments). If you installed =mastodon.el= from MELPA, it should be fine, else you can install it yourself from MELPA or https://github.com/tkf/emacs-request. ** NB: bugs @@ -83,7 +100,7 @@ It looks like 2-factor auth was never completed in the original repo. It's not a ** contributing -Contributions are welcome. Registration is disabled by default on the gitea instance, but if you are interested, get in touch with me on mastodon: +Contributions are welcome. Feel free to open an issue or get in touch with me on mastodon: [[https://todon.nl/@mousebot][@mousebot@todon.nl]] -- cgit v1.2.3 From db2d0aed887c072e1a100ee54205091e1f2d981c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Mar 2022 10:05:56 +0100 Subject: remove require test for --translate-toot-text we already have the same test for declaring lingva-translate fun, so this shouldn't be needed and seems to prevent our fun from loading. --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 76d7d41..780e726 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -283,7 +283,7 @@ Makes a POST request to the server." (kill-new (mastodon-tl--content toot)) (message "Toot content copied to the clipboard."))) -(when (require 'lingva nil :no-error) +;; (when (require 'lingva nil :no-error) (defun mastodon-toot--translate-toot-text () "Translate text of toot at point. Uses `lingva.el'." @@ -293,7 +293,7 @@ Uses `lingva.el'." (if toot (lingva-translate nil (mastodon-tl--content toot)) (message "No toot to translate?"))) - (message "No mastodon buffer?")))) + (message "No mastodon buffer?"))) (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." -- cgit v1.2.3 From c7b475160d2e7712e339e15adf168529f71b52c6 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 19 Mar 2022 16:07:44 +0100 Subject: attach parent JSON to fave/boost notifs to fix replies because we switched to using boost/fave JSON rather than parent, as 'toot-json, replies to these toots were broken (mentions, etc.) so now we attach both bits of data and selectively pull from each. --- lisp/mastodon-notifications.el | 9 ++++++--- lisp/mastodon-tl.el | 5 +++-- lisp/mastodon-toot.el | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 041918d..6b253ec 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -214,9 +214,12 @@ Status notifications are given when "Posted") ((equal type 'poll) "Posted a poll")))) - id))) + id + (when (or (equal type 'favourite) + (equal type 'boost)) + status)))) -(defun mastodon-notifications--insert-status (toot body author-byline action-byline id) +(defun mastodon-notifications--insert-status (toot body author-byline action-byline id &optional parent-toot) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -232,7 +235,7 @@ takes a single function. By default it is ID is the notification's own id, which is attached as a property." (when toot ; handle rare blank notif server bug - (mastodon-tl--insert-status toot body author-byline action-byline id))) + (mastodon-tl--insert-status toot body author-byline action-byline id parent-toot))) (defun mastodon-notifications--by-type (note) "Filters NOTE for those listed in `mastodon-notifications--types-alist'." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4833a3f..40cbcae 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -852,7 +852,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--get-poll toot)) (mastodon-tl--media toot)))) -(defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id) +(defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id parent-toot) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -876,7 +876,8 @@ a notification." 'toot-id (or id ; for notifications (alist-get 'id toot)) 'base-toot-id (mastodon-tl--toot-id toot) - 'toot-json toot) + 'toot-json toot + 'parent-toot parent-toot) "\n") (when mastodon-tl--display-media-p (mastodon-media--inline-images start-pos (point))))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 780e726..07ab400 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -617,11 +617,12 @@ candidate ARG. IGNORED remains a mystery." "Reply to toot at `point'." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) + (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id toot))) (account (mastodon-tl--field 'account toot)) (user (alist-get 'acct account)) - (mentions (mastodon-toot--mentions toot)) - (boosted (mastodon-tl--field 'reblog toot)) + (mentions (mastodon-toot--mentions (or parent toot))) + (boosted (mastodon-tl--field 'reblog (or parent toot))) (booster (when boosted (alist-get 'acct (alist-get 'account toot))))) @@ -637,7 +638,7 @@ candidate ARG. IGNORED remains a mystery." mentions)) (concat (mastodon-toot--process-local user) mentions))) - id toot))) + id (or parent toot)))) (defun mastodon-toot--toggle-warning () "Toggle `mastodon-toot--content-warning'." -- cgit v1.2.3 From 6d4528ca05d946892e13cbc4657d0c379445b13d Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 25 Mar 2022 17:39:19 +0100 Subject: call lingva-translate with optional variable-pitch arg --- lisp/mastodon-toot.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 07ab400..52b061c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -289,9 +289,12 @@ Makes a POST request to the server." Uses `lingva.el'." (interactive) (if mastodon-tl--buffer-spec - (let* ((toot (mastodon-tl--property 'toot-json))) + (let ((toot (mastodon-tl--property 'toot-json))) (if toot - (lingva-translate nil (mastodon-tl--content toot)) + (lingva-translate nil + (mastodon-tl--content toot) + (when mastodon-tl--enable-proportional-fonts + t)) (message "No toot to translate?"))) (message "No mastodon buffer?"))) -- cgit v1.2.3 From 1cc9cc621c9ab31419f965d5958ff24b1bc8f987 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 29 Mar 2022 21:34:23 +0200 Subject: toot--reply: improve mentions in replies - make sure we get ID from parent if its a fave/boost - avoid duplicates if user or booster already in mentions list --- lisp/mastodon-toot.el | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 52b061c..79f3d74 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -621,7 +621,8 @@ candidate ARG. IGNORED remains a mystery." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling - (id (mastodon-tl--as-string (mastodon-tl--field 'id toot))) + (id (mastodon-tl--as-string + (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) (user (alist-get 'acct account)) (mentions (mastodon-toot--mentions (or parent toot))) @@ -634,14 +635,27 @@ candidate ARG. IGNORED remains a mystery." (if (and (not (equal user booster)) (not (string-match booster mentions))) + ;; different booster, user and mentions: (concat (mastodon-toot--process-local user) ;; "@" booster " " - (mastodon-toot--process-local booster) mentions) + (mastodon-toot--process-local booster) + mentions) + ;; booster is either user or in mentions: + (if (not string-match user mentions) + ;; user not already in mentions: + (concat (mastodon-toot--process-local user) + mentions) + ;; user already in mentions: + mentions)) + ;; no booster: + (if (not (string-match user mentions)) + ;; user not in mentions: (concat (mastodon-toot--process-local user) - mentions)) - (concat (mastodon-toot--process-local user) - mentions))) - id (or parent toot)))) + mentions) + ;; user in mentions already: + mentions))) + id + (or parent toot)))) (defun mastodon-toot--toggle-warning () "Toggle `mastodon-toot--content-warning'." -- cgit v1.2.3 From 0794d93ab897a2cb8c917bb6884007b13e04a1d3 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:05 +0200 Subject: toot: indents and flycheck --- lisp/mastodon-toot.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 79f3d74..1f3440c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -48,6 +48,7 @@ (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) +(defvar mastodon-tl--enable-proportional-fonts) (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--delete "mastodon-http") @@ -70,7 +71,7 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") -; for mastodon-toot--translate-toot-text +;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") (when (require 'lingva nil :no-error) (declare-function lingva-translate "lingva")) @@ -176,9 +177,9 @@ Valid values are \"direct\", \"private\" (followers-only), (alist-get 'statuses (alist-get 'configuration json-response)))))) - (setq mastodon-toot--max-toot-chars max-chars) - (with-current-buffer "*new toot*" - (mastodon-toot--update-status-fields)))) + (setq mastodon-toot--max-toot-chars max-chars) + (with-current-buffer "*new toot*" + (mastodon-toot--update-status-fields)))) (defun mastodon-toot--action-success (marker byline-region remove) "Insert/remove the text MARKER with 'success face in byline. @@ -202,7 +203,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (propertize marker 'face 'success))))) ;; leave point after the marker: (unless remove - (mastodon-tl--goto-next-toot)))) + (mastodon-tl--goto-next-toot)))) (defun mastodon-toot--action (action callback) "Take ACTION on toot at point, then execute CALLBACK. @@ -296,7 +297,7 @@ Uses `lingva.el'." (when mastodon-tl--enable-proportional-fonts t)) (message "No toot to translate?"))) - (message "No mastodon buffer?"))) + (message "No mastodon buffer?")))) (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." @@ -350,7 +351,7 @@ NO-REDRAFT means delete toot only." (if no-redraft (progn (when mastodon-tl--buffer-spec - (mastodon-tl--reload-timeline-or-profile)) + (mastodon-tl--reload-timeline-or-profile)) (message "Toot deleted!")) (mastodon-toot--redraft response reply-id @@ -519,9 +520,9 @@ If media items have been attached and uploaded with (symbol-name t))) ("spoiler_text" . ,spoiler))) (args-media (when mastodon-toot--media-attachments - (mapcar (lambda (id) - (cons "media_ids[]" id)) - mastodon-toot--media-attachment-ids))) + (mapcar (lambda (id) + (cons "media_ids[]" id)) + mastodon-toot--media-attachment-ids))) (args (append args-media args-no-media))) (cond ((and mastodon-toot--media-attachments ;; make sure we have media args -- cgit v1.2.3 From 2fbf4694672e8dfa53767e6e2402490fa871d824 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:32 +0200 Subject: toot: missing parens in --reply booster checks --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1f3440c..6521b16 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -642,13 +642,13 @@ candidate ARG. IGNORED remains a mystery." (mastodon-toot--process-local booster) mentions) ;; booster is either user or in mentions: - (if (not string-match user mentions) + (if (not (string-match user mentions)) ;; user not already in mentions: (concat (mastodon-toot--process-local user) mentions) ;; user already in mentions: mentions)) - ;; no booster: + ;; ELSE no booster: (if (not (string-match user mentions)) ;; user not in mentions: (concat (mastodon-toot--process-local user) -- cgit v1.2.3 From adccdcd22a527720efaa38f57f3077d70687bdfe Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:51 +0200 Subject: toot: message if translate-toot called without lingva.el --- lisp/mastodon-toot.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 6521b16..f8d0642 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -285,10 +285,12 @@ Makes a POST request to the server." (message "Toot content copied to the clipboard."))) ;; (when (require 'lingva nil :no-error) - (defun mastodon-toot--translate-toot-text () - "Translate text of toot at point. +(defun mastodon-toot--translate-toot-text () + "Translate text of toot at point. Uses `lingva.el'." - (interactive) + (interactive) + (if (not (require 'lingva nil :no-error)) + (message "Looks like you need to install lingva.el first.") (if mastodon-tl--buffer-spec (let ((toot (mastodon-tl--property 'toot-json))) (if toot -- cgit v1.2.3 From fb69058495574a73df17856014c42370b23d81d7 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:17:59 +0200 Subject: flychecks and docstrings --- lisp/mastodon-media.el | 3 ++- lisp/mastodon-notifications.el | 4 +++- lisp/mastodon-tl.el | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 383e062..e5a1111 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -310,7 +310,8 @@ Replace them with the referenced image." (defun mastodon-media--get-media-link-rendering (media-url &optional full-remote-url type caption) "Return the string to be written that renders the image at MEDIA-URL. FULL-REMOTE-URL is used for `shr-browse-image'. -TYPE is the attachment's type field on the server." +TYPE is the attachment's type field on the server. +CAPTION is the image caption if provided." (let* ((help-echo-base "RET/i: load full image (prefix: copy URL), +/-: zoom, r: rotate, o: save preview") (help-echo (if caption (concat help-echo-base diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6b253ec..5de7354 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -233,7 +233,9 @@ such as boosting favouriting and following to the byline. It also takes a single function. By default it is `mastodon-tl--byline-boosted'. -ID is the notification's own id, which is attached as a property." +ID is the notification's own id, which is attached as a property. +If the status is a favourite or a boost, PARENT-TOOT is the JSON +of the toot responded to." (when toot ; handle rare blank notif server bug (mastodon-tl--insert-status toot body author-byline action-byline id parent-toot))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 40cbcae..3c96ecc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -865,7 +865,8 @@ takes a single function. By default it is `mastodon-tl--byline-boosted'. ID is that of the toot, which is attached as a property if it is -a notification." +a notification. If the status is a favourite or a boost, +PARENT-TOOT is the JSON of the toot responded to." (let ((start-pos (point))) (insert (propertize -- cgit v1.2.3