diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-http.el | 17 | ||||
-rw-r--r-- | lisp/mastodon-notifications.el | 6 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 21 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 90 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 13 | ||||
-rw-r--r-- | lisp/mastodon.el | 3 |
6 files changed, 110 insertions, 40 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 7ef6f77..60654ff 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -141,14 +141,21 @@ Used for API form data parameters that take an array." &optional params headers unauthenticated-p json) "POST synchronously to URL, optionally with PARAMS and HEADERS. Authorization header is included by default unless -UNAUTHENTICATED-P is non-nil.If JSON, encode PARAMS as JSON for -the request data." +UNAUTHENTICATED-P is non-nil. +If JSON is :json, encode PARAMS as JSON for +the request data. If it is :raw, just use the plain params." + ;; NB: raw is used by `mastodon-tl--unfilter-user-languages'; not sure if + ;; there's a way around it? (mastodon-http--authorized-request "POST" (let* ((url-request-data (when params - (if json - (json-encode params) - (mastodon-http--build-params-string params)))) + (cond ((eq json :json) + (json-encode + params)) + ((eq json :raw) + params) + (t + (mastodon-http--build-params-string params))))) (url-request-extra-headers (append url-request-extra-headers ; auth set in macro (unless (assoc "Content-Type" headers) ; pleroma compat: diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 9b40861..c26d0b0 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -59,13 +59,11 @@ :group 'mastodon) (defcustom mastodon-notifications--profile-note-in-foll-reqs t - "When non-nil, show some of a user's profile note in follow -request notifications." + "If non-nil, show a user's profile note in follow request notifications." :type '(boolean)) (defcustom mastodon-notifications--profile-note-in-foll-reqs-max-length nil - "The maximum character length for display of user profile note in -follow requests. + "The max character length for user profile note in follow requests. Profile notes are only displayed if `mastodon-notifications--profile-note-in-foll-reqs' is non-nil. If unset, profile notes of any size will be displayed, which may diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 31a1983..46a56f6 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -130,7 +130,10 @@ It contains details of the current user's account.") Other clients can change these settings on the server at any time, so this list is not the canonical source for settings. It is updated on entering mastodon mode and on toggle any setting it -contains") +contains. +This variable is set from data in +`mastodon-profile-credential-account' not +`mastodon-profile-account-preferences-data'.") (define-minor-mode mastodon-profile-update-mode "Minor mode to update user profile." @@ -498,7 +501,7 @@ Returns the results as an alist." "Limit string X to 255 chars max." (if (> (length x) 255) (substring x 0 255) x)) -;; used in tl.el +;; used in tl.el and toot.el: (defun mastodon-profile--get-preferences-pref (pref) "Fetch PREF from the endpoint \"/preferences\". If `mastodon-profile-acccount-preferences-data' is set, fetch @@ -697,12 +700,20 @@ TAG is a hashtag to restrict posts to." 'success) ;; insert relationship (follows) (let-alist relationships - (let ((followsp (mastodon-profile--follows-p - (list .requested_by .following .followed_by)))) + (let* ((followsp (mastodon-profile--follows-p + (list .requested_by .following .followed_by))) + (rels (mastodon-profile--relationships-get .id)) + (langs-filtered (if-let ((langs (alist-get 'languages rels))) + (concat " (" + (mapconcat #'identity + langs + " ") + ")") + ""))) (if followsp (mastodon-tl--set-face (concat (when (equal .following 't) - " | FOLLOWED BY YOU") + (format " | FOLLOWED BY YOU%s" langs-filtered)) (when (equal .followed_by 't) " | FOLLOWS YOU") (when (equal .requested_by 't) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index db923a4..aa70507 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -88,6 +88,7 @@ (autoload 'mastodon-http--get-response "mastodon-http") (autoload 'mastodon-search--insert-heading "mastodon-search") (autoload 'mastodon-media--process-full-sized-image-response "mastodon-media") +(autoload 'mastodon-search--trending-statuses "mastodon-search") (defvar mastodon-toot--visibility) (defvar mastodon-toot-mode) @@ -213,7 +214,8 @@ respects the user's `browse-url' settings." :type '(boolean)) (defcustom mastodon-tl--remote-local-domains nil - "A list of domains to view the local timelines of using `mastodon-tl--get-remote-local-timeline'." + "A list of domains to view the local timelines of. +See `mastodon-tl--get-remote-local-timeline' for view remote local domains." :type '(repeat string)) @@ -473,7 +475,10 @@ You can enter any working instance domain. Domains that you want to regularly load can be stored in `mastodon-tl--remote-local-domains' for easy access with completion. Note that some instances do not make their local timelines public, in -which case this will not work." +which case this will not work. +To interact with any item, you must view it from your own +instance, which you can do with +`mastodon-tl--view-item-on-own-instance'." (interactive) (let* ((domain (completing-read "Domain for remote local tl: " mastodon-tl--remote-local-domains)) @@ -485,17 +490,22 @@ which case this will not work." (mastodon-http--api "instance/peers"))))) ;; condition-case doesn't work here, so i added basic error handling to ;; `mastodon-tl--init*' instead - (if (not known) - (when (y-or-n-p - "Domain appears unknown to your instance. Proceed?") - ;; TODO: refactor these calls: - (mastodon-tl--init buf - "timelines/public" 'mastodon-tl--timeline nil - params nil domain)) + (when (or known + (y-or-n-p + "Domain appears unknown to your instance. Proceed?")) (mastodon-tl--init buf "timelines/public" 'mastodon-tl--timeline nil params nil domain)))) +(defun mastodon-tl--view-item-on-own-instance () + "Load current toot on your own instance. +Use this to re-load remote-local items in order to interact with them." + (interactive) + (mastodon-tl--do-if-item + (let* ((toot (mastodon-tl--property 'item-json)) + (uri (mastodon-tl--field 'uri toot))) + (mastodon-url-lookup uri)))) + (defun mastodon-tl--get-local-timeline (&optional prefix) "Open local timeline. With a single PREFIX arg, hide-replies. @@ -2036,19 +2046,21 @@ ID is that of the post the context is currently displayed for." ;;; FOLLOW/BLOCK/MUTE, ETC -(defun mastodon-tl--follow-user (user-handle &optional notify langs reblogs) +(defun mastodon-tl--follow-user (user-handle + &optional notify langs reblogs json) "Query for USER-HANDLE from current status and follow that user. 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. LANGS is an array parameters alist of languages to filer user's posts by. REBLOGS is a boolean string like NOTIFY, enabling or disabling -display of the user's boosts in your timeline." +display of the user's boosts in your timeline. +JSON is a flag arg for `mastodon-http--post'." (interactive (list (mastodon-tl--user-handles-get "follow"))) (mastodon-tl--do-if-item (mastodon-tl--do-user-action-and-response - user-handle "follow" nil notify langs reblogs))) + user-handle "follow" nil notify langs reblogs json))) ;; TODO: make this action "enable/disable notifications" (defun mastodon-tl--enable-notify-user-posts (user-handle) @@ -2081,24 +2093,42 @@ display of boosts." (mastodon-tl--follow-user user-handle nil nil "true")) (defun mastodon-tl--filter-user-user-posts-by-language (user-handle) - "Query for USER-HANDLE and enable notifications when they post. -This feature is experimental and for now not easily varified by -the instance API." + "Query for USER-HANDLE and filter display of their posts by language. +If they are not already followed, they will be too. +To be filtered, a post has to be marked as in the language given. +This may mean that you will not see posts that are in your +desired language if they are not marked as such (or as anything)." (interactive (list (mastodon-tl--user-handles-get "filter by language"))) (let ((langs (mastodon-tl--read-filter-langs))) (mastodon-tl--do-if-item - (mastodon-tl--follow-user user-handle nil langs)))) + (if (equal "" (cdar langs)) + (mastodon-tl--unfilter-user-languages user-handle) + (mastodon-tl--follow-user user-handle nil langs))))) + +(defun mastodon-tl--unfilter-user-languages (user-handle) + "Remove any language filters for USER-HANDLE. +This means you will receive posts of theirs marked as being in +any or no language." + (interactive + (list (mastodon-tl--user-handles-get "filter by language"))) + (let ((langs "languages[]")) + (mastodon-tl--do-if-item + ;; we need "languages[]" as a param, with no "=" and not json-encoded as + ;; a string + (mastodon-tl--follow-user user-handle nil langs nil :raw)))) (defun mastodon-tl--read-filter-langs (&optional langs) "Read language choices and return an alist array parameter. LANGS is the accumulated array param alist if we re-run recursively." - (let* ((langs-alist langs) + (let* ((iso-const mastodon-iso-639-1) + (iso (cons '("None (all)" . "") iso-const)) + (langs-alist langs) (choice (completing-read "Filter user's posts by language: " - mastodon-iso-639-1))) + iso))) (when choice (setq langs-alist - (push `("languages[]" . ,(alist-get choice mastodon-iso-639-1 + (push `("languages[]" . ,(alist-get choice iso nil nil #'string=)) langs-alist)) (if (y-or-n-p "Filter by another language? ") @@ -2204,7 +2234,7 @@ Action must be either \"unblock\" or \"unmute\"." accts nil t)))) ; require match (defun mastodon-tl--do-user-action-and-response - (user-handle action &optional negp notify langs reblogs) + (user-handle action &optional negp notify langs reblogs json) "Do ACTION on user USER-HANDLE. NEGP is whether the action involves un-doing something. If NOTIFY is \"true\", enable notifications when that user posts. @@ -2234,18 +2264,18 @@ display of the user's boosts in your timeline." (url (mastodon-http--api (format "accounts/%s/%s" user-id action)))) (if account (if (equal action "follow") ; y-or-n for all but follow - (mastodon-tl--do-user-action-function url name user-handle action notify args reblogs) + (mastodon-tl--do-user-action-function url name user-handle action notify args reblogs json) (when (y-or-n-p (format "%s user %s? " action name)) (mastodon-tl--do-user-action-function url name user-handle action args))) (message "Cannot find a user with handle %S" user-handle)))) (defun mastodon-tl--do-user-action-function - (url name user-handle action &optional notify args reblogs) + (url name user-handle action &optional notify args reblogs json) "Post ACTION on user NAME/USER-HANDLE to URL. NOTIFY is either \"true\" or \"false\", and used when we have been called by `mastodon-tl--follow-user' to enable or disable notifications. ARGS is an alist of any parameters to send with the request." - (let ((response (mastodon-http--post url args))) + (let ((response (mastodon-http--post url args nil nil json))) (mastodon-http--triage response (lambda (response) @@ -2271,6 +2301,8 @@ ARGS is an alist of any parameters to send with the request." ((or (string-equal action "mute") (string-equal action "unmute")) (message "User %s (@%s) %sd!" name user-handle action)) + ((equal args "languages[]") + (message "User %s language filters removed!" name)) ((assoc "languages[]" args #'equal) (message "User %s filtered by language(s): %s" name (mapconcat #'cdr args " "))) @@ -2868,7 +2900,17 @@ RESPONSE is the data returned from the server by JSON and http headers, without it just the JSON." (let ((json (if headers (car response) response))) (cond ((not json) ; praying this is right here, else try "\n[]" - (message "Looks like nothing returned from endpoint: %s" endpoint)) + ;; this means that whatever tl was inited won't load, which is not + ;; always wanted, as sometimes you still need the page to load so + ;; you can be in eg mastodon-mode, have keymap, search etc. + (message "Looks like nothing returned from endpoint: %s" endpoint) + ;; if we are a new account, home tl may have nothing, but then + ;; this clause means we can never load mastodon.el at all! + ;; so as a fallback, load trending statuses: + ;; FIXME: this could possibly be a fallback for all timelines not + ;; just home? + (when (equal endpoint "timelines/home") + (mastodon-search--trending-statuses))) ((eq (caar json) 'error) (user-error "Looks like the server bugged out: \"%s\"" (cdar json))) (t diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 864d767..654918c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -50,6 +50,7 @@ (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--enable-proportional-fonts) (defvar mastodon-profile-account-settings) +(defvar mastodon-profile-acccount-preferences-data) (autoload 'iso8601-parse "iso8601") (autoload 'mastodon-auth--user-acct "mastodon-auth") @@ -92,6 +93,8 @@ (autoload 'mastodon-views--view-scheduled-toots "mastodon-views") (autoload 'org-read-date "org") (autoload 'mastodon-tl--toot-or-base "mastodon-tl") +(autoload 'mastodon-profile--get-source-value "mastodon-toot") +(autoload 'mastodon-tl--get-buffer-type "mastodon-tl") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -1878,11 +1881,19 @@ EDIT means we are editing an existing toot, not composing a new one." (switch-to-buffer-other-window buffer) (text-mode) (mastodon-toot-mode t) + ;; set visibility: (setq mastodon-toot--visibility (or (plist-get mastodon-profile-account-settings 'privacy) ;; use toot visibility setting from the server: - (mastodon-profile--get-source-pref 'privacy) + (mastodon-profile--get-source-value 'privacy) "public")) ; fallback + ;; default language: + ;; NB: this is not necessarily set in + ;; `mastodon-profile-credential-account' nor in + ;; `mastodon-profile-account-settings'! + (setq mastodon-toot--language + (mastodon-profile--get-preferences-pref 'posting:default:language)) + ;; display original toot: (if mastodon-toot-display-orig-in-reply-buffer (progn (mastodon-toot--display-docs-and-status-fields reply-text) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6eac3d8..a0b5bbc 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -6,7 +6,7 @@ ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Marty Hiatt <martianhiatus@riseup.net> ;; Maintainer: Marty Hiatt <martianhiatus@riseup.net> -;; Version: 1.0.22 +;; Version: 1.0.23 ;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) ;; Homepage: https://codeberg.org/martianh/mastodon.el @@ -175,6 +175,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "P") #'mastodon-profile--show-user) (define-key map (kbd "s") #'mastodon-search--query) (define-key map (kbd "/") #'mastodon-switch-to-buffer) + (define-key map (kbd "\\") #'mastodon-tl--get-remote-local-timeline) ;; quitting mastodon (define-key map (kbd "q") #'kill-current-buffer) (define-key map (kbd "Q") #'mastodon-kill-window) |