From e6d2c3ab8cc616799ccff979fa66e3d83c43f9f8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 14:12:59 +0100 Subject: factor out mastodon-views.el for minor views These are currently lists, follow suggestions, filters, scheduled toots, follow requests, and instance descriptions. fix remanant tl fun names in views stray views fun rename in notifs.el stray views funs in notifs stray views funs in toot.el views file commentary --- lisp/mastodon-views.el | 894 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 894 insertions(+) create mode 100644 lisp/mastodon-views.el (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el new file mode 100644 index 0000000..1e3dd4a --- /dev/null +++ b/lisp/mastodon-views.el @@ -0,0 +1,894 @@ +;;; mastodon-views.el --- Minor views functions for mastodon.el -*- lexical-binding: t -*- + +;; Copyright (C) 2020-2022 Marty Hiatt +;; Author: Marty Hiatt +;; Maintainer: Marty Hiatt +;; Version: 1.0.0 +;; Package-Requires: ((emacs "27.1")) +;; Homepage: https://codeberg.org/martianh/mastodon.el + +;; This file is not part of GNU Emacs. + +;; This file is part of mastodon.el. + +;; mastodon.el is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; mastodon.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mastodon.el. If not, see . + +;;; Commentary: + +;; mastodon-views.el provides minor views functions. + +;; These are currently lists, follow suggestions, filters, scheduled toots, +;; follow requests, and instance descriptions. + +;; It doesn't include favourites, bookmarks, preferences, trending tags, followed tags, toot edits, + +;;; Code: + +(require 'cl-lib) +(require 'mastodon-http) + +(defvar mastodon-profile--account) +(defvar mastodon-mode-map) + +(autoload 'mastodon-mode "mastodon") +(autoload 'mastodon-tl--init "mastodon-tl") +(autoload 'mastodon-tl--init-sync "mastodon-tl") +(autoload 'mastodon-tl--field "mastodon-tl") +(autoload 'mastodon-tl--property "mastodon-tl") +(autoload 'mastodon-tl--set-face "mastodon-tl") +(autoload 'mastodon-tl--buffer-type-eq "mastodon-tl") +(autoload 'mastodon-tl--profile-buffer-p "mastodon-tl") +(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-tl--do-if-toot "mastodon-tl") +(autoload 'mastodon-tl--set-buffer-spec "mastodon-tl") +(autoload 'mastodon-tl--render-text "mastodon-tl") +(autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") +(autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") +(autoload 'mastodon-auth--get-account-id "mastodon-auth") +(autoload 'mastodon-toot--iso-to-human "mastodon-toot") +(autoload 'mastodon-toot--schedule-toot "mastodon-toot") +(autoload 'mastodon-toot--compose-buffer "mastodon-toot") +(autoload 'mastodon-toot--set-toot-properties "mastodon-toot") +(autoload 'mastodon-search--propertize-user "mastodon-search") +(autoload 'mastodon-search--insert-users-propertized "mastodon-search") + + +;;; KEYMAPS + +(defvar mastodon-views--view-filters-keymap + (let ((map + (copy-keymap mastodon-mode-map))) + (define-key map (kbd "d") 'mastodon-views--delete-filter) + (define-key map (kbd "c") 'mastodon-views--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-item) + (define-key map (kbd "g") 'mastodon-views--view-filters) + (keymap-canonicalize map)) + "Keymap for viewing filters.") + +(defvar mastodon-views--follow-suggestions-map + (let ((map + (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 "g") 'mastodon-views--get-follow-suggestions) + (keymap-canonicalize map)) + "Keymap for viewing follow suggestions.") + +(defvar mastodon-views--view-lists-keymap + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) + (define-key map (kbd "D") 'mastodon-views--delete-list) + (define-key map (kbd "C") 'mastodon-views--create-list) + (define-key map (kbd "A") 'mastodon-views--add-account-to-list) + (define-key map (kbd "R") 'mastodon-views--remove-account-from-list) + (define-key map (kbd "E") 'mastodon-views--edit-list) + (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-views--view-lists) + (keymap-canonicalize map)) + "Keymap for viewing lists.") + +(defvar mastodon-views--list-name-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "") 'mastodon-views--view-timeline-list-at-point) + (define-key map (kbd "d") 'mastodon-views--delete-list-at-point) + (define-key map (kbd "a") 'mastodon-views--add-account-to-list-at-point) + (define-key map (kbd "r") 'mastodon-views--remove-account-from-list-at-point) + (define-key map (kbd "e") 'mastodon-views--edit-list-at-point) + (keymap-canonicalize map)) + "Keymap for when point is on list name.") + +(defvar mastodon-views--scheduled-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "r") 'mastodon-views--reschedule-toot) + (define-key map (kbd "c") 'mastodon-views--cancel-scheduled-toot) + (define-key map (kbd "e") 'mastodon-views--edit-scheduled-as-new) + (define-key map (kbd "") 'mastodon-views--edit-scheduled-as-new) + (keymap-canonicalize map)) + "Keymap for when point is on a scheduled toot.") + +(defvar mastodon-views--view-follow-requests-keymap + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) + ;; make reject binding match the binding in notifs view + ;; 'r' is then reserved for replying, even tho it is not avail + ;; in foll-reqs view + (define-key map (kbd "j") #'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-views--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.") + + +;;; GENERAL FUNCTION + +(defun mastodon-views--minor-view (view-name bindings-string insert-fun data) + "Load a minor view named VIEW-NAME. +BINDINGS-STRING is a string explaining the view's local bindings. +INSERT-FUN is the function to call to insert the view's elements. +DATA is the argument to insert-fun, usually JSON returned in a +request. +This function is used as the update-function to +`mastodon-tl--init-sync', which initializes a buffer for us and +provides the JSON data." + (erase-buffer) + (insert (mastodon-tl--set-face + (concat "\n ------------\n " + (upcase view-name) + "\n" + " ------------\n\n") + 'success) + (if bindings-string + (mastodon-tl--set-face + (concat "[" bindings-string "]" + "\n\n") + 'font-lock-comment-face) + "")) + (if (seq-empty-p data) + (insert (propertize + (format "Looks like you have no %s for now." view-name) + 'face font-lock-comment-face + 'byline t + 'toot-id "0")) ; so point can move here when no filters + (funcall insert-fun data) + (goto-char (point-min))) + ;; (when json + ;; FIXME: this seems to trigger a new request, but ideally would run. + ;; (mastodon-tl--goto-next-toot)))) + ) + + +;;; LISTS + +(defun mastodon-views--view-lists () + "Show the user's lists in a new buffer." + (interactive) + (mastodon-tl--init-sync "lists" + "lists" + 'mastodon-views--insert-lists) + (with-current-buffer "*mastodon-lists*" + (use-local-map mastodon-views--view-lists-keymap))) + +(defun mastodon-views--insert-lists (json) + "Insert the user's lists from JSON." + (mastodon-views--minor-view + "your lists" + "C - create a list\n D - delete a list\ + \n A/R - add/remove account from a list\ + \n E - edit a list\n n/p - go to next/prev item" + #'mastodon-views--print-list-set + json)) + +(defun mastodon-views--print-list-set (lists) + "Print each account plus a separator for each list in LISTS." + (let ((lists-names + (mapcar (lambda (x) + (alist-get 'title x)) + lists))) + (mapc (lambda (x) + (mastodon-views--print-list-accounts x) + (insert (propertize " ------------\n\n" + 'face 'success))) + lists-names))) + +(defun mastodon-views--print-list-accounts (list-name) + "Insert the accounts in list named LIST-NAME." + (let* ((id (mastodon-views--get-list-id list-name)) + (accounts (mastodon-views--accounts-in-list id))) + (insert + (propertize list-name + 'byline t ; so we nav here + 'toot-id "0" ; so we nav here + 'help-echo "RET: view list timeline, d: delete this list, \ +a: add account to this list, r: remove account from this list" + 'list t + 'face 'link + 'keymap mastodon-views--list-name-keymap + 'list-name list-name + 'list-id id) + (propertize + "\n\n" + 'list t + 'keymap mastodon-views--list-name-keymap + 'list-name list-name + 'list-id id) + (propertize + (mapconcat #'mastodon-search--propertize-user accounts + " ") + ;; (mastodon-search--insert-users-propertized accounts) + 'list t + 'keymap mastodon-views--list-name-keymap + 'list-name list-name + 'list-id id)))) + +(defun mastodon-views--get-users-lists () + "Get the list of the user's lists from the server." + (let ((url (mastodon-http--api "lists"))) + (mastodon-http--get-json url))) + +(defun mastodon-views--get-lists-names () + "Return a list of the user's lists' names." + (let ((lists (mastodon-views--get-users-lists))) + (mapcar (lambda (x) + (alist-get 'title x)) + lists))) + +(defun mastodon-views--get-list-by-name (name) + "Return the list data for list with NAME." + (let* ((lists (mastodon-views--get-users-lists))) + (cl-loop for list in lists + if (string= (alist-get 'title list) name) + return list))) + +(defun mastodon-views--get-list-id (name) + "Return id for list with NAME." + (let ((list (mastodon-views--get-list-by-name name))) + (alist-get 'id list))) + +(defun mastodon-views--get-list-name (id) + "Return name of list with ID." + (let* ((url (mastodon-http--api (format "lists/%s" id))) + (response (mastodon-http--get-json url))) + (alist-get 'title response))) + +(defun mastodon-views--edit-list-at-point () + "Edit list at point." + (interactive) + (let ((id (get-text-property (point) 'list-id))) + (mastodon-views--edit-list id))) + +(defun mastodon-views--edit-list (&optional id) + "Prompt for a list and edit the name and replies policy. +If ID is provided, use that list." + (interactive) + (let* ((list-names (unless id (mastodon-views--get-lists-names))) + (name-old (if id + (get-text-property (point) 'list-name) + (completing-read "Edit list: " + list-names))) + (id (or id (mastodon-views--get-list-id name-old))) + (name-choice (read-string "List name: " name-old)) + (replies-policy (completing-read "Replies policy: " ; give this a proper name + '("followed" "list" "none") + nil t nil nil "list")) + (url (mastodon-http--api (format "lists/%s" id))) + (response (mastodon-http--put url + `(("title" . ,name-choice) + ("replies_policy" . ,replies-policy))))) + (mastodon-http--triage response + (lambda () + (with-current-buffer response + (let* ((json (mastodon-http--process-json)) + (name-new (alist-get 'title json))) + (message "list %s edited to %s!" name-old name-new))) + (when (mastodon-tl--buffer-type-eq 'lists) + (mastodon-views--view-lists)))))) + +(defun mastodon-views--view-timeline-list-at-point () + "View timeline of list at point." + (interactive) + (let ((list-id (get-text-property (point) 'list-id))) + (mastodon-views--view-list-timeline list-id))) + +(defun mastodon-views--view-list-timeline (&optional id) + "Prompt for a list and view its timeline. +If ID is provided, use that list." + (interactive) + (let* ((list-names (unless id (mastodon-views--get-lists-names))) + (list-name (unless id (completing-read "View list: " list-names))) + (id (or id (mastodon-views--get-list-id list-name))) + (endpoint (format "timelines/list/%s" id)) + (name (mastodon-views--get-list-name id)) + (buffer-name (format "list-%s" name))) + (mastodon-tl--init buffer-name endpoint 'mastodon-tl--timeline))) + +(defun mastodon-views--create-list () + "Create a new list. +Prompt for name and replies policy." + (interactive) + (let* ((title (read-string "New list name: ")) + (replies-policy (completing-read "Replies policy: " ; give this a proper name + '("followed" "list" "none") + nil t nil nil "list")) ; default + (response (mastodon-http--post (mastodon-http--api "lists") + `(("title" . ,title) + ("replies_policy" . ,replies-policy)) + nil))) + (mastodon-views--list-action-triage response + (message "list %s created!" title)))) + +(defun mastodon-views--delete-list-at-point () + "Delete list at point." + (interactive) + (let ((id (get-text-property (point) 'list-id))) + (mastodon-views--delete-list id))) + +(defun mastodon-views--delete-list (&optional id) + "Prompt for a list and delete it. +If ID is provided, delete that list." + (interactive) + (let* ((list-names (unless id (mastodon-views--get-lists-names))) + (name (if id + (mastodon-views--get-list-name id) + (completing-read "Delete list: " + list-names))) + (id (or id (mastodon-views--get-list-id name))) + (url (mastodon-http--api (format "lists/%s" id)))) + (when (y-or-n-p (format "Delete list %s?" name)) + (let ((response (mastodon-http--delete url))) + (mastodon-views--list-action-triage response + (message "list %s deleted!" name)))))) + +(defun mastodon-views--get-users-followings () + "Return the list of followers of the logged in account." + (let* ((id (mastodon-auth--get-account-id)) + (url (mastodon-http--api (format "accounts/%s/following" id)))) + (mastodon-http--get-json url '(("limit" . "80"))))) ; max 80 accounts + +(defun mastodon-views--add-account-to-list-at-point () + "Prompt for account and add to list at point." + (interactive) + (let ((id (get-text-property (point) 'list-id))) + (mastodon-views--add-account-to-list id))) + +(defun mastodon-views--add-account-to-list (&optional id account-id handle) + "Prompt for a list and for an account, add account to list. +If ID is provided, use that list. +If ACCOUNT-ID and HANDLE are provided use them rather than prompting." + (interactive) + (let* ((list-prompt (if handle + (format "Add %s to list: " handle) + "Add account to list: ")) + (list-name (if id + (get-text-property (point) 'list-name) + (completing-read list-prompt + (mastodon-views--get-lists-names) nil t))) + (list-id (or id (mastodon-views--get-list-id list-name))) + (followings (mastodon-views--get-users-followings)) + (handles (mapcar (lambda (x) + (cons (alist-get 'acct x) + (alist-get 'id x))) + followings)) + (account (or handle (completing-read "Account to add: " + handles nil t))) + (account-id (or account-id (alist-get account handles nil nil 'equal))) + (url (mastodon-http--api (format "lists/%s/accounts" list-id))) + (response (mastodon-http--post url + `(("account_ids[]" . ,account-id))))) + (mastodon-views--list-action-triage + response + (message "%s added to list %s!" account list-name)))) + +(defun mastodon-views--add-toot-account-at-point-to-list () + "Prompt for a list, and add the account of the toot at point to it." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (account (mastodon-tl--field 'account toot)) + (account-id (mastodon-tl--field 'id account)) + (handle (mastodon-tl--field 'acct account))) + (mastodon-views--add-account-to-list nil account-id handle))) + +(defun mastodon-views--remove-account-from-list-at-point () + "Prompt for account and remove from list at point." + (interactive) + (let ((id (get-text-property (point) 'list-id))) + (mastodon-views--remove-account-from-list id))) + +(defun mastodon-views--remove-account-from-list (&optional id) + "Prompt for a list, select an account and remove from list. +If ID is provided, use that list." + (interactive) + (let* ((list-name (if id + (get-text-property (point) 'list-name) + (completing-read "Remove account from list: " + (mastodon-views--get-lists-names) nil t))) + (list-id (or id (mastodon-views--get-list-id list-name))) + (accounts (mastodon-views--accounts-in-list list-id)) + (handles (mapcar (lambda (x) + (cons (alist-get 'acct x) + (alist-get 'id x))) + accounts)) + (account (completing-read "Account to remove: " + handles nil t)) + (account-id (alist-get account handles nil nil 'equal)) + (url (mastodon-http--api (format "lists/%s/accounts" list-id))) + (args (mastodon-http--build-array-params-alist "account_ids[]" `(,account-id))) + (response (mastodon-http--delete url args))) + (mastodon-views--list-action-triage + response + (message "%s removed from list %s!" account list-name)))) + +(defun mastodon-views--list-action-triage (response message) + "Call `mastodon-http--triage' on RESPONSE and display MESSAGE." + (mastodon-http--triage response + (lambda () + (when (mastodon-tl--buffer-type-eq 'lists) + (mastodon-views--view-lists)) + message))) + +(defun mastodon-views--accounts-in-list (list-id) + "Return the JSON of the accounts in list with LIST-ID." + (let* ((url (mastodon-http--api (format "lists/%s/accounts" list-id)))) + (mastodon-http--get-json url))) + + +;;; FOLLOW REQUESTS + +(defun mastodon-views--insert-follow-requests (json) + "Insert the user's current follow requests. +JSON is the data returned by the server." + (mastodon-views--minor-view + "follow requests" + "a/r - accept/reject request at point\n n/p - go to next/prev request" + #'mastodon-views--insert-users-propertized-note + json)) + +(defun mastodon-views--view-follow-requests () + "Open a new buffer displaying the user's follow requests." + (interactive) + (mastodon-tl--init-sync "follow-requests" + "follow_requests" + 'mastodon-views--insert-follow-requests) + (mastodon-tl--goto-first-item) + (with-current-buffer "*mastodon-follow-requests*" + (use-local-map mastodon-views--view-follow-requests-keymap))) + + +;;; SCHEDULED TOOTS + +(defun mastodon-views--view-scheduled-toots () + "Show the user's scheduled toots in a new buffer." + (interactive) + (mastodon-tl--init-sync "scheduled-toots" + "scheduled_statuses" + 'mastodon-views--insert-scheduled-toots)) + +(defun mastodon-views--insert-scheduled-toots (json) + "Insert the user's scheduled toots, from JSON." + (mastodon-views--minor-view + "your scheduled toots" + "n/p - prev/next\n r - reschedule\n e/RET - edit toot\n c - cancel" + #'mastodon-views--insert-scheduled-toots-list + json)) + +(defun mastodon-views--insert-scheduled-toots-list (scheduleds) + "Insert scheduled toots in SCHEDULEDS." + (mapc #'mastodon-views--insert-scheduled-toot scheduleds)) + +(defun mastodon-views--insert-scheduled-toot (toot) + "Insert scheduled TOOT into the buffer." + (let* ((id (alist-get 'id toot)) + (scheduled (alist-get 'scheduled_at toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params))) + (insert + (propertize (concat text + " | " + (mastodon-toot--iso-to-human scheduled)) + 'byline t ; so we nav here + 'toot-id "0" ; so we nav here + 'face 'font-lock-comment-face + 'keymap mastodon-views--scheduled-map + 'scheduled-json toot + 'id id) + "\n"))) + +(defun mastodon-views--get-scheduled-toots (&optional id) + "Get the user's currently scheduled toots. +If ID, just return that toot." + (let* ((endpoint (if id + (format "scheduled_statuses/%s" id) + "scheduled_statuses")) + (url (mastodon-http--api endpoint))) + (mastodon-http--get-json url))) + +(defun mastodon-views--reschedule-toot () + "Reschedule the scheduled toot at point." + (interactive) + (mastodon-toot--schedule-toot :reschedule)) + +(defun mastodon-views--copy-scheduled-toot-text () + "Copy the text of the scheduled toot at point." + (interactive) + (let* ((toot (get-text-property (point) 'toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params))) + (kill-new text))) + +(defun mastodon-views--cancel-scheduled-toot (&optional id no-confirm) + "Cancel the scheduled toot at point. +ID is that of the scheduled toot to cancel. +NO-CONFIRM means there is no ask or message, there is only do." + (interactive) + (let* ((id (or id (get-text-property (point) 'id))) + (url (mastodon-http--api (format "scheduled_statuses/%s" id)))) + (when (or no-confirm + (y-or-n-p "Cancel scheduled toot?")) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (mastodon-views--view-scheduled-toots) + (unless no-confirm + (message "Toot cancelled!")))))))) + +(defun mastodon-views--edit-scheduled-as-new () + "Edit scheduled status as new toot." + (interactive) + (let* ((toot (get-text-property (point) 'scheduled-json)) + (id (alist-get 'id toot)) + (scheduled (alist-get 'scheduled_at toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params)) + (visibility (alist-get 'visibility params)) + (cw (alist-get 'spoiler_text params)) + (lang (alist-get 'language params)) + ;; (poll (alist-get 'poll params)) + (reply-id (alist-get 'in_reply_to_id params))) + ;; (media (alist-get 'media_attachments toot))) + (mastodon-toot--compose-buffer) + (goto-char (point-max)) + (insert text) + ;; adopt properties from scheduled toot: + (mastodon-toot--set-toot-properties reply-id visibility cw + lang scheduled id))) + + +;;; FILTERS + + + +;;; FILTERS + +(defun mastodon-views--view-filters () + "View the user's filters in a new buffer." + (interactive) + (mastodon-tl--init-sync "filters" + "filters" + 'mastodon-views--insert-filters) + (with-current-buffer "*mastodon-filters*" + (use-local-map mastodon-views--view-filters-keymap))) + +(defun mastodon-views--insert-filters (json) + "Insert the user's current filters. +JSON is what is returned by by the server." + (mastodon-views--minor-view + "current filters" + "c - create filter\n d - delete filter at point\n n/p - go to next/prev filter" + #'mastodon-views--insert-filter-string-set + json)) + +(defun mastodon-views--insert-filter-string-set (json) + "Insert a filter string plus a blank line. +JSON is the filters data." + (mapc (lambda (x) + (mastodon-views--insert-filter-string x) + (insert "\n\n")) + json)) + +(defun mastodon-views--insert-filter-string (filter) + "Insert a single 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-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-views--view-filters-keymap + 'byline t)))) ;for goto-next-filter compat + +(defun mastodon-views--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(s) to filter (%s): " (or (current-word) "")) + nil nil (or (current-word) ""))) + (contexts + (if (string-empty-p 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 + (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)))) + (mastodon-http--triage response + (lambda () + (message "Filter created for %s!" word) + ;; reload if we are in filters view: + (when (mastodon-tl--buffer-type-eq 'filters) + (mastodon-views--view-filters)))))) + +(defun mastodon-views--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-views--view-filters) + (message "Filter for \"%s\" deleted!" phrase))))))) + + +;;; FOLLOW SUGGESTIONS + +(defun mastodon-views--get-follow-suggestions () + "Display a buffer of suggested accounts to follow." + (interactive) + (mastodon-tl--init-sync "follow-suggestions" + "suggestions" + 'mastodon-views--insert-follow-suggestions) + (with-current-buffer "*mastodon-follow-suggestions*" + (use-local-map mastodon-views--follow-suggestions-map))) + +(defun mastodon-views--insert-follow-suggestions (json) + "Insert follow suggestions into buffer. +JSON is the data returned by the server." + (mastodon-views--minor-view + "suggested accounts" + nil + #'mastodon-views--insert-users-propertized-note + json)) + +(defun mastodon-views--insert-users-propertized-note (json) + "Insert users list into the buffer, including profile note. +JSON is the users list data." + (mastodon-search--insert-users-propertized json :note)) + + +;;; INSTANCES + +(defun mastodon-views--view-own-instance (&optional brief) + "View details of your own instance. +BRIEF means show fewer details." + (interactive) + (mastodon-views--view-instance-description :user brief)) + +(defun mastodon-views--view-own-instance-brief () + "View brief details of your own instance." + (interactive) + (mastodon-views--view-instance-description :user :brief)) + +(defun mastodon-views--view-instance-description-brief () + "View brief details of the instance the current post's author is on." + (interactive) + (mastodon-views--view-instance-description nil :brief)) + +(defun mastodon-views--view-instance-description (&optional user brief instance) + "View the details of the instance the current post's author is on. +USER means to show the instance details for the logged in user. +BRIEF means to show fewer details. +INSTANCE is an instance domain name." + (interactive) + (if user + (let ((response (mastodon-http--get-json + (mastodon-http--api "instance") + nil ; params + nil ; silent + :vector))) + (mastodon-views--instance-response-fun response brief instance)) + (mastodon-tl--do-if-toot + (let* ((toot (if (mastodon-tl--profile-buffer-p) + (mastodon-tl--property 'profile-json) ; profile may have 0 toots + (mastodon-tl--property 'toot-json))) + (reblog (alist-get 'reblog toot)) + (account (or (alist-get 'account reblog) + (alist-get 'account toot))) + (url (if (mastodon-tl--profile-buffer-p) + (alist-get 'url toot) ; profile + (alist-get 'url account))) + (username (if (mastodon-tl--profile-buffer-p) + (alist-get 'username toot) ;; profile + (alist-get 'username account))) + (instance (if instance + (concat "https://" instance) + ;; pleroma URL is https://instance.com/users/username + (if (string-suffix-p "users/" (url-basepath url)) + (string-remove-suffix "/users/" + (url-basepath url)) + ;; mastodon: + (string-remove-suffix (concat "/@" username) + url)))) + (response (mastodon-http--get-json + (if user + (mastodon-http--api "instance") + (concat instance "/api/v1/instance")) + nil ; params + nil ; silent + :vector))) + (mastodon-views--instance-response-fun response brief instance))))) + +(defun mastodon-views--instance-response-fun (response brief instance) + "Display instance description RESPONSE in a new buffer. +BRIEF means to show fewer details. +INSTANCE is the instance were are working with." + (when response + (let* ((domain (url-file-nondirectory instance)) + (buf (get-buffer-create + (format "*mastodon-instance-%s*" domain)))) + (with-current-buffer buf + (switch-to-buffer-other-window buf) + (let ((inhibit-read-only t)) + (erase-buffer) + (special-mode) + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) + (mastodon-views--print-json-keys response) + (mastodon-mode) + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) + (goto-char (point-min))))))) + +(defun mastodon-views--format-key (el pad) + "Format a key of element EL, a cons, with PAD padding." + (format (concat "%-" + (number-to-string pad) + "s: ") + (propertize + (prin1-to-string (car el)) + 'face '(:underline t)))) + +(defun mastodon-views--print-json-keys (response &optional ind) + "Print the JSON keys and values in RESPONSE. +IND is the optional indentation level to print at." + (let* ((cars (mapcar + (lambda (x) (symbol-name (car x))) + response)) + (pad (1+ (cl-reduce #'max (mapcar #'length cars))))) + (while response + (let ((el (pop response))) + (cond + ;; vector of alists (fields, instance rules): + ((and (vectorp (cdr el)) + (not (seq-empty-p (cdr el))) + (consp (seq-elt (cdr el) 0))) + (insert + (mastodon-views--format-key el pad) + "\n\n") + (seq-do #'mastodon-views--print-instance-rules-or-fields (cdr el)) + (insert "\n")) + ;; vector of strings (media types): + ((and (vectorp (cdr el)) + (not (seq-empty-p (cdr el))) + (< 1 (seq-length (cdr el))) + (stringp (seq-elt (cdr el) 0))) + (when ind (indent-to ind)) + (insert + (mastodon-views--format-key el pad) + "\n" + (seq-mapcat + (lambda (x) (concat x ", ")) + (cdr el) 'string) + "\n\n")) + ;; basic nesting: + ((consp (cdr el)) + (when ind (indent-to ind)) + (insert + (mastodon-views--format-key el pad) + "\n\n") + (mastodon-views--print-json-keys + (cdr el) (if ind (+ ind 4) 4))) + (t + ;; basic handling of raw booleans: + (let ((val (cond ((equal (cdr el) ':json-false) + "no") + ((equal (cdr el) 't) + "yes") + (t + (cdr el))))) + (when ind (indent-to ind)) + (insert (mastodon-views--format-key el pad) + " " + (mastodon-views--newline-if-long (cdr el)) + ;; only send strings straight to --render-text + ;; this makes hyperlinks work: + (if (not (stringp val)) + (mastodon-tl--render-text + (prin1-to-string val)) + (mastodon-tl--render-text val)) + "\n")))))))) + +(defun mastodon-views--print-instance-rules-or-fields (alist) + "Print ALIST of instance rules or contact account or emoji fields." + (let ((key (cond ((alist-get 'id alist) + 'id) + ((alist-get 'name alist) + 'name) + ((alist-get 'shortcode alist) + 'shortcode))) + (value (cond ((alist-get 'id alist) + 'text) + ((alist-get 'value alist) + 'value) + ((alist-get 'url alist) + 'url)))) + (indent-to 4) + (insert + (format "%-5s: " + (propertize (alist-get key alist) + 'face '(:underline t))) + (mastodon-views--newline-if-long (alist-get value alist)) + (format "%s" (mastodon-tl--render-text + (alist-get value alist))) + "\n"))) + +(defun mastodon-views--newline-if-long (el) + "Return a newline string if the cdr of EL is over 50 characters long." + (let ((rend (if (stringp el) (mastodon-tl--render-text el) el))) + (if (and (sequencep rend) + (< 50 (length rend))) + "\n" + ""))) + +(provide 'mastodon-views) +;;; mastodon-views.el ends here -- cgit v1.2.3 From 7bd869fdb58b95ae5a3d009f7030f8854191581d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 15:16:34 +0100 Subject: fix check for filter on delete-filter --- lisp/mastodon-views.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 1e3dd4a..2a6238b 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -660,7 +660,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (phrase (get-text-property (point) 'phrase)) (url (mastodon-http--api (format "filters/%s" filter-id)))) - (if (equal nil filter-id) + (if (null phrase) (error "No filter at point?") (when (y-or-n-p (format "Delete this filter? "))) (let ((response (mastodon-http--delete url))) -- cgit v1.2.3 From 34f9c78566a8fdb21987843a335c789a1dcfb8c4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 15:24:26 +0100 Subject: add next prev item funs to lists/scheduled maps --- lisp/mastodon-views.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 2a6238b..10a6a8a 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -105,6 +105,8 @@ (defvar mastodon-views--list-name-keymap (let ((map (make-sparse-keymap))) + (define-key map (kbd "n") 'mastodon-tl--goto-next-item) + (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) (define-key map (kbd "") 'mastodon-views--view-timeline-list-at-point) (define-key map (kbd "d") 'mastodon-views--delete-list-at-point) (define-key map (kbd "a") 'mastodon-views--add-account-to-list-at-point) @@ -115,6 +117,8 @@ (defvar mastodon-views--scheduled-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "n") 'mastodon-tl--goto-next-item) + (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) (define-key map (kbd "r") 'mastodon-views--reschedule-toot) (define-key map (kbd "c") 'mastodon-views--cancel-scheduled-toot) (define-key map (kbd "e") 'mastodon-views--edit-scheduled-as-new) -- cgit v1.2.3 From 393f700bc45ae713af48b40fedc422da4d986f57 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 15:24:47 +0100 Subject: use scheduled map on viewing scheduleds --- lisp/mastodon-views.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 10a6a8a..ed68528 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -485,7 +485,9 @@ JSON is the data returned by the server." (interactive) (mastodon-tl--init-sync "scheduled-toots" "scheduled_statuses" - 'mastodon-views--insert-scheduled-toots)) + 'mastodon-views--insert-scheduled-toots) + (with-current-buffer "*mastodon-scheduled-toots*" + (use-local-map mastodon-views--scheduled-map))) (defun mastodon-views--insert-scheduled-toots (json) "Insert the user's scheduled toots, from JSON." -- cgit v1.2.3 From 4a06f0c5c0cc8b70e51d6a816d55dc53fe7edcf8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 15:25:44 +0100 Subject: check for scheduled toot at point before action fix reschedule check fix cancel scheduled toot rejig --- lisp/mastodon-views.el | 67 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index ed68528..45317cf 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -531,7 +531,10 @@ If ID, just return that toot." (defun mastodon-views--reschedule-toot () "Reschedule the scheduled toot at point." (interactive) - (mastodon-toot--schedule-toot :reschedule)) + (let ((id (get-text-property (point) 'id))) + (if (null id) + (message "no scheduled toot at point?") + (mastodon-toot--schedule-toot :reschedule)))) (defun mastodon-views--copy-scheduled-toot-text () "Copy the text of the scheduled toot at point." @@ -546,41 +549,41 @@ If ID, just return that toot." ID is that of the scheduled toot to cancel. NO-CONFIRM means there is no ask or message, there is only do." (interactive) - (let* ((id (or id (get-text-property (point) 'id))) - (url (mastodon-http--api (format "scheduled_statuses/%s" id)))) - (when (or no-confirm - (y-or-n-p "Cancel scheduled toot?")) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response - (lambda () - (mastodon-views--view-scheduled-toots) - (unless no-confirm - (message "Toot cancelled!")))))))) + (let ((id (or id (get-text-property (point) 'id)))) + (if (null id) + (message "no scheduled toot at point?") + (when (or no-confirm + (y-or-n-p "Cancel scheduled toot?")) + (let* ((url (mastodon-http--api (format "scheduled_statuses/%s" id))) + (response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (mastodon-views--view-scheduled-toots) + (unless no-confirm + (message "Toot cancelled!"))))))))) (defun mastodon-views--edit-scheduled-as-new () "Edit scheduled status as new toot." (interactive) - (let* ((toot (get-text-property (point) 'scheduled-json)) - (id (alist-get 'id toot)) - (scheduled (alist-get 'scheduled_at toot)) - (params (alist-get 'params toot)) - (text (alist-get 'text params)) - (visibility (alist-get 'visibility params)) - (cw (alist-get 'spoiler_text params)) - (lang (alist-get 'language params)) - ;; (poll (alist-get 'poll params)) - (reply-id (alist-get 'in_reply_to_id params))) - ;; (media (alist-get 'media_attachments toot))) - (mastodon-toot--compose-buffer) - (goto-char (point-max)) - (insert text) - ;; adopt properties from scheduled toot: - (mastodon-toot--set-toot-properties reply-id visibility cw - lang scheduled id))) - - -;;; FILTERS - + (let ((id (get-text-property (point) 'id))) + (if (null id) + (message "no scheduled toot at point?") + (let* ((toot (get-text-property (point) 'scheduled-json)) + (scheduled (alist-get 'scheduled_at toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params)) + (visibility (alist-get 'visibility params)) + (cw (alist-get 'spoiler_text params)) + (lang (alist-get 'language params)) + ;; (poll (alist-get 'poll params)) + (reply-id (alist-get 'in_reply_to_id params))) + ;; (media (alist-get 'media_attachments toot))) + (mastodon-toot--compose-buffer) + (goto-char (point-max)) + (insert text) + ;; adopt properties from scheduled toot: + (mastodon-toot--set-toot-properties reply-id visibility cw + lang scheduled id))))) ;;; FILTERS -- cgit v1.2.3 From 9b2bacb956e64cc68f3778da27362f353eed9421 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 15:48:11 +0100 Subject: views: comment on keymap inheritace - all maps inherit --- lisp/mastodon-views.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 45317cf..544c362 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -68,6 +68,17 @@ ;;; KEYMAPS +;; copy `mastodon-mode-map' if possible, as then all timeline functions are +;; available. this is helpful because if a minor view is the only buffer left +;; open, calling `mastodon' will switch to it, but then we will be unable to +;; switch to timlines without closing the minor view. + +;; copying the mode map however means we need to avoid/unbind/override any +;; functions that might cause interfere with the minor view. + +;; this is not redundant, as while the buffer -init function calls +;; `mastodon-mode', it gets overridden in some but not all cases. + (defvar mastodon-views--view-filters-keymap (let ((map (copy-keymap mastodon-mode-map))) @@ -116,7 +127,9 @@ "Keymap for when point is on list name.") (defvar mastodon-views--scheduled-map - (let ((map (make-sparse-keymap))) + (let ((map ;(make-sparse-keymap))) + (copy-keymap mastodon-mode-map))) + ;; (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'mastodon-tl--goto-next-item) (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) (define-key map (kbd "r") 'mastodon-views--reschedule-toot) -- cgit v1.2.3 From dc1149ae594f44944d6807001dd2765ff1766d71 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 18:08:28 +0100 Subject: show filter name in y-or-n prompt --- lisp/mastodon-views.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 544c362..e38455b 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -684,7 +684,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (format "filters/%s" filter-id)))) (if (null phrase) (error "No filter at point?") - (when (y-or-n-p (format "Delete this filter? "))) + (when (y-or-n-p (format "Delete filter %s? " phrase))) (let ((response (mastodon-http--delete url))) (mastodon-http--triage response (lambda () (mastodon-views--view-filters) -- cgit v1.2.3 From d6470dd725c0da74345e1ed8bf40822730e0c004 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 21:57:42 +0100 Subject: map-get-accts > map-alist, handle no results for fam folls use tl--map-alist in views.el --- lisp/mastodon-profile.el | 16 ++++++++-------- lisp/mastodon-tl.el | 29 ++++++++++------------------- lisp/mastodon-toot.el | 6 +++--- lisp/mastodon-views.el | 8 ++------ 4 files changed, 23 insertions(+), 36 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 3661615..684b11f 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -70,7 +70,7 @@ (autoload 'mastodon-tl--init "mastodon-tl.el") (autoload 'mastodon-tl--init-sync "mastodon-tl") (autoload 'mastodon-tl--interactive-user-handles-get "mastodon-tl") -(autoload 'mastodon-tl--map-get-accts "mastodon-views") +(autoload 'mastodon-tl--map-alist "mastodon-tl") (autoload 'mastodon-tl--profile-buffer-p "mastodon tl") (autoload 'mastodon-tl--property "mastodon-tl.el") (autoload 'mastodon-tl--render-text "mastodon-tl.el") @@ -827,9 +827,7 @@ These include the author, author of reblogged entries and any user mentioned." 'list (list (alist-get 'acct this-account)) (mastodon-profile--extract-users-handles reblog) - (mapcar (lambda (mention) - (alist-get 'acct mention)) - mentions))))))) + (mastodon-tl--map-alist 'acct mentions))))))) (defun mastodon-profile--lookup-account-in-status (handle status) "Return account for HANDLE using hints in STATUS if possible." @@ -989,10 +987,12 @@ the given account." (url (mastodon-http--api "accounts/familiar_followers")) (json (mastodon-http--get-json url params)) (accounts (alist-get 'accounts (car json))) ; first id result - (handles (mastodon-tl--map-get-accts accounts)) - (choice (completing-read "Show profile of user: " - handles))) - (mastodon-profile--show-user choice))) + (handles (mastodon-tl--map-alist 'acct accounts))) + (if (null handles) + (message "Looks like there are no familiar followers for this account") + (let ((choice (completing-read "Show profile of user: " + handles))) + (mastodon-profile--show-user choice))))) (provide 'mastodon-profile) ;;; mastodon-profile.el ends here diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6e80db3..95af2f1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -489,9 +489,7 @@ image media from the byline." (defun mastodon-tl--get-media-types (toot) "Return a list of the media attachment types of the TOOT at point." (let* ((attachments (mastodon-tl--field 'media_attachments toot))) - (mapcar (lambda (x) - (alist-get 'type x)) - attachments))) + (mastodon-tl--map-alist 'type attachments))) (defun mastodon-tl--get-attachments-for-byline (toot) "Return a list of attachment URLs and types for TOOT. @@ -1124,9 +1122,7 @@ this just means displaying toot client." (voters-count (mastodon-tl--field 'voters_count poll)) (vote-count (mastodon-tl--field 'votes_count poll)) (options (mastodon-tl--field 'options poll)) - (option-titles (mapcar (lambda (x) - (alist-get 'title x)) - options)) + (option-titles (mastodon-tl--map-alist 'title options)) (longest-option (car (sort option-titles (lambda (x y) (> (length x) @@ -1194,9 +1190,7 @@ this just means displaying toot client." (poll (or (alist-get 'poll reblog) (mastodon-tl--field 'poll toot))) (options (mastodon-tl--field 'options poll)) - (options-titles (mapcar (lambda (x) - (alist-get 'title x)) - options)) + (options-titles (mastodon-tl--map-alist 'title options)) (options-number-seq (number-sequence 1 (length options))) (options-numbers (mapcar #'number-to-string options-number-seq)) (options-alist (cl-mapcar 'cons options-numbers options-titles)) @@ -1504,11 +1498,11 @@ timeline." ;;; UTILITIES -;; consider having this return an id / acct alist -(defun mastodon-tl--map-get-accts (alist) - "Return a list of handles from ALIST." +(defun mastodon-tl--map-alist (key alist) + "Return a list of values extracted from ALIST with KEY. +Key is a symbol, as with `alist-get'." (mapcar (lambda (x) - (alist-get 'acct x)) + (alist-get key x)) alist)) (defun mastodon-tl--symbol (name) @@ -1973,9 +1967,8 @@ If TAG provided, follow it." If TAG is provided, unfollow it." (interactive) (let* ((followed-tags-json (unless tag (mastodon-tl--followed-tags))) - (tags (unless tag (mapcar (lambda (x) - (alist-get 'name x)) - followed-tags-json))) + (tags (unless tag + (mastodon-tl--map-alist 'name followed-tags-json))) (tag (or tag (completing-read "Unfollow tag: " tags))) (url (mastodon-http--api (format "tags/%s/unfollow" tag))) @@ -1988,9 +1981,7 @@ If TAG is provided, unfollow it." "List followed tags. View timeline of tag user choses." (interactive) (let* ((followed-tags-json (mastodon-tl--followed-tags)) - (tags (mapcar (lambda (x) - (alist-get 'name x)) - followed-tags-json)) + (tags (mastodon-tl--map-alist 'name followed-tags-json)) (tag (completing-read "Tag: " tags))) (mastodon-tl--get-tag-timeline tag))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1d91f84..df9a22c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -75,7 +75,7 @@ (autoload 'mastodon-tl--find-property-range "mastodon-tl") (autoload 'mastodon-tl--find-property-range "mastodon-tl") (autoload 'mastodon-tl--goto-next-toot "mastodon-tl") -(autoload 'mastodon-tl--map-get-accts "mastodon-views") +(autoload 'mastodon-tl--map-alist "mastodon-tl") (autoload 'mastodon-tl--property "mastodon-tl") (autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") (autoload 'mastodon-tl--render-text "mastodon-tl") @@ -451,7 +451,7 @@ With FAVOURITE, list favouriters, else list boosters." (if (eq (caar json) 'error) (error "%s (Status does not exist or is private)" (alist-get 'error json)) - (let ((handles (mastodon-tl--map-get-accts json)) + (let ((handles (mastodon-tl--map-alist 'acct json)) (type-string (if favourite "Favouriters" "Boosters"))) (if (not handles) (error "Looks like this toot has no %s" type-string) @@ -921,7 +921,7 @@ Federated user: `username@host.co`." (alist-get 'mentions (alist-get 'reblog status)) (alist-get 'mentions status)))) ;; reverse does not work on vectors in 24.5 - (mastodon-tl--map-get-accts (reverse mentions)))) + (mastodon-tl--map-alist 'acct (reverse mentions)))) (defun mastodon-toot--get-bounds (regex) "Get bounds of tag or handle before point using REGEX." diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index e38455b..f92a9aa 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -219,9 +219,7 @@ provides the JSON data." (defun mastodon-views--print-list-set (lists) "Print each account plus a separator for each list in LISTS." (let ((lists-names - (mapcar (lambda (x) - (alist-get 'title x)) - lists))) + (mastodon-tl--map-alist 'title lists))) (mapc (lambda (x) (mastodon-views--print-list-accounts x) (insert (propertize " ------------\n\n" @@ -266,9 +264,7 @@ a: add account to this list, r: remove account from this list" (defun mastodon-views--get-lists-names () "Return a list of the user's lists' names." (let ((lists (mastodon-views--get-users-lists))) - (mapcar (lambda (x) - (alist-get 'title x)) - lists))) + (mastodon-tl--map-alist 'title lists))) (defun mastodon-views--get-list-by-name (name) "Return the list data for list with NAME." -- cgit v1.2.3 From 5d62213b4f8f92cb974c24c4ab0fc373fe806115 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Mar 2023 22:17:45 +0100 Subject: refactor tl--map-alist-to-alist --- lisp/mastodon-profile.el | 11 ++--------- lisp/mastodon-tl.el | 8 ++++++++ lisp/mastodon-views.el | 10 ++-------- 3 files changed, 12 insertions(+), 17 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 684b11f..b77bdac 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -540,10 +540,7 @@ FIELDS means provide a fields vector fetched by other means." (let ((fields (or fields (mastodon-profile--account-field account 'fields)))) (when fields - (mapcar (lambda (el) - (cons (alist-get 'name el) - (alist-get 'value el))) - fields)))) + (mastodon-tl-map-alist-to-alist 'name 'value fields)))) (defun mastodon-profile--fields-insert (fields) "Format and insert field pairs (a.k.a profile metadata) in FIELDS." @@ -891,11 +888,7 @@ Currently limited to 100 handles. If not found, try (url (mastodon-http--api endpoint)) (response (mastodon-http--get-json url `(("limit" . "100")))) - (handles (mapcar (lambda (x) - (cons - (alist-get 'acct x) - (alist-get 'id x))) - response)) + (handles (mastodon-tl-map-alist-to-alist 'acct 'id response)) (choice (completing-read "Remove from followers: " handles)) (id (alist-get choice handles nil nil 'equal))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 95af2f1..91619f1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1505,6 +1505,14 @@ Key is a symbol, as with `alist-get'." (alist-get key x)) alist)) +(defun mastodon-tl-map-alist-to-alist (key1 key2 alist) + "From ALIST, return an alist consisting of (val1 . val2) elements. +Values are accessed by `alist-get', using KEY1 and KEY2." + (mapcar (lambda (x) + (cons (alist-get key1 x) + (alist-get key2 x))) + alist)) + (defun mastodon-tl--symbol (name) "Return the unicode symbol (as a string) corresponding to NAME. If symbol is not displayable, an ASCII equivalent is returned. If diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index f92a9aa..d3865bc 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -398,10 +398,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) (followings (mastodon-views--get-users-followings)) - (handles (mapcar (lambda (x) - (cons (alist-get 'acct x) - (alist-get 'id x))) - followings)) + (handles (mastodon-tl-map-alist-to-alist 'acct 'id followings)) (account (or handle (completing-read "Account to add: " handles nil t))) (account-id (or account-id (alist-get account handles nil nil 'equal))) @@ -437,10 +434,7 @@ If ID is provided, use that list." (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) (accounts (mastodon-views--accounts-in-list list-id)) - (handles (mapcar (lambda (x) - (cons (alist-get 'acct x) - (alist-get 'id x))) - accounts)) + (handles (mastodon-tl-map-alist-to-alist 'acct 'id accounts)) (account (completing-read "Account to remove: " handles nil t)) (account-id (alist-get account handles nil nil 'equal)) -- cgit v1.2.3 From 521c7c2ae40635532ae22b742a7a521761b2ee85 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 19 Mar 2023 12:44:59 +0100 Subject: rename mastodon-tl-map-alist-to-alist to mastodon-tl--map-alist-vals-to-alist --- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-tl.el | 2 +- lisp/mastodon-views.el | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b77bdac..380c82f 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -540,7 +540,7 @@ FIELDS means provide a fields vector fetched by other means." (let ((fields (or fields (mastodon-profile--account-field account 'fields)))) (when fields - (mastodon-tl-map-alist-to-alist 'name 'value fields)))) + (mastodon-tl--map-alist-vals-to-alist 'name 'value fields)))) (defun mastodon-profile--fields-insert (fields) "Format and insert field pairs (a.k.a profile metadata) in FIELDS." @@ -888,7 +888,7 @@ Currently limited to 100 handles. If not found, try (url (mastodon-http--api endpoint)) (response (mastodon-http--get-json url `(("limit" . "100")))) - (handles (mastodon-tl-map-alist-to-alist 'acct 'id response)) + (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id response)) (choice (completing-read "Remove from followers: " handles)) (id (alist-get choice handles nil nil 'equal))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 91619f1..7ec5ec4 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1505,7 +1505,7 @@ Key is a symbol, as with `alist-get'." (alist-get key x)) alist)) -(defun mastodon-tl-map-alist-to-alist (key1 key2 alist) +(defun mastodon-tl--map-alist-vals-to-alist (key1 key2 alist) "From ALIST, return an alist consisting of (val1 . val2) elements. Values are accessed by `alist-get', using KEY1 and KEY2." (mapcar (lambda (x) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index d3865bc..9274f45 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -398,7 +398,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) (followings (mastodon-views--get-users-followings)) - (handles (mastodon-tl-map-alist-to-alist 'acct 'id followings)) + (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id followings)) (account (or handle (completing-read "Account to add: " handles nil t))) (account-id (or account-id (alist-get account handles nil nil 'equal))) @@ -434,7 +434,7 @@ If ID is provided, use that list." (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) (accounts (mastodon-views--accounts-in-list list-id)) - (handles (mastodon-tl-map-alist-to-alist 'acct 'id accounts)) + (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id accounts)) (account (completing-read "Account to remove: " handles nil t)) (account-id (alist-get account handles nil nil 'equal)) -- cgit v1.2.3 From f9c1399ba56a6818255f1ab0664adaa05649ce51 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 20 Mar 2023 20:07:21 +0100 Subject: remove unused code --- lisp/mastodon-notifications.el | 1 - lisp/mastodon-profile.el | 7 +++---- lisp/mastodon-search.el | 2 -- lisp/mastodon-tl.el | 5 ----- lisp/mastodon-views.el | 3 ++- 5 files changed, 5 insertions(+), 13 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bb9637c..22228f2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -46,7 +46,6 @@ (autoload 'mastodon-tl--find-property-range "mastodon-tl") (autoload 'mastodon-tl--has-spoiler "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl") -(autoload 'mastodon-tl--init-sync "mastodon-tl") (autoload 'mastodon-tl--insert-status "mastodon-tl") (autoload 'mastodon-tl--property "mastodon-tl") (autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 380c82f..175af06 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -68,7 +68,6 @@ (autoload 'mastodon-tl--goto-next-toot "mastodon-tl.el") (autoload 'mastodon-tl--goto-prev-item "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl.el") -(autoload 'mastodon-tl--init-sync "mastodon-tl") (autoload 'mastodon-tl--interactive-user-handles-get "mastodon-tl") (autoload 'mastodon-tl--map-alist "mastodon-tl") (autoload 'mastodon-tl--profile-buffer-p "mastodon tl") @@ -84,11 +83,9 @@ (autoload 'mastodon-toot--count-toot-chars "mastodon-toot") (autoload 'mastodon-toot--get-max-toot-chars "mastodon-toot") (autoload 'mastodon-views--add-account-to-list "mastodon-views") +(autoload 'mastodon-tl--map-alist-vals-to-alist "mastodon-tl") -(defvar mastodon-instance-url) -(defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) -(defvar mastodon-mode-map) (defvar mastodon-toot--max-toot-chars) (defvar mastodon-toot--visibility) (defvar mastodon-toot--content-nsfw) @@ -350,6 +347,7 @@ This is done after changing the setting on the server." (setq mastodon-profile-account-settings (plist-put mastodon-profile-account-settings pref val))) +;; used in toot.el (defun mastodon-profile--fetch-server-account-settings-maybe () "Fetch account settings from the server. Only do so if `mastodon-profile-account-settings' is nil." @@ -491,6 +489,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 (defun mastodon-profile--get-preferences-pref (pref) "Fetch PREF from the endpoint \"/preferences\". This endpoint only holds a few preferences. For others, see diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 3f76162..eba7292 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -45,8 +45,6 @@ (defvar mastodon-toot--completion-style-for-mentions) (defvar mastodon-instance-url) (defvar mastodon-tl--link-keymap) -(defvar mastodon-http--timeout) -(defvar mastodon-toot--enable-completion-for-mentions) ;; functions for completion of mentions in mastodon-toot diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index dc538a9..0448fb3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1949,11 +1949,6 @@ ARGS is an alist of any parameters to send with the request." ;; FOLLOW TAGS -(defun mastodon-tl--get-tag-json (tag) - "Return JSON data about TAG." - (let ((url (mastodon-http--api (format "tags/%s" tag)))) - (mastodon-http--get-json url))) - (defun mastodon-tl--follow-tag (&optional tag) "Prompt for a tag and follow it. If TAG provided, follow it." diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 9274f45..54469e1 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -38,7 +38,6 @@ (require 'cl-lib) (require 'mastodon-http) -(defvar mastodon-profile--account) (defvar mastodon-mode-map) (autoload 'mastodon-mode "mastodon") @@ -64,6 +63,8 @@ (autoload 'mastodon-toot--set-toot-properties "mastodon-toot") (autoload 'mastodon-search--propertize-user "mastodon-search") (autoload 'mastodon-search--insert-users-propertized "mastodon-search") +(autoload 'mastodon-tl--map-alist "mastodon-tl") +(autoload 'mastodon-tl--map-alist-vals-to-alist "mastodon-tl") ;;; KEYMAPS -- cgit v1.2.3 From 4c90d4700a18ed9b980805ef637b8f3d31a8add5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 20 Mar 2023 20:30:10 +0100 Subject: factor out a views keymap --- lisp/mastodon-views.el | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 54469e1..e8c5cd0 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -80,13 +80,19 @@ ;; this is not redundant, as while the buffer -init function calls ;; `mastodon-mode', it gets overridden in some but not all cases. -(defvar mastodon-views--view-filters-keymap +(defvar mastodon-views-map (let ((map (copy-keymap mastodon-mode-map))) - (define-key map (kbd "d") 'mastodon-views--delete-filter) - (define-key map (kbd "c") 'mastodon-views--create-filter) (define-key map (kbd "n") 'mastodon-tl--goto-next-item) (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) + (keymap-canonicalize map)) + "Base keymap for minor mastodon views.") + +(defvar mastodon-views--view-filters-keymap + (let ((map + (copy-keymap mastodon-views-map))) + (define-key map (kbd "d") 'mastodon-views--delete-filter) + (define-key map (kbd "c") 'mastodon-views--create-filter) (define-key map (kbd "TAB") 'mastodon-tl--goto-next-item) (define-key map (kbd "g") 'mastodon-views--view-filters) (keymap-canonicalize map)) @@ -94,31 +100,25 @@ (defvar mastodon-views--follow-suggestions-map (let ((map - (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) + (copy-keymap mastodon-views-map))) (define-key map (kbd "g") 'mastodon-views--get-follow-suggestions) (keymap-canonicalize map)) "Keymap for viewing follow suggestions.") (defvar mastodon-views--view-lists-keymap - (let ((map ;(make-sparse-keymap))) - (copy-keymap mastodon-mode-map))) + (let ((map + (copy-keymap mastodon-views-map))) (define-key map (kbd "D") 'mastodon-views--delete-list) (define-key map (kbd "C") 'mastodon-views--create-list) (define-key map (kbd "A") 'mastodon-views--add-account-to-list) (define-key map (kbd "R") 'mastodon-views--remove-account-from-list) (define-key map (kbd "E") 'mastodon-views--edit-list) - (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-views--view-lists) (keymap-canonicalize map)) "Keymap for viewing lists.") (defvar mastodon-views--list-name-keymap (let ((map (make-sparse-keymap))) - (define-key map (kbd "n") 'mastodon-tl--goto-next-item) - (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) (define-key map (kbd "") 'mastodon-views--view-timeline-list-at-point) (define-key map (kbd "d") 'mastodon-views--delete-list-at-point) (define-key map (kbd "a") 'mastodon-views--add-account-to-list-at-point) @@ -129,10 +129,7 @@ (defvar mastodon-views--scheduled-map (let ((map ;(make-sparse-keymap))) - (copy-keymap mastodon-mode-map))) - ;; (let ((map (make-sparse-keymap))) - (define-key map (kbd "n") 'mastodon-tl--goto-next-item) - (define-key map (kbd "p") 'mastodon-tl--goto-prev-item) + (copy-keymap mastodon-views-map))) (define-key map (kbd "r") 'mastodon-views--reschedule-toot) (define-key map (kbd "c") 'mastodon-views--cancel-scheduled-toot) (define-key map (kbd "e") 'mastodon-views--edit-scheduled-as-new) @@ -142,18 +139,13 @@ (defvar mastodon-views--view-follow-requests-keymap (let ((map ;(make-sparse-keymap))) - (copy-keymap mastodon-mode-map))) + (copy-keymap mastodon-views-map))) ;; make reject binding match the binding in notifs view ;; 'r' is then reserved for replying, even tho it is not avail ;; in foll-reqs view (define-key map (kbd "j") #'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-views--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.") -- cgit v1.2.3 From 2ad964bac68adc29ee71f5f9c4d0793f9ac9e6ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 20 Mar 2023 22:00:13 +0100 Subject: rename view-follow-suggestions --- lisp/mastodon-views.el | 4 ++-- lisp/mastodon.el | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index e8c5cd0..5cfbe41 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -101,7 +101,7 @@ (defvar mastodon-views--follow-suggestions-map (let ((map (copy-keymap mastodon-views-map))) - (define-key map (kbd "g") 'mastodon-views--get-follow-suggestions) + (define-key map (kbd "g") 'mastodon-views--view-follow-suggestions) (keymap-canonicalize map)) "Keymap for viewing follow suggestions.") @@ -676,7 +676,7 @@ Prompt for a context, must be a list containting at least one of \"home\", ;;; FOLLOW SUGGESTIONS -(defun mastodon-views--get-follow-suggestions () +(defun mastodon-views--view-follow-suggestions () "Display a buffer of suggested accounts to follow." (interactive) (mastodon-tl--init-sync "follow-suggestions" diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 075aa6a..731aba2 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -89,7 +89,7 @@ (when (require 'lingva nil :no-error) (autoload 'mastodon-toot--translate-toot-text "mastodon-toot")) (autoload 'mastodon-toot--view-toot-history "mastodon-tl") -(autoload 'mastodon-views--get-follow-suggestions "mastodon-views") +(autoload 'mastodon-views--view-follow-suggestions "mastodon-views") (autoload 'mastodon-views--view-filters "mastodon-views") (autoload 'mastodon-views--view-follow-requests "mastodon-views") (autoload 'mastodon-views--view-instance-description "mastodon-views") @@ -197,7 +197,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-profile--view-bookmarks) (define-key map (kbd "I") #'mastodon-views--view-filters) - (define-key map (kbd "G") #'mastodon-views--get-follow-suggestions) + (define-key map (kbd "G") #'mastodon-views--view-follow-suggestions) (define-key map (kbd "X") #'mastodon-views--view-lists) (define-key map (kbd "@") #'mastodon-notifications--get-mentions) (define-key map (kbd "e") #'mastodon-toot--edit-toot-at-point) -- cgit v1.2.3 From d711903e751125875467982a8ba843a75f45eedc Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 21 Mar 2023 10:45:05 +0100 Subject: use tl--property 'prop :no-move. FIX #416 --- lisp/mastodon-profile.el | 6 +++--- lisp/mastodon-tl.el | 33 +++++++++++++++++---------------- lisp/mastodon-toot.el | 13 ++++++------- lisp/mastodon-views.el | 30 +++++++++++++++--------------- lisp/mastodon.el | 2 +- 5 files changed, 42 insertions(+), 42 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index e00a028..a252abc 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -714,7 +714,7 @@ IMG-TYPE is the JSON key from the account data." (interactive (list (if (and (not (mastodon-tl--profile-buffer-p)) - (not (get-text-property (point) 'toot-json))) + (not (mastodon-tl--property 'toot-json :no-move))) (message "Looks like there's no toot or user at point?") (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) @@ -725,7 +725,7 @@ IMG-TYPE is the JSON key from the account data." (if (not (or ;; own profile has no need for toot-json test: (equal user-handle (mastodon-auth--get-account-name)) - (get-text-property (point) 'toot-json))) + (mastodon-tl--property 'toot-json :no-move))) (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)))) @@ -839,7 +839,7 @@ These include the author, author of reblogged entries and any user mentioned." "Remove a user from your followers. Optionally provide the ID of the account to remove." (interactive) - (let* ((account (unless id (get-text-property (point) 'toot-json))) + (let* ((account (unless id (mastodon-tl--property 'toot-json :no-move))) (id (or id (alist-get 'id account))) (handle (if account (alist-get 'acct account) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d62b798..8588ebd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -67,6 +67,7 @@ (autoload 'mastodon-profile--lookup-account-in-status "mastodon-profile") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--my-profile "mastodon-profile") +(autoload 'mastodon-profile--profile-json "mastodon-profile") (autoload 'mastodon-profile--search-account-by-handle "mastodon-profile") (autoload 'mastodon-profile--toot-json "mastodon-profile") (autoload 'mastodon-profile--view-author-profile "mastodon-profile") @@ -268,7 +269,7 @@ This also skips tab items in invisible text, i.e. hidden spoiler text." (if (null next-range) (message "Nothing else here.") (goto-char (car next-range)) - (message "%s" (get-text-property (point) 'help-echo))))) + (message "%s" (mastodon-tl--property 'help-echo :no-move))))) (defun mastodon-tl--previous-tab-item () "Move to the previous interesting item. @@ -288,7 +289,7 @@ text, i.e. hidden spoiler text." (if (null next-range) (message "Nothing else before this.") (goto-char (car next-range)) - (message "%s" (get-text-property (point) 'help-echo))))) + (message "%s" (mastodon-tl--property 'help-echo :no-move))))) (defun mastodon-tl--goto-toot-pos (find-pos refresh &optional pos) "Search for toot with FIND-POS. @@ -395,12 +396,12 @@ Optionally load TAG timeline directly." Do so if type of status at poins is not follow_request/follow." (let ((type (alist-get 'type - (get-text-property (point) 'toot-json))) - (echo (get-text-property (point) 'help-echo))) + (mastodon-tl--property 'toot-json :no-move))) + (echo (mastodon-tl--property 'help-echo :no-move))) (when echo ; not for followers/following in profile (unless (or (string= type "follow_request") (string= type "follow")) ; no counts for these - (message "%s" (get-text-property (point) 'help-echo)))))) + (message "%s" (mastodon-tl--property 'help-echo :no-move)))))) (defun mastodon-tl--byline-author (toot &optional avatar) "Propertize author of TOOT. @@ -1256,11 +1257,11 @@ in which case play first video or gif from current toot." ;; point in byline: url ;; point in toot: - (get-text-property (point) 'image-url))) + (mastodon-tl--property 'image-url :no-move))) (type (or ;; in byline: type ;; point in toot: - (mastodon-tl--property 'mastodon-media-type)))) + (mastodon-tl--property 'mastodon-media-type :no-move)))) (if url (if (or (equal type "gifv") (equal type "video")) @@ -1541,7 +1542,8 @@ Return value from boosted content if available." (defun mastodon-tl--property (prop &optional no-move backward) "Get property PROP for toot at point. -Move forward (down) the timeline unless BACKWARD is non-nil." +Move forward (down) the timeline unless NO-MOVE is non-nil. +BACKWARD means move backward (up) the timeline." (if no-move (get-text-property (point) prop) (or (get-text-property (point) prop) @@ -1856,14 +1858,13 @@ LANGS is the accumulated array param alist if we re-run recursively." ;; fetch 'toot-json: (mastodon-tl--buffer-type-eq 'profile-followers) (mastodon-tl--buffer-type-eq 'profile-following)) - (list (alist-get 'acct (get-text-property (point) 'toot-json)))) - ;; profile view, no toots, point on profile note, ie. 'profile-json: + (list (alist-get 'acct + (mastodon-tl--property 'toot-json :no-move)))) + ;; profile view, no toots ;; needed for e.g. gup.pe groups which show no toots publically: - ((and (mastodon-tl--profile-buffer-p) - (get-text-property (point) 'profile-json)) - (list (alist-get 'acct (get-text-property (point) 'profile-json)))) - ;; avoid tl--property here because it calls next-toot - ;; which breaks non-toot buffers like foll reqs etc.: + ((mastodon-tl--profile-buffer-p) + (list (alist-get 'acct + (mastodon-profile--profile-json)))) (t (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))))) @@ -1905,7 +1906,7 @@ LANGS is an array parameters alist of languages to filer user's posts by." ;; if profile view, use 'profile-json as status: (if (mastodon-tl--profile-buffer-p) (mastodon-profile--lookup-account-in-status - user-handle (get-text-property (point) 'profile-json)) + user-handle (mastodon-profile--profile-json)) ;; if muting/blocking, we select from handles in current status (mastodon-profile--lookup-account-in-status user-handle (mastodon-profile--toot-json))))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 0a3b602..a487932 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -295,7 +295,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (let ((inhibit-read-only t) (bol (car byline-region)) (eol (cdr byline-region)) - (at-byline-p (eq (get-text-property (point) 'byline) t))) + (at-byline-p (eq (mastodon-tl--property 'byline :no-move) t))) (save-excursion (when remove (goto-char bol) @@ -1008,10 +1008,9 @@ Customize `mastodon-toot-display-orig-in-reply-buffer' to display text of the toot being replied to in the compose buffer." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - ;; NB: we cannot use mastodon-tl--property for 'base-toot - ;; because if it doesn't have one, it is fetched from next toot! - ;; we also cannot use --field because we need to get a different property first - (base-toot (get-text-property (point) 'base-toot)) ; for new notifs handling + ;; no-move arg for base toot, because if it doesn't have one, it is + ;; fetched from next toot! + (base-toot (mastodon-tl--property 'base-toot :no-move)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id (or base-toot toot)))) (account (mastodon-tl--field 'account toot)) (user (alist-get 'acct account)) @@ -1238,10 +1237,10 @@ With RESCHEDULE, reschedule the scheduled toot at point without editing." (mastodon-tl--buffer-type-eq 'scheduled-statuses))) (message "You can only schedule toots from the compose toot buffer or the scheduled toots view.")) (t - (let* ((id (when reschedule (get-text-property (point) 'id))) + (let* ((id (when reschedule (mastodon-tl--property 'id :no-move))) (ts (when reschedule (alist-get 'scheduled_at - (get-text-property (point) 'scheduled-json)))) + (mastodon-tl--property 'scheduled-json :no-move)))) (time-value (org-read-date t t nil "Schedule toot:" ;; default to scheduled timestamp if already set: diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 5cfbe41..762efa9 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -280,7 +280,7 @@ a: add account to this list, r: remove account from this list" (defun mastodon-views--edit-list-at-point () "Edit list at point." (interactive) - (let ((id (get-text-property (point) 'list-id))) + (let ((id (mastodon-tl--property 'list-id :no-move))) (mastodon-views--edit-list id))) (defun mastodon-views--edit-list (&optional id) @@ -289,7 +289,7 @@ If ID is provided, use that list." (interactive) (let* ((list-names (unless id (mastodon-views--get-lists-names))) (name-old (if id - (get-text-property (point) 'list-name) + (mastodon-tl--property 'list-name :no-move) (completing-read "Edit list: " list-names))) (id (or id (mastodon-views--get-list-id name-old))) @@ -313,7 +313,7 @@ If ID is provided, use that list." (defun mastodon-views--view-timeline-list-at-point () "View timeline of list at point." (interactive) - (let ((list-id (get-text-property (point) 'list-id))) + (let ((list-id (mastodon-tl--property 'list-id :no-move))) (mastodon-views--view-list-timeline list-id))) (defun mastodon-views--view-list-timeline (&optional id) @@ -346,7 +346,7 @@ Prompt for name and replies policy." (defun mastodon-views--delete-list-at-point () "Delete list at point." (interactive) - (let ((id (get-text-property (point) 'list-id))) + (let ((id (mastodon-tl--property 'list-id :no-move))) (mastodon-views--delete-list id))) (defun mastodon-views--delete-list (&optional id) @@ -374,7 +374,7 @@ If ID is provided, delete that list." (defun mastodon-views--add-account-to-list-at-point () "Prompt for account and add to list at point." (interactive) - (let ((id (get-text-property (point) 'list-id))) + (let ((id (mastodon-tl--property 'list-id :no-move))) (mastodon-views--add-account-to-list id))) (defun mastodon-views--add-account-to-list (&optional id account-id handle) @@ -386,7 +386,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (format "Add %s to list: " handle) "Add account to list: ")) (list-name (if id - (get-text-property (point) 'list-name) + (mastodon-tl--property 'list-name :no-move) (completing-read list-prompt (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) @@ -414,7 +414,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (defun mastodon-views--remove-account-from-list-at-point () "Prompt for account and remove from list at point." (interactive) - (let ((id (get-text-property (point) 'list-id))) + (let ((id (mastodon-tl--property 'list-id :no-move))) (mastodon-views--remove-account-from-list id))) (defun mastodon-views--remove-account-from-list (&optional id) @@ -422,7 +422,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." If ID is provided, use that list." (interactive) (let* ((list-name (if id - (get-text-property (point) 'list-name) + (mastodon-tl--property 'list-name :no-move) (completing-read "Remove account from list: " (mastodon-views--get-lists-names) nil t))) (list-id (or id (mastodon-views--get-list-id list-name))) @@ -527,7 +527,7 @@ If ID, just return that toot." (defun mastodon-views--reschedule-toot () "Reschedule the scheduled toot at point." (interactive) - (let ((id (get-text-property (point) 'id))) + (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) (message "no scheduled toot at point?") (mastodon-toot--schedule-toot :reschedule)))) @@ -535,7 +535,7 @@ If ID, just return that toot." (defun mastodon-views--copy-scheduled-toot-text () "Copy the text of the scheduled toot at point." (interactive) - (let* ((toot (get-text-property (point) 'toot)) + (let* ((toot (mastodon-tl--property 'toot :no-move)) (params (alist-get 'params toot)) (text (alist-get 'text params))) (kill-new text))) @@ -545,7 +545,7 @@ If ID, just return that toot." ID is that of the scheduled toot to cancel. NO-CONFIRM means there is no ask or message, there is only do." (interactive) - (let ((id (or id (get-text-property (point) 'id)))) + (let ((id (or id (mastodon-tl--property 'id :no-move)))) (if (null id) (message "no scheduled toot at point?") (when (or no-confirm @@ -561,10 +561,10 @@ NO-CONFIRM means there is no ask or message, there is only do." (defun mastodon-views--edit-scheduled-as-new () "Edit scheduled status as new toot." (interactive) - (let ((id (get-text-property (point) 'id))) + (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) (message "no scheduled toot at point?") - (let* ((toot (get-text-property (point) 'scheduled-json)) + (let* ((toot (mastodon-tl--property 'scheduled-json :no-move)) (scheduled (alist-get 'scheduled_at toot)) (params (alist-get 'params toot)) (text (alist-get 'text params)) @@ -661,8 +661,8 @@ Prompt for a context, must be a list containting at least one of \"home\", (defun mastodon-views--delete-filter () "Delete filter at point." (interactive) - (let* ((filter-id (get-text-property (point) 'toot-id)) - (phrase (get-text-property (point) 'phrase)) + (let* ((filter-id (mastodon-tl--property 'toot-id :no-move)) + (phrase (mastodon-tl--property 'phrase :no-move)) (url (mastodon-http--api (format "filters/%s" filter-id)))) (if (null phrase) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index d54380d..8875419 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -309,7 +309,7 @@ not, just browse the URL in the normal fashion." (interactive) (let* ((query (or query-url (thing-at-point-url-at-point) - (get-text-property (point) 'shr-url) + (mastodon-tl--property 'shr-url :no-move) (read-string "Lookup URL: ")))) (if (not (mastodon--masto-url-p query)) ;; this doesn't work as shr-browse-url doesn't take a url arg -- cgit v1.2.3 From fdeeb396c7c2c9a6618661e2ea5d24b999a0e42f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 21 Mar 2023 14:50:55 +0100 Subject: manually(!) apply stephan monnier's patch, save the ts work thanks stephan! --- lisp/mastodon-async.el | 9 ++--- lisp/mastodon-http.el | 2 +- lisp/mastodon-media.el | 7 ++-- lisp/mastodon-profile.el | 8 ++--- lisp/mastodon-search.el | 4 +-- lisp/mastodon-tl.el | 78 ++++++++++++++++++++---------------------- lisp/mastodon-toot.el | 42 +++++++++-------------- lisp/mastodon-views.el | 82 ++++++++++++++++++++++----------------------- lisp/mastodon.el | 3 -- test/mastodon-auth-tests.el | 4 ++- 10 files changed, 111 insertions(+), 128 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 364c5db..9de69db 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -1,4 +1,4 @@ -;;; mastodon-async.el --- async streaming functions for mastodon.el -*- lexical-binding: t -*- +;;; mastodon-async.el --- Async streaming functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017 Alex J. Griffith ;; Author: Alex J. Griffith @@ -30,6 +30,7 @@ ;;; Code: +(require 'mastodon-tl) (require 'json) (require 'url-http) @@ -227,9 +228,9 @@ ENDPOINT is the endpoint for the stream and timeline." (mastodon-mode) (mastodon-tl--set-buffer-spec buffer-name endpoint - ,(if (equal name "notifications") - 'mastodon-notifications--timeline - 'mastodon-tl--timeline)) + (if (equal name "notifications") + 'mastodon-notifications--timeline + 'mastodon-tl--timeline)) (setq-local mastodon-tl--enable-relative-timestamps nil) (setq-local mastodon-tl--display-media-p t) (current-buffer)))) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index d1f654e..3632a11 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -317,7 +317,7 @@ PARAMS is an alist of any extra parameters to send with the request." (when status ;; only when we actually get sth? (apply callback (mastodon-http--process-json) cbargs))))) -(defun mastodon-http--post-async (url params headers &optional callback &rest cbargs) +(defun mastodon-http--post-async (url params _headers &optional callback &rest cbargs) "POST asynchronously to URL with PARAMS and HEADERS. Then run function CALLBACK with arguements CBARGS. Authorization header is included by default unless UNAUTHENTICED-P is non-nil." diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 3fb10b0..63860bd 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -50,17 +50,14 @@ (defcustom mastodon-media--avatar-height 20 "Height of the user avatar images (if shown)." - :group 'mastodon-media :type 'integer) (defcustom mastodon-media--preview-max-height 250 "Max height of any media attachment preview to be shown in timelines." - :group 'mastodon-media :type 'integer) (defcustom mastodon-media--enable-image-caching nil "Whether images should be cached." - :group 'mastodon-media :type 'boolean) (defvar mastodon-media--generic-avatar-data @@ -139,7 +136,7 @@ CAQgEIBAAAIBFiNOFMaY6V1tnFhkDQIQCEAgAIEABAKAQAACAQgEIBCAQAACAQgEIBCAQABIXO4e c1y+zhoEIBCAQAAQCEAgAIEABAIQCEAgAIEABAIQCEAgAAgEIBCAQAACAQgEIBCAQAACAQgEAIEA BAIQCEAgAIEABAIsJVH58WqHw8FIgjUIQCAACAQgEIBAAAIBCAQgEIBAAAIBCAQgEAAEAhAIQCBA fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=") - "The PNG data for a generic 200x200 'broken image' view.") + "The PNG data for a generic 200x200 \"broken image\" view.") (defun mastodon-media--process-image-response (status-plist marker image-options region-length url) @@ -185,7 +182,7 @@ with the image." (defun mastodon-media--load-image-from-url (url media-type start region-length) "Take a URL and MEDIA-TYPE and load the image asynchronously. -MEDIA-TYPE is a symbol and either 'avatar or 'media-link. +MEDIA-TYPE is a symbol and either `avatar' or `media-link.' START is the position where we start loading the image. REGION-LENGTH is the range from start to propertize." (let ((image-options (when (or (image-type-available-p 'imagemagick) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index a252abc..6c58e52 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -258,7 +258,7 @@ NO-REBLOGS means do not display boosts in statuses." 'display nil) "/500 characters") 'read-only t - 'face 'font-lock-comment-face + 'face font-lock-comment-face 'note-header t) "\n") (make-local-variable 'after-change-functions) @@ -317,7 +317,7 @@ Ask for confirmation if length > 500 characters." (defun mastodon-profile--update-preference (pref val &optional source) "Update account PREF erence to setting VAL. Both args are strings. -SOURCE means that the preference is in the 'source' part of the account JSON." +SOURCE means that the preference is in the `source' part of the account JSON." (let* ((url (mastodon-http--api "accounts/update_credentials")) (pref-formatted (if source (concat "source[" pref "]") pref)) (response (mastodon-http--patch url `((,pref-formatted . ,val))))) @@ -744,7 +744,7 @@ IMG-TYPE is the JSON key from the account data." (defun mastodon-profile--account-field (account field) "Return FIELD from the ACCOUNT. -FIELD is used to identify regions under 'account" +FIELD is used to identify regions under `account'." (cdr (assoc field account))) (defun mastodon-profile--add-author-bylines (tootv) @@ -806,7 +806,7 @@ These include the author, author of reblogged entries and any user mentioned." (reblog (or (alist-get 'reblog (alist-get 'status status)) (alist-get 'reblog status)))) (seq-filter - 'stringp + #'stringp (seq-uniq (seq-concatenate 'list diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 80a26ff..b5900c7 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -121,7 +121,7 @@ QUERY is the string to search." tags)) ;; (status-list (mapcar #'mastodon-search--get-status-info ;; statuses)) - (status-ids-list (mapcar 'mastodon-search--get-id-from-status + (status-ids-list (mapcar #'mastodon-search--get-id-from-status statuses)) (toots-list-json (mapcar #'mastodon-search--fetch-full-status-from-id status-ids-list))) @@ -153,7 +153,7 @@ QUERY is the string to search." " STATUSES\n" " ------------\n") 'success)) - (mapc 'mastodon-tl--toot toots-list-json) + (mapc #'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) (defun mastodon-search--insert-users-propertized (json &optional note) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a9e2353..49ddd94 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -64,6 +64,7 @@ (autoload 'mastodon-profile--account-from-id "mastodon-profile") (autoload 'mastodon-profile--extract-users-handles "mastodon-profile") (autoload 'mastodon-profile--get-preferences-pref "mastodon-profile") +(autoload 'mastodon-profile--get-toot-author "mastodon-profile") (autoload 'mastodon-profile--lookup-account-in-status "mastodon-profile") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--my-profile "mastodon-profile") @@ -107,13 +108,11 @@ "Whether to show relative (to the current time) timestamps. This will require periodic updates of a timeline buffer to keep the timestamps current as time progresses." - :group 'mastodon-tl :type '(boolean :tag "Enable relative timestamps and background updater task")) (defcustom mastodon-tl--enable-proportional-fonts nil "Nonnil to enable using proportional fonts when rendering HTML. By default fixed width fonts are used." - :group 'mastodon-tl :type '(boolean :tag "Enable using proportional rather than fixed \ width fonts when rendering HTML text")) @@ -121,18 +120,15 @@ width fonts when rendering HTML text")) "Display an image's caption rather than URL. Only has an effect when `mastodon-tl--display-media-p' is set to nil." - :group 'mastodon-tl :type 'boolean) (defcustom mastodon-tl--show-avatars nil "Whether to enable display of user avatars in timelines." - :group 'mastodon-tl :type '(boolean :tag "Whether to display user avatars in timelines")) (defcustom mastodon-tl--show-stats t "Whether to show toot stats (faves, boosts, replies counts)." - :type 'bool - :group 'mastodon-tl) + :type 'bool) (defcustom mastodon-tl--symbols '((reply . ("💬" . "R")) @@ -148,8 +144,7 @@ nil." "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." - :type '(alist :key-type symbol :value-type string) - :group 'mastodon-tl) + :type '(alist :key-type symbol :value-type string)) (defcustom mastodon-tl-position-after-update nil "Defines where `point' should be located after a timeline update. @@ -170,7 +165,6 @@ Must be an integer between 20 and 40 inclusive." "Whether to hide replies from the timelines. Note that you can hide replies on a one-off basis by loading a timeline with a simple prefix argument, `C-u'." - :group 'mastodon-tl :type '(boolean :tag "Whether to hide replies from the timelines.")) @@ -203,44 +197,46 @@ If nil `(point-min)' is used instead.") (define-key map [return] 'mastodon-tl--do-link-action-at-point) (define-key map [mouse-2] 'mastodon-tl--do-link-action) (define-key map [follow-link] 'mouse-face) - (keymap-canonicalize map)) + map) "The keymap for link-like things in buffer (except for shr.el generate links). This will make the region of text act like like a link with mouse highlighting, mouse click action tabbing to next/previous link etc.") (defvar mastodon-tl--shr-map-replacement - (let ((map (copy-keymap shr-map))) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map shr-map) ;; Replace the move to next/previous link bindings with our ;; version that knows about more types of links. - (define-key map [remap shr-next-link] 'mastodon-tl--next-tab-item) - (define-key map [remap shr-previous-link] 'mastodon-tl--previous-tab-item) + (define-key map [remap shr-next-link] #'mastodon-tl--next-tab-item) + (define-key map [remap shr-previous-link] #'mastodon-tl--previous-tab-item) ;; keep new my-profile binding; shr 'O' doesn't work here anyway - (define-key map (kbd "O") 'mastodon-profile--my-profile) - (define-key map [remap shr-browse-url] 'mastodon-url-lookup) - (keymap-canonicalize map)) + (define-key map (kbd "O") #'mastodon-profile--my-profile) + (define-key map [remap shr-browse-url] #'mastodon-url-lookup) + map) "The keymap to be set for shr.el generated links that are not images. 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--shr-image-map-replacement - (let ((map (copy-keymap (if (boundp 'shr-image-map) - shr-image-map - shr-map)))) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map (if (boundp 'shr-image-map) + shr-image-map + shr-map)) ;; Replace the move to next/previous link bindings with our ;; version that knows about more types of links. - (define-key map [remap shr-next-link] 'mastodon-tl--next-tab-item) - (define-key map [remap shr-previous-link] 'mastodon-tl--previous-tab-item) + (define-key map [remap shr-next-link] #'mastodon-tl--next-tab-item) + (define-key map [remap shr-previous-link] #'mastodon-tl--previous-tab-item) ;; browse-url loads the preview only, we want browse-image ;; on RET to browse full sized image URL - (define-key map [remap shr-browse-url] 'shr-browse-image) + (define-key map [remap shr-browse-url] #'shr-browse-image) ;; remove shr's u binding, as it the maybe-probe-and-copy-url ;; is already bound to w also - (define-key map (kbd "u") 'mastodon-tl--update) + (define-key map (kbd "u") #'mastodon-tl--update) ;; keep new my-profile binding; shr 'O' doesn't work here anyway - (define-key map (kbd "O") 'mastodon-profile--my-profile) - (define-key map (kbd "") 'mastodon-tl--mpv-play-video-at-point) - (keymap-canonicalize map)) + (define-key map (kbd "O") #'mastodon-profile--my-profile) + (define-key map (kbd "") #'mastodon-tl--mpv-play-video-at-point) + map) "The keymap to be set for shr.el generated image links. We need to override the keymap so tabbing will navigate to all types of mastodon links and not just shr.el-generated ones.") @@ -248,9 +244,9 @@ types of mastodon links and not just shr.el-generated ones.") (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) - (define-key map (kbd "") 'mastodon-profile--get-toot-author) - (keymap-canonicalize map))) + (define-key map (kbd "") #'mastodon-tl--mpv-play-video-from-byline) + (define-key map (kbd "RET") #'mastodon-profile--get-toot-author) + map)) "The keymap to be set for the author byline. It is active where point is placed by `mastodon-tl--goto-next-toot.'") @@ -397,7 +393,7 @@ Optionally load TAG timeline directly." ;;; BYLINES, etc. (defun mastodon-tl--message-help-echo () - "Call message on 'help-echo property at point. + "Call message on `help-echo' property at point. Do so if type of status at poins is not follow_request/follow." (let ((type (alist-get 'type @@ -626,7 +622,7 @@ this just means displaying toot client." (propertize (format-time-string mastodon-toot-timestamp-format edited-parsed) - 'face 'font-lock-comment-face + 'face font-lock-comment-face 'timestamp edited-parsed 'display (if mastodon-tl--enable-relative-timestamps (mastodon-tl--relative-time-description edited-parsed) @@ -870,7 +866,7 @@ LINK-TYPE is the type of link to produce." (defun mastodon-tl--do-link-action-at-point (position) "Do the action of the link at POSITION. -Used for hitting on a given link." +Used for hitting RET on a given link." (interactive "d") (let ((link-type (get-text-property position 'mastodon-tab-stop))) (cond ((eq link-type 'content-warning) @@ -1149,18 +1145,18 @@ To disable showing the stats, customize 'favourited-p favourited 'favourites-field t 'favourites-count favourites-count - 'face 'font-lock-comment-face) - (propertize " | " 'face 'font-lock-comment-face) + 'face font-lock-comment-face) + (propertize " | " 'face font-lock-comment-face) (propertize boosts 'boosted-p boosted 'boosts-field t 'boosts-count boosts-count - 'face 'font-lock-comment-face) - (propertize " | " 'face 'font-lock-comment-face) + 'face font-lock-comment-face) + (propertize " | " 'face font-lock-comment-face) (propertize replies 'replies-field t 'replies-count replies-count - 'face 'font-lock-comment-face))) + 'face font-lock-comment-face))) (status (concat (propertize " " 'display `(space :align-to (- right ,(+ (length status) 7)))) status))) @@ -1249,7 +1245,7 @@ To disable showing the stats, customize (options-titles (mastodon-tl--map-alist 'title options)) (options-number-seq (number-sequence 1 (length options))) (options-numbers (mapcar #'number-to-string options-number-seq)) - (options-alist (cl-mapcar 'cons options-numbers options-titles)) + (options-alist (cl-mapcar #'cons options-numbers options-titles)) ;; we display both option number and the option title ;; but also store both as cons cell as cdr, as we need it below (candidates (mapcar (lambda (cell) @@ -1335,7 +1331,7 @@ in which case play first video or gif from current toot." (not (mastodon-tl--field 'rebloged toot)))) (defun mastodon-tl--toot (toot &optional detailed-p) - "Formats TOOT and inserts it into the buffer. + "Format TOOT and insert it into the buffer. DETAILED-P means display more detailed info. For now this just means displaying toot client." (mastodon-tl--insert-status @@ -1353,7 +1349,7 @@ this just means displaying toot client." (defun mastodon-tl--timeline (toots) "Display each toot in TOOTS. This function removes replies if user required." - (mapc 'mastodon-tl--toot + (mapc #'mastodon-tl--toot ;; hack to *not* filter replies on profiles: (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) toots @@ -2051,7 +2047,7 @@ the current view." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) (args (if params (push (car args) params) args)) (url (mastodon-http--api endpoint))) - (apply 'mastodon-http--get-json-async url args callback cbargs))) + (apply #'mastodon-http--get-json-async url args callback cbargs))) ;; TODO ;; Look into the JSON returned here by Local diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a487932..c6f87d3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -33,11 +33,11 @@ ;;; Code: (eval-when-compile (require 'subr-x)) -(when (require 'emojify nil :noerror) - (declare-function emojify-insert-emoji "emojify") - (declare-function emojify-set-emoji-data "emojify") - (defvar emojify-emojis-dir) - (defvar emojify-user-emojis)) +(require 'emojify nil :noerror) +(declare-function emojify-insert-emoji "emojify") +(declare-function emojify-set-emoji-data "emojify") +(defvar emojify-emojis-dir) +(defvar emojify-user-emojis) (require 'cl-lib) (require 'persist) @@ -99,18 +99,15 @@ (defcustom mastodon-toot--default-media-directory "~/" "The default directory when prompting for a media file to upload." - :group 'mastodon-toot :type 'string) (defcustom mastodon-toot--attachment-height 80 "Height of the attached images preview in the toot draft buffer." - :group 'mastodon-toot :type 'integer) (defcustom mastodon-toot--enable-completion t "Whether to enable completion of mentions and hashtags. Used for completion in toot compose buffer." - :group 'mastodon-toot :type 'boolean) (defcustom mastodon-toot--use-company-for-completion nil @@ -120,12 +117,10 @@ buffer, and mastodon completion backends are added to `company-capf'. You need to install company yourself to use this." - :group 'mastodon-toot :type 'boolean) (defcustom mastodon-toot--completion-style-for-mentions "all" "The company completion style to use for mentions." - :group 'mastodon-toot :type '(choice (const :tag "off" nil) (const :tag "following only" "following") @@ -133,27 +128,23 @@ You need to install company yourself to use this." (defcustom mastodon-toot-display-orig-in-reply-buffer nil "Display a copy of the toot replied to in the compose buffer." - :group 'mastodon-toot :type 'boolean) (defcustom mastodon-toot-orig-in-reply-length 160 "Length to crop toot replied to in the compose buffer to." - :group 'mastodon-toot :type 'integer) (defcustom mastodon-toot--default-reply-visibility "public" "Default visibility settings when replying. If the original toot visibility is different we use the more restricted one." - :group 'mastodon-toot :type '(choice - (const :tag "public" "public") - (const :tag "unlisted" "unlisted") - (const :tag "followers only" "private") - (const :tag "direct" "direct"))) + (const :tag "public" "public") + (const :tag "unlisted" "unlisted") + (const :tag "followers only" "private") + (const :tag "direct" "direct"))) (defcustom mastodon-toot--enable-custom-instance-emoji nil "Whether to enable your instance's custom emoji by default." - :group 'mastodon-toot :type 'boolean) (defvar-local mastodon-toot--content-warning nil @@ -288,7 +279,7 @@ NO-TOOT means we are not calling from a toot buffer." (mastodon-toot--update-status-fields))))) (defun mastodon-toot--action-success (marker byline-region remove) - "Insert/remove the text MARKER with 'success face in byline. + "Insert/remove the text MARKER with `success' face in byline. BYLINE-REGION is a cons of start and end pos of the byline to be modified. Remove MARKER if REMOVE is non-nil, otherwise add it." @@ -330,7 +321,7 @@ boosting, or bookmarking toots." (defun mastodon-toot--toggle-boost-or-favourite (type) "Toggle boost or favourite of toot at `point'. -TYPE is a symbol, either 'favourite or 'boost." +TYPE is a symbol, either `favourite' or `boost.'" (interactive) (let* ((boost-p (equal type 'boost)) (has-id (mastodon-tl--property 'base-toot-id)) @@ -861,7 +852,7 @@ instance to edit a toot." (insert (propertize (if (= count 1) (format "%s [original]:\n" count) (format "%s:\n" count)) - 'face 'font-lock-comment-face) + 'face font-lock-comment-face) (mastodon-toot--insert-toot-iter x) "\n") (cl-incf count)) @@ -1342,7 +1333,7 @@ LONGEST is the length of the longest binding." (mastodon-toot--format-kbinds kbinds)))) (concat " Compose a new toot here. The following keybindings are available:" - (mapconcat 'identity + (mapconcat #'identity (mastodon-toot--formatted-kbinds-pairs (mastodon-toot--format-kbinds kbinds) longest-kbind) @@ -1383,7 +1374,7 @@ REPLY-TEXT is the text of the toot being replied to." (propertize "None " 'toot-attachments t) "\n") - 'face 'font-lock-comment-face + 'face font-lock-comment-face 'read-only "Edit your message below." 'toot-post-header t) (if reply-text @@ -1395,7 +1386,7 @@ REPLY-TEXT is the text of the toot being replied to." (propertize (concat divider "\n") 'rear-nonsticky t - 'face 'font-lock-comment-face + 'face font-lock-comment-face 'read-only "Edit your message below." 'toot-post-header t)))) @@ -1629,7 +1620,7 @@ EDIT means we are editing an existing toot, not composing a new one." ;; company (when (and mastodon-toot--use-company-for-completion (require 'company nil :no-error)) - (declare-function 'company-mode-on "company") + (declare-function company-mode-on "company") (set (make-local-variable 'company-backends) (add-to-list 'company-backends 'company-capf)) (company-mode-on))) @@ -1657,7 +1648,6 @@ EDIT means we are editing an existing toot, not composing a new one." (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." - :group 'mastodon-toot :keymap mastodon-toot-mode-map :global nil) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 762efa9..d113d44 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -69,7 +69,7 @@ ;;; KEYMAPS -;; copy `mastodon-mode-map' if possible, as then all timeline functions are +;; we copy `mastodon-mode-map', as then all timeline functions are ;; available. this is helpful because if a minor view is the only buffer left ;; open, calling `mastodon' will switch to it, but then we will be unable to ;; switch to timlines without closing the minor view. @@ -81,65 +81,65 @@ ;; `mastodon-mode', it gets overridden in some but not all cases. (defvar mastodon-views-map - (let ((map - (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) - (keymap-canonicalize map)) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-mode-map) + (define-key map (kbd "n") #'mastodon-tl--goto-next-item) + (define-key map (kbd "p") #'mastodon-tl--goto-prev-item) + map) "Base keymap for minor mastodon views.") (defvar mastodon-views--view-filters-keymap - (let ((map - (copy-keymap mastodon-views-map))) - (define-key map (kbd "d") 'mastodon-views--delete-filter) - (define-key map (kbd "c") 'mastodon-views--create-filter) - (define-key map (kbd "TAB") 'mastodon-tl--goto-next-item) - (define-key map (kbd "g") 'mastodon-views--view-filters) - (keymap-canonicalize map)) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-views-map) + (define-key map (kbd "d") #'mastodon-views--delete-filter) + (define-key map (kbd "c") #'mastodon-views--create-filter) + (define-key map (kbd "TAB") #'mastodon-tl--goto-next-item) + (define-key map (kbd "g") #'mastodon-views--view-filters) + map) "Keymap for viewing filters.") (defvar mastodon-views--follow-suggestions-map - (let ((map - (copy-keymap mastodon-views-map))) - (define-key map (kbd "g") 'mastodon-views--view-follow-suggestions) - (keymap-canonicalize map)) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-views-map) + (define-key map (kbd "g") #'mastodon-views--view-follow-suggestions) + map) "Keymap for viewing follow suggestions.") (defvar mastodon-views--view-lists-keymap - (let ((map - (copy-keymap mastodon-views-map))) - (define-key map (kbd "D") 'mastodon-views--delete-list) - (define-key map (kbd "C") 'mastodon-views--create-list) - (define-key map (kbd "A") 'mastodon-views--add-account-to-list) - (define-key map (kbd "R") 'mastodon-views--remove-account-from-list) - (define-key map (kbd "E") 'mastodon-views--edit-list) - (define-key map (kbd "g") 'mastodon-views--view-lists) - (keymap-canonicalize map)) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-views-map) + (define-key map (kbd "D") #'mastodon-views--delete-list) + (define-key map (kbd "C") #'mastodon-views--create-list) + (define-key map (kbd "A") #'mastodon-views--add-account-to-list) + (define-key map (kbd "R") #'mastodon-views--remove-account-from-list) + (define-key map (kbd "E") #'mastodon-views--edit-list) + (define-key map (kbd "g") #'mastodon-views--view-lists) + map) "Keymap for viewing lists.") (defvar mastodon-views--list-name-keymap (let ((map (make-sparse-keymap))) - (define-key map (kbd "") 'mastodon-views--view-timeline-list-at-point) - (define-key map (kbd "d") 'mastodon-views--delete-list-at-point) - (define-key map (kbd "a") 'mastodon-views--add-account-to-list-at-point) - (define-key map (kbd "r") 'mastodon-views--remove-account-from-list-at-point) - (define-key map (kbd "e") 'mastodon-views--edit-list-at-point) - (keymap-canonicalize map)) + (define-key map (kbd "RET") #'mastodon-views--view-timeline-list-at-point) + (define-key map (kbd "d") #'mastodon-views--delete-list-at-point) + (define-key map (kbd "a") #'mastodon-views--add-account-to-list-at-point) + (define-key map (kbd "r") #'mastodon-views--remove-account-from-list-at-point) + (define-key map (kbd "e") #'mastodon-views--edit-list-at-point) + map) "Keymap for when point is on list name.") (defvar mastodon-views--scheduled-map - (let ((map ;(make-sparse-keymap))) - (copy-keymap mastodon-views-map))) - (define-key map (kbd "r") 'mastodon-views--reschedule-toot) - (define-key map (kbd "c") 'mastodon-views--cancel-scheduled-toot) - (define-key map (kbd "e") 'mastodon-views--edit-scheduled-as-new) - (define-key map (kbd "") 'mastodon-views--edit-scheduled-as-new) - (keymap-canonicalize map)) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-views-map) + (define-key map (kbd "r") #'mastodon-views--reschedule-toot) + (define-key map (kbd "c") #'mastodon-views--cancel-scheduled-toot) + (define-key map (kbd "e") #'mastodon-views--edit-scheduled-as-new) + (define-key map (kbd "RET") #'mastodon-views--edit-scheduled-as-new) + map) "Keymap for when point is on a scheduled toot.") (defvar mastodon-views--view-follow-requests-keymap - (let ((map ;(make-sparse-keymap))) - (copy-keymap mastodon-views-map))) + (let ((map (make-sparse-keymap))) + (set-keymap-parent map mastodon-views-map) ;; make reject binding match the binding in notifs view ;; 'r' is then reserved for replying, even tho it is not avail ;; in foll-reqs view diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 8875419..5a46735 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -116,7 +116,6 @@ 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 nil @@ -131,7 +130,6 @@ should be \"https://social.instance.org\". After setting these variables you should restart Emacs for these changes to take effect." - :group 'mastodon :type 'string) (defcustom mastodon-toot-timestamp-format "%F %T" @@ -139,7 +137,6 @@ changes to take effect." For valid formatting options see `format-time-string`. The default value \"%F %T\" prints ISO8601-style YYYY-mm-dd HH:MM:SS. Use. e.g. \"%c\" for your locale's date and time format." - :group 'mastodon :type 'string) (defvar mastodon-mode-map diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 2d9d6df..f2fe009 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -1,6 +1,8 @@ ;;; mastodon-auth-test.el --- Tests for mastodon-auth.el -*- lexical-binding: nil -*- (require 'el-mock) +(require 'mastodon) +(require 'mastodon-auth) (ert-deftest mastodon-auth--handle-token-response--good () "Should extract the access token from a good response." @@ -29,7 +31,7 @@ `(error ,(format "Mastodon-auth--access-token: invalid_grant: %s" error-message)) (condition-case error (mastodon-auth--handle-token-response - `(:error "invalid_grant" :error_description ,error-message)) + `(:error "Invalid_grant" :error_description ,error-message)) (t error)))))) (ert-deftest mastodon-auth--get-token () -- cgit v1.2.3 From 35487576acb349e8dc2b407d01d2a394957772dc Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 22 Mar 2023 16:43:14 +0100 Subject: make view instance work on user listings --- lisp/mastodon-views.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index d113d44..42bf81d 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -733,7 +733,12 @@ INSTANCE is an instance domain name." (mastodon-views--instance-response-fun response brief instance)) (mastodon-tl--do-if-toot (let* ((toot (if (mastodon-tl--profile-buffer-p) - (mastodon-tl--property 'profile-json) ; profile may have 0 toots + ;; we may be on profile itself: + (or (mastodon-tl--property 'profile-json) + ;; or on profile account listings, which use toot-json: + ;; or just toots: + (mastodon-tl--property 'toot-json)) + ;; normal timeline: (mastodon-tl--property 'toot-json))) (reblog (alist-get 'reblog toot)) (account (or (alist-get 'account reblog) -- cgit v1.2.3 From e188f426b7e8aa922514a37d6481c77e474a2b27 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 23 Mar 2023 10:23:39 +0100 Subject: fix view instance desc when on toot/user in profile buffer --- lisp/mastodon-views.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 42bf81d..22eac7e 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -743,10 +743,14 @@ INSTANCE is an instance domain name." (reblog (alist-get 'reblog toot)) (account (or (alist-get 'account reblog) (alist-get 'account toot))) - (url (if (mastodon-tl--profile-buffer-p) + ;; we can't use --profile-buffer-p as our test here because we may + ;; be looking at toots/boosts/users in a profile buffer + ;; profile-json works as a defacto test for if point is on the + ;; profile details at the top of a profile buffer. + (url (if (mastodon-tl--property 'profile-json) (alist-get 'url toot) ; profile (alist-get 'url account))) - (username (if (mastodon-tl--profile-buffer-p) + (username (if (mastodon-tl--property 'profile-json) (alist-get 'username toot) ;; profile (alist-get 'username account))) (instance (if instance -- cgit v1.2.3