From 6dda2522d2a5ea57f88898e0f043760e68c7309d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Aug 2024 21:31:59 +0200 Subject: toot: attach-media: get max attachments from instance, y-or-n-p views: get-own-instance (for max attachs) --- 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 775b96b..e956ccd 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -738,6 +738,11 @@ If INSTANCE is given, use that." (string-remove-suffix (concat "/@" username) url)))) +(defun mastodon-views--get-own-instance () + "Return JSON of `mastodon-active-user's instance." + (mastodon-http--get-json + (mastodon-http--api "instance" "v2") nil nil :vector)) + (defun mastodon-views--view-instance-description (&optional user brief instance misskey) "View the details of the instance the current post's author is on. @@ -747,8 +752,7 @@ INSTANCE is an instance domain name. MISSKEY means the instance is a Misskey or derived server." (interactive) (if user - (let ((response (mastodon-http--get-json - (mastodon-http--api "instance" "v2") nil nil :vector))) + (let ((response (mastodon-views--get-own-instance))) (mastodon-views--instance-response-fun response brief instance)) (mastodon-tl--do-if-item (let* ((toot (if (mastodon-tl--profile-buffer-p) -- cgit v1.2.3 From 7043349b2a5bbb621712fe596086f3d82b65a580 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 6 Aug 2024 10:18:12 +0200 Subject: views add account to list: unless handle clauses to prevent unneeded requests --- lisp/mastodon-views.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index e956ccd..5ec2642 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -393,8 +393,11 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (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 (mastodon-tl--map-alist-vals-to-alist 'acct 'id followings)) + (followings (unless handle + (mastodon-views--get-users-followings))) + (handles (unless handle + (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))) -- cgit v1.2.3 From 6b70ee39efcb958c3bc300498a009b04bee06e84 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 6 Aug 2024 11:08:20 +0200 Subject: audit views.el --- lisp/mastodon-views.el | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 5ec2642..4b29115 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -75,7 +75,7 @@ ;; 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. +;; functions that might 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. @@ -121,6 +121,7 @@ (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) + (define-key map (kbd "g") #'mastodon-views--view-lists) map) "Keymap for when point is on list name.") @@ -131,6 +132,7 @@ (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) + (define-key map (kbd "g") #'mastodon-views--view-scheduled-toots) map) "Keymap for when point is on a scheduled toot.") @@ -158,15 +160,9 @@ 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." - ;; FIXME: this is not an update function as it inserts a heading and - ;; possible bindings string - ;; either it should go in init-sync, or possibly in each view function - ;; but either way, this function does almost nothing for us. - ;; could we call init-sync in here pehaps? - ;; (mastodon-search--insert-heading view-name) - ;; (when bindings-string - ;; (insert (mastodon-tl--set-face (concat "[" bindings-string "]\n\n") - ;; 'font-lock-comment-face))) + ;; FIXME not tecnically an update-fun for init-sync, but just a simple way + ;; to set up the empty buffer or else call the insert-fun. not sure if we cd + ;; improve by eg calling init-sync in here, making this a real view function. (if (seq-empty-p data) (insert (propertize (format "Looks like you have no %s for now." view-name) @@ -326,8 +322,7 @@ If ID is provided, use that list." (name (mastodon-views--get-list-name id)) (buffer-name (format "list-%s" name))) (mastodon-tl--init buffer-name endpoint - 'mastodon-tl--timeline - nil + 'mastodon-tl--timeline nil `(("limit" . ,mastodon-tl--timeline-posts-count))))) (defun mastodon-views--create-list () @@ -432,8 +427,7 @@ If ID is provided, use that list." (list-id (or id (mastodon-views--get-list-id list-name))) (accounts (mastodon-views--accounts-in-list list-id)) (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id accounts)) - (account (completing-read "Account to remove: " - handles nil t)) + (account (completing-read "Account to remove: " handles nil t)) (account-id (alist-get account handles)) (url (mastodon-http--api (format "lists/%s/accounts" list-id))) (args (mastodon-http--build-array-params-alist "account_ids[]" `(,account-id))) @@ -537,7 +531,7 @@ If ID, just return that toot." (interactive) (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) - (message "no scheduled toot at point?") + (user-error "no scheduled toot at point?") (mastodon-toot--schedule-toot :reschedule)))) (defun mastodon-views--copy-scheduled-toot-text () @@ -555,7 +549,7 @@ NO-CONFIRM means there is no ask or message, there is only do." (interactive) (let ((id (or id (mastodon-tl--property 'id :no-move)))) (if (null id) - (message "no scheduled toot at point?") + (user-error "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))) @@ -571,7 +565,7 @@ NO-CONFIRM means there is no ask or message, there is only do." (interactive) (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) - (message "no scheduled toot at point?") + (user-error "no scheduled toot at point?") (let* ((toot (mastodon-tl--property 'scheduled-json :no-move)) (scheduled (alist-get 'scheduled_at toot))) (let-alist (alist-get 'params toot) @@ -646,9 +640,8 @@ Prompt for a context, must be a list containting at least one of \"home\", (contexts-processed (if (equal nil contexts) (user-error "You must select at least one context for a filter") - (mapcar (lambda (x) - (cons "context[]" x)) - contexts))) + (cl-loop for c in contexts + collect (cons "context[]" c)))) (response (mastodon-http--post url (push `("phrase" . ,word) contexts-processed)))) @@ -726,8 +719,7 @@ BRIEF means show fewer details." "Return an instance base url from a user account URL. USERNAME is the name to cull. If INSTANCE is given, use that." - (cond (instance - (concat "https://" instance)) + (cond (instance (concat "https://" instance)) ;; pleroma URL is https://instance.com/users/username ((string-suffix-p "users/" (url-basepath url)) (string-remove-suffix "/users/" @@ -758,13 +750,9 @@ MISSKEY means the instance is a Misskey or derived server." (let ((response (mastodon-views--get-own-instance))) (mastodon-views--instance-response-fun response brief instance)) (mastodon-tl--do-if-item - (let* ((toot (if (mastodon-tl--profile-buffer-p) - ;; we may be on profile description itself: - (or (mastodon-tl--property 'profile-json) - ;; or on profile account listings, or just toots: - (mastodon-tl--property 'item-json)) - ;; normal timeline/account listing: - (mastodon-tl--property 'item-json))) + (let* ((toot (or (and (mastodon-tl--profile-buffer-p) + (mastodon-tl--property 'profile-json)) ; either profile + (mastodon-tl--property 'item-json)) ; or toot or user listing (reblog (alist-get 'reblog toot)) (account (or (alist-get 'account reblog) (alist-get 'account toot) -- cgit v1.2.3 From 8594adb38659bc7e823dea9c379f50c1f35b2969 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 9 Aug 2024 11:52:06 +0200 Subject: basic apply filters. #575. --- lisp/mastodon-notifications.el | 1 + lisp/mastodon-tl.el | 125 +++++++++++++++++++++++++++++------------ lisp/mastodon-views.el | 9 ++- 3 files changed, 95 insertions(+), 40 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 070d23f..f43a9b3 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -201,6 +201,7 @@ Status notifications are given when (defun mastodon-notifications--format-note (note type) "Format for a NOTE of TYPE." + ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' (let* ((id (alist-get 'id note)) (profile-note (when (equal 'follow-request type) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 948ee37..a4d6ec0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1101,12 +1101,13 @@ content should be hidden." (when (not (equal "" cw)) (mastodon-tl--toggle-spoiler-text-in-toot)))))))) -(defun mastodon-tl--spoiler (toot) +(defun mastodon-tl--spoiler (toot &optional filter) "Render TOOT with spoiler message. This assumes TOOT is a toot with a spoiler message. The main body gets hidden and only the spoiler text and the content warning message are displayed. The content warning -message is a link which unhides/hides the main body." +message is a link which unhides/hides the main body. +FILTER is a string to use as a filter warning spoiler instead." (let* ((spoiler (mastodon-tl--field 'spoiler_text toot)) (string (mastodon-tl--set-face (mastodon-tl--clean-tabs-and-nl @@ -1114,7 +1115,9 @@ message is a link which unhides/hides the main body." 'default)) (message (concat " " mastodon-tl--horiz-bar "\n " (mastodon-tl--make-link - (concat "CW: " string) + (if filter + (concat "Filtered: " filter) + (concat "CW: " string)) 'content-warning) "\n " mastodon-tl--horiz-bar "\n")) @@ -1123,20 +1126,22 @@ message is a link which unhides/hides the main body." cw (propertize (mastodon-tl--content toot) 'invisible - (let ((cust mastodon-tl--expand-content-warnings)) - (cond ((eq t cust) - nil) - ((eq nil cust) - t) - ((eq 'server cust) - (unless (eq t - ;; If something goes wrong reading prefs, - ;; just return nil so CWs show by default. - (condition-case nil - (mastodon-profile--get-preferences-pref - 'reading:expand:spoilers) - (error nil))) - t)))) + (if filter + t + (let ((cust mastodon-tl--expand-content-warnings)) + (cond ((eq t cust) + nil) + ((eq nil cust) + t) + ((eq 'server cust) + (unless (eq t + ;; If something goes wrong reading prefs, + ;; just return nil so CWs show by default. + (condition-case nil + (mastodon-profile--get-preferences-pref + 'reading:expand:spoilers) + (error nil))) + t))))) 'mastodon-content-warning-body t)))) @@ -1573,6 +1578,42 @@ Used as a predicate in `mastodon-tl--timeline'." (and (mastodon-tl--field 'in_reply_to_id toot) (eq :json-false (mastodon-tl--field 'reblogged toot)))) +(defun mastodon-tl--filters-alist (filters) + "Parse filter data for FILTERS. +For each filter, return a list of action (warn or hide), filter +title, and context." + (cl-loop for x in filters ;; includes non filter elts! + for f = (alist-get 'filter x) + collect (list (alist-get 'filter_action f) + (alist-get 'title f) + (alist-get 'context f)))) + +(defun mastodon-tl--filter-by-context (context filters) + "Remove FILTERS that don't apply to the current CONTEXT." + (cl-remove-if-not + (lambda (x) + (member context (nth 2 x))) + filters)) + +(defun mastodon-tl--filters-context () + "Return a string of the current buffer's filter context. +Returns a member of `mastodon-views--filter-types'." + (let ((buf (mastodon-tl--get-buffer-type))) + (cond ((or (eq buf 'local) (eq buf 'federated)) + "public") + ((mastodon-tl--profile-buffer-p) + "profile") + (t ;; thread, notifs, home: + (symbol-name buf))))) + +(defun mastodon-tl--current-filters (filters) + "Return the filters from FILTERS data that apply in the current context. +For each filter, return a list of action (warn or hide), filter +title, and context." + (let ((context (mastodon-tl--filters-context)) + (filters-no-context (mastodon-tl--filters-alist filters))) + (mastodon-tl--filter-by-context context filters-no-context))) + (defun mastodon-tl--toot (toot &optional detailed-p thread domain unfolded no-byline) "Format TOOT and insert it into the buffer. @@ -1582,32 +1623,42 @@ THREAD means the status will be displayed in a thread view. When DOMAIN, force inclusion of user's domain in their handle. UNFOLDED is a boolean meaning whether to unfold or fold item if foldable. NO-BYLINE means just insert toot body, used for folding." - (mastodon-tl--insert-status - toot - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler toot) - (mastodon-tl--spoiler toot) - (mastodon-tl--content toot))) - 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted - nil nil detailed-p thread domain unfolded no-byline)) + (let* ((filtered (mastodon-tl--field 'filtered toot)) + (filters (when filtered + (mastodon-tl--current-filters filtered))) + (spoiler-or-content (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler toot (cadr match)) + (if (mastodon-tl--has-spoiler toot) + (mastodon-tl--spoiler toot) + (mastodon-tl--content toot))))) + ;; If any filters are "hide", then we hide, + ;; even though item may also have a "warn" filter: + (if (and filtered (assoc "hide" filters)) + nil ;; no insert + (mastodon-tl--insert-status + toot + (mastodon-tl--clean-tabs-and-nl spoiler-or-content) + 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted + nil nil detailed-p thread domain unfolded no-byline)))) (defun mastodon-tl--timeline (toots &optional thread domain) "Display each toot in TOOTS. This function removes replies if user required. THREAD means the status will be displayed in a thread view. When DOMAIN, force inclusion of user's domain in their handle." - (mapc (lambda (toot) - (mastodon-tl--toot toot nil thread domain)) - ;; hack to *not* filter replies on profiles: - (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) - toots - (if (or ; we were called via --more*: - (mastodon-tl--buffer-property 'hide-replies nil :no-error) - ;; loading a tl with a prefix arg: - (mastodon-tl--hide-replies-p current-prefix-arg)) - (cl-remove-if-not #'mastodon-tl--is-reply toots) - toots))) - (goto-char (point-min))) + (let ((toots ;; hack to *not* filter replies on profiles: + (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) + toots + (if (or ; we were called via --more*: + (mastodon-tl--buffer-property 'hide-replies nil :no-error) + ;; loading a tl with a prefix arg: + (mastodon-tl--hide-replies-p current-prefix-arg)) + (cl-remove-if-not #'mastodon-tl--is-reply toots) + toots)))) + (mapc (lambda (toot) + (mastodon-tl--toot toot nil thread domain)) + toots) + (goto-char (point-min)))) ;;; FOLDING diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 4b29115..1ddb769 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -621,6 +621,9 @@ JSON is the filters data." 'byline t) ;for goto-next-filter compat "\n\n"))) +(defvar mastodon-views--filter-types + '("home" "notifications" "public" "thread" "profile")) + (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\", @@ -635,7 +638,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (user-error "You must select at least one word for a filter") (completing-read-multiple "Contexts to filter [TAB for options]: " - '("home" "notifications" "public" "thread") + mastodon-views--filter-types nil t))) (contexts-processed (if (equal nil contexts) @@ -647,9 +650,9 @@ Prompt for a context, must be a list containting at least one of \"home\", contexts-processed)))) (mastodon-http--triage response (lambda (_) - (message "Filter created for %s!" word) (when (mastodon-tl--buffer-type-eq 'filters) - (mastodon-views--view-filters)))))) + (mastodon-views--view-filters)) + (message "Filter created for %s!" word))))) (defun mastodon-views--delete-filter () "Delete filter at point." -- cgit v1.2.3 From dccf84397d43135e2c2fd15ab918e887ff0eed9d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Aug 2024 08:59:52 +0200 Subject: create-filter v2 --- lisp/mastodon-views.el | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 1ddb769..f0b9cbf 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -629,30 +629,38 @@ JSON is the filters data." 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) ""))) + ;; FIXME: implement "keywords_attributes[][whole_word]" boolean for each + ;; term + (let* ((url (mastodon-http--api "filters" "v2")) + (title (read-string "Filter name: ")) + (terms (read-string "Terms to filter (space separated): ")) + (terms-split (split-string terms "[ ]")) + (terms-processed + (if (not terms) + (user-error "You must select at least one term to filter") + (mastodon-http--build-array-params-alist + "keywords_attributes[][keyword]" terms-split))) + (warn-or-hide + (completing-read "Warn (like CW) or hide? " + '("warn" "hide") nil :match)) (contexts - (if (string-empty-p word) - (user-error "You must select at least one word for a filter") - (completing-read-multiple - "Contexts to filter [TAB for options]: " - mastodon-views--filter-types - nil t))) + (completing-read-multiple "Filter contexts [TAB for options]: " + mastodon-views--filter-types nil :match)) (contexts-processed - (if (equal nil contexts) + (if (not contexts) (user-error "You must select at least one context for a filter") - (cl-loop for c in contexts - collect (cons "context[]" c)))) - (response (mastodon-http--post url (push - `("phrase" . ,word) - contexts-processed)))) + (mastodon-http--build-array-params-alist "context[]" contexts))) + (params (append `(("title" . ,title) + ("filter_action" . ,warn-or-hide)) + ;; ("keywords_attributes[][whole_word]" . "false")) + terms-processed + contexts-processed)) + (response (mastodon-http--post url params))) (mastodon-http--triage response (lambda (_) (when (mastodon-tl--buffer-type-eq 'filters) (mastodon-views--view-filters)) - (message "Filter created for %s!" word))))) + (message "Filter %s created!" title))))) (defun mastodon-views--delete-filter () "Delete filter at point." -- cgit v1.2.3 From 348eb4fba78e0e19f1c3d8784228f174b95979e2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Aug 2024 09:27:40 +0200 Subject: v basic display/delete v2 filters --- lisp/mastodon-views.el | 58 +++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index f0b9cbf..cbe1e46 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -589,7 +589,7 @@ NO-CONFIRM means there is no ask or message, there is only do." nil nil nil "current filters" "c - create filter\n d - delete filter at point\n\ - n/p - go to next/prev filter") + n/p - go to next/prev filter" "v2") (with-current-buffer "*mastodon-filters*" (use-local-map mastodon-views--view-filters-keymap))) @@ -608,18 +608,31 @@ JSON is the filters data." (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 ", ")))) + (let-alist filter (insert - (propertize filter-string - 'item-id id ;for goto-next-filter compat - 'item-type 'filter - 'phrase phrase - 'byline t) ;for goto-next-filter compat - "\n\n"))) + (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n " + (propertize (upcase .title) + 'item-id .id + 'item-type 'filter + 'filter-title .title + 'byline t) + " " "\n" + " " mastodon-tl--horiz-bar "\n") + 'success)) + (insert "Context: " + (mapconcat #'identity .context ", ")) + (insert "\n\nType: " .filter_action) + (if (not .keywords) + "" + (insert "\n\nTerms:") + (mapc (lambda (kw) + (insert + (concat (format "\n %s \"%s\"" + (if (char-displayable-p ?―) "―" "-") + (alist-get 'keyword kw))))) + .keywords)) + (insert "\n"))) (defvar mastodon-views--filter-types '("home" "notifications" "public" "thread" "profile")) @@ -633,8 +646,8 @@ Prompt for a context, must be a list containting at least one of \"home\", ;; term (let* ((url (mastodon-http--api "filters" "v2")) (title (read-string "Filter name: ")) - (terms (read-string "Terms to filter (space separated): ")) - (terms-split (split-string terms "[ ]")) + (terms (read-string "Terms to filter (comma or space separated): ")) + (terms-split (split-string terms "[, ]")) (terms-processed (if (not terms) (user-error "You must select at least one term to filter") @@ -644,8 +657,9 @@ Prompt for a context, must be a list containting at least one of \"home\", (completing-read "Warn (like CW) or hide? " '("warn" "hide") nil :match)) (contexts - (completing-read-multiple "Filter contexts [TAB for options]: " - mastodon-views--filter-types nil :match)) + (completing-read-multiple + "Filter contexts [TAB for options, comma separated]: " + mastodon-views--filter-types nil :match)) (contexts-processed (if (not contexts) (user-error "You must select at least one context for a filter") @@ -665,17 +679,17 @@ 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 (mastodon-tl--property 'item-id :no-move)) - (phrase (mastodon-tl--property 'phrase :no-move)) - (url (mastodon-http--api (format "filters/%s" filter-id)))) - (if (null phrase) + (let* ((id (mastodon-tl--property 'item-id :no-move)) + (title (mastodon-tl--property 'filter-title :no-move)) + (url (mastodon-http--api (format "filters/%s" id) "v2"))) + (if (null id) (user-error "No filter at point?") - (when (y-or-n-p (format "Delete filter %s? " phrase)) + (when (y-or-n-p (format "Delete filter %s? " title)) (let ((response (mastodon-http--delete url))) (mastodon-http--triage response (lambda (_) (mastodon-views--view-filters) - (message "Filter for \"%s\" deleted!" phrase)))))))) + (message "Filter \"%s\" deleted!" title)))))))) ;;; FOLLOW SUGGESTIONS -- cgit v1.2.3 From d619c096de763075a52c3836a8d0a617bedec19b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Aug 2024 09:27:53 +0200 Subject: instance desc - missing paren --- 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 cbe1e46..a363ef0 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -777,7 +777,7 @@ MISSKEY means the instance is a Misskey or derived server." (mastodon-tl--do-if-item (let* ((toot (or (and (mastodon-tl--profile-buffer-p) (mastodon-tl--property 'profile-json)) ; either profile - (mastodon-tl--property 'item-json)) ; or toot or user listing + (mastodon-tl--property 'item-json))) ; or toot or user listing (reblog (alist-get 'reblog toot)) (account (or (alist-get 'account reblog) (alist-get 'account toot) -- cgit v1.2.3 From caf694e383a3382bdd8bf712d86acbe1e50f00ef Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Aug 2024 09:37:29 +0200 Subject: flymake views.el --- lisp/mastodon-views.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index a363ef0..b23d364 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -531,7 +531,7 @@ If ID, just return that toot." (interactive) (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) - (user-error "no scheduled toot at point?") + (user-error "No scheduled toot at point?") (mastodon-toot--schedule-toot :reschedule)))) (defun mastodon-views--copy-scheduled-toot-text () @@ -549,7 +549,7 @@ NO-CONFIRM means there is no ask or message, there is only do." (interactive) (let ((id (or id (mastodon-tl--property 'id :no-move)))) (if (null id) - (user-error "no scheduled toot at point?") + (user-error "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))) @@ -565,7 +565,7 @@ NO-CONFIRM means there is no ask or message, there is only do." (interactive) (let ((id (mastodon-tl--property 'id :no-move))) (if (null id) - (user-error "no scheduled toot at point?") + (user-error "No scheduled toot at point?") (let* ((toot (mastodon-tl--property 'scheduled-json :no-move)) (scheduled (alist-get 'scheduled_at toot))) (let-alist (alist-get 'params toot) -- cgit v1.2.3 From ba364e75dcab736770fc8b6a60f7f7b4ff611f34 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 13 Aug 2024 09:44:10 +0200 Subject: do-if-item for scheduled toots --- lisp/mastodon-views.el | 58 +++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index b23d364..160de47 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -513,7 +513,7 @@ JSON is the data returned by the server." 'item-type 'scheduled ; so we nav here 'face 'font-lock-comment-face 'keymap mastodon-views--scheduled-map - 'scheduled-json toot + 'item-json toot 'id .id) "\n"))) @@ -529,10 +529,8 @@ If ID, just return that toot." (defun mastodon-views--reschedule-toot () "Reschedule the scheduled toot at point." (interactive) - (let ((id (mastodon-tl--property 'id :no-move))) - (if (null id) - (user-error "No scheduled toot at point?") - (mastodon-toot--schedule-toot :reschedule)))) + (mastodon-tl--do-if-item + (mastodon-toot--schedule-toot :reschedule))) (defun mastodon-views--copy-scheduled-toot-text () "Copy the text of the scheduled toot at point." @@ -547,36 +545,34 @@ 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 (mastodon-tl--property 'id :no-move)))) - (if (null id) - (user-error "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!"))))))))) + (mastodon-tl--do-if-item + (when (or no-confirm + (y-or-n-p "Cancel scheduled toot?")) + (let* ((id (or id (mastodon-tl--property 'id :no-move))) + (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 ((id (mastodon-tl--property 'id :no-move))) - (if (null id) - (user-error "No scheduled toot at point?") - (let* ((toot (mastodon-tl--property 'scheduled-json :no-move)) - (scheduled (alist-get 'scheduled_at toot))) - (let-alist (alist-get 'params toot) - ;; TODO: preserve polls - ;; (poll (alist-get 'poll params)) - (mastodon-toot--compose-buffer nil .in_reply_to_id nil .text :edit) - (goto-char (point-max)) - ;; adopt properties from scheduled toot: - (mastodon-toot--set-toot-properties - .in_reply_to_id .visibility .spoiler_text .language - scheduled id (alist-get 'media_attachments toot))))))) + (mastodon-tl--do-if-item + (let* ((toot (mastodon-tl--property 'scheduled-json :no-move)) + (id (mastodon-tl--property 'id :no-move)) + (scheduled (alist-get 'scheduled_at toot))) + (let-alist (alist-get 'params toot) + ;; TODO: preserve polls + ;; (poll (alist-get 'poll params)) + (mastodon-toot--compose-buffer nil .in_reply_to_id nil .text :edit) + (goto-char (point-max)) + ;; adopt properties from scheduled toot: + (mastodon-toot--set-toot-properties + .in_reply_to_id .visibility .spoiler_text .language + scheduled id (alist-get 'media_attachments toot)))))) ;;; FILTERS -- cgit v1.2.3 From d18f86a0e21b17eb67685c4c0500819e864d4427 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 14 Aug 2024 13:56:24 +0200 Subject: clean up filters code --- lisp/mastodon-views.el | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 160de47..0d0277e 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -594,17 +594,32 @@ NO-CONFIRM means there is no ask or message, there is only do." JSON is what is returned by by the server." (mastodon-views--minor-view "filters" - #'mastodon-views--insert-filter-string-set + #'mastodon-views--insert-filters json)) -(defun mastodon-views--insert-filter-string-set (json) +(defun mastodon-views--insert-filters (json) "Insert a filter string plus a blank line. JSON is the filters data." - (mapc #'mastodon-views--insert-filter-string json)) - -(defun mastodon-views--insert-filter-string (filter) + (mapc #'mastodon-views--insert-filter json)) + +(defun mastodon-views--insert-filter-kws (kws) + "Insert filter keywords KWS." + (mapc (lambda (kw) + (let ((whole (alist-get 'whole_word kw))) + (insert + (propertize (concat + (format "\n %s \"%s\" | whole word: %s" + (if (char-displayable-p ?―) "―" "-") + (alist-get 'keyword kw) + whole)) + 'kw-id (alist-get 'id kw) + 'whole-word whole)))) + kws)) + +(defun mastodon-views--insert-filter (filter) "Insert a single FILTER." (let-alist filter + ;; heading: (insert (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " @@ -616,18 +631,16 @@ JSON is the filters data." " " "\n" " " mastodon-tl--horiz-bar "\n") 'success)) + ;; context: (insert "Context: " (mapconcat #'identity .context ", ")) + ;; type (warn or hide): (insert "\n\nType: " .filter_action) + ;; terms list: (if (not .keywords) "" (insert "\n\nTerms:") - (mapc (lambda (kw) - (insert - (concat (format "\n %s \"%s\"" - (if (char-displayable-p ?―) "―" "-") - (alist-get 'keyword kw))))) - .keywords)) + (mastodon-views--insert-filter-kws \.keywords)) (insert "\n"))) (defvar mastodon-views--filter-types @@ -677,7 +690,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (interactive) (let* ((id (mastodon-tl--property 'item-id :no-move)) (title (mastodon-tl--property 'filter-title :no-move)) - (url (mastodon-http--api (format "filters/%s" id) "v2"))) + (url (mastodon-http--api-v2 (format "filters/%s" id)))) (if (null id) (user-error "No filter at point?") (when (y-or-n-p (format "Delete filter %s? " title)) -- cgit v1.2.3 From 5e2e14b1f9aee068d3b59c4d319fa923114b9f71 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 14 Aug 2024 13:57:24 +0200 Subject: get filter kw, update filter kw --- lisp/mastodon-views.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 0d0277e..8c36f27 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -700,6 +700,33 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-views--view-filters) (message "Filter \"%s\" deleted!" title)))))))) +(defun mastodon-views--get-filter-kw (&optional id) + "GET filter with ID." + (let* ((id (or id (mastodon-tl--property 'kw-id :no-move))) + (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) + (resp (mastodon-http--get-json url))) + resp)) + +(defun mastodon-views--update-filter-kw () + "Update filter keyword at point. +Prmopt to change the term, and the whole words option. +When t, whole words means only match whole words." + (interactive) + (let* ((id (mastodon-tl--property 'kw-id :no-move)) + (kw (mastodon-views--get-filter-kw id)) + (keyword (read-string "Keyword: " (alist-get 'keyword kw))) + (whole-word (if (y-or-n-p "Match whole words only? ") + "true" + "false")) + (params `(("keyword" . ,keyword) + ("whole_word" . ,whole-word))) + (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) + (resp (mastodon-http--put url params))) + (mastodon-http--triage + resp + (lambda (resp) + (message (format "Keyword %s updated!" keyword)))))) + ;;; FOLLOW SUGGESTIONS ;; No pagination: max 80 results -- cgit v1.2.3 From c58e69b4d6e327603d868b98745e032d2436bafa Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 14 Aug 2024 14:27:29 +0200 Subject: fix insert-filter-kws --- lisp/mastodon-views.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 8c36f27..2a0d248 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -604,11 +604,15 @@ JSON is the filters data." (defun mastodon-views--insert-filter-kws (kws) "Insert filter keywords KWS." + ;; FIXME: make this a table (ideally upatable) + (insert "\n\nTerms: | whole words only:") (mapc (lambda (kw) - (let ((whole (alist-get 'whole_word kw))) + (let ((whole (if (eq :json-false (alist-get 'whole_word kw)) + "nil" + "t"))) (insert (propertize (concat - (format "\n %s \"%s\" | whole word: %s" + (format "\n %s \"%s\" | %s" (if (char-displayable-p ?―) "―" "-") (alist-get 'keyword kw) whole)) @@ -637,10 +641,9 @@ JSON is the filters data." ;; type (warn or hide): (insert "\n\nType: " .filter_action) ;; terms list: - (if (not .keywords) + (if (not .keywords) ;; poss to have a filter sans keywords "" - (insert "\n\nTerms:") - (mastodon-views--insert-filter-kws \.keywords)) + (mastodon-views--insert-filter-kws .keywords)) (insert "\n"))) (defvar mastodon-views--filter-types -- cgit v1.2.3 From 0be17ad84990dc2d9bd0042680eca06ec5433297 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 10:33:09 +0200 Subject: rough table display of filter keywords --- lisp/mastodon-views.el | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 2a0d248..9d46279 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -605,20 +605,31 @@ JSON is the filters data." (defun mastodon-views--insert-filter-kws (kws) "Insert filter keywords KWS." ;; FIXME: make this a table (ideally upatable) - (insert "\n\nTerms: | whole words only:") - (mapc (lambda (kw) - (let ((whole (if (eq :json-false (alist-get 'whole_word kw)) - "nil" - "t"))) - (insert - (propertize (concat - (format "\n %s \"%s\" | %s" - (if (char-displayable-p ?―) "―" "-") - (alist-get 'keyword kw) - whole)) - 'kw-id (alist-get 'id kw) - 'whole-word whole)))) - kws)) + (insert "\n\n") + (let ((beg (point)) + (whole-str "whole-words-only:")) + (insert (concat "Terms: | " whole-str "\n")) + (mapc (lambda (kw) + (let ((whole (if (eq :json-false (alist-get 'whole_word kw)) + "nil" + "t"))) + (insert + (propertize (concat + (format "\"%s\" | %s\n" + (alist-get 'keyword kw) whole)) + 'kw-id (alist-get 'id kw) + 'whole-word whole)))) + kws) + ;; table display of kws: + (table-capture beg (point) "|" "\n" nil (+ 2 (length whole-str))) + (table-justify-column 'center) + (table-forward-cell) ;; col 2 + (table-justify-column 'center) + (while (re-search-forward ;; goto end of table: + (concat table-cell-horizontal-chars + (make-string 1 table-cell-intersection-char) + "\n") + nil :no-error)))) (defun mastodon-views--insert-filter (filter) "Insert a single FILTER." @@ -643,8 +654,7 @@ JSON is the filters data." ;; terms list: (if (not .keywords) ;; poss to have a filter sans keywords "" - (mastodon-views--insert-filter-kws .keywords)) - (insert "\n"))) + (mastodon-views--insert-filter-kws .keywords)))) (defvar mastodon-views--filter-types '("home" "notifications" "public" "thread" "profile")) -- cgit v1.2.3 From 5256df1189a787d09eb6b80d2206c198648f52e4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 15:40:05 +0200 Subject: add add/remove filter kw, plus some propertizing and cleanup. #578. --- lisp/mastodon-views.el | 87 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 25 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 9d46279..8b5d975 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -589,14 +589,6 @@ NO-CONFIRM means there is no ask or message, there is only do." (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 - "filters" - #'mastodon-views--insert-filters - json)) - (defun mastodon-views--insert-filters (json) "Insert a filter string plus a blank line. JSON is the filters data." @@ -618,6 +610,8 @@ JSON is the filters data." (format "\"%s\" | %s\n" (alist-get 'keyword kw) whole)) 'kw-id (alist-get 'id kw) + 'item-json kw + 'mastodon-tab-stop t 'whole-word whole)))) kws) ;; table display of kws: @@ -636,21 +630,28 @@ JSON is the filters data." (let-alist filter ;; heading: (insert - (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n " - (propertize (upcase .title) - 'item-id .id - 'item-type 'filter - 'filter-title .title - 'byline t) - " " "\n" - " " mastodon-tl--horiz-bar "\n") - 'success)) - ;; context: - (insert "Context: " - (mapconcat #'identity .context ", ")) - ;; type (warn or hide): - (insert "\n\nType: " .filter_action) + (propertize + (concat + (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n " + (propertize (upcase .title) + 'item-id .id + 'item-type 'filter + 'filter-title .title + 'byline t) + " " "\n" + " " mastodon-tl--horiz-bar "\n") + 'success) + ;; context: + (concat "Context: " + (mapconcat #'identity .context ", ")) + ;; type (warn or hide): + (concat "\n\nType: " .filter_action)) + 'item-json filter + 'item-id .id + 'item-type 'filter)) + + ;; FIXME: return a string so we can propertize/insert in here: ;; terms list: (if (not .keywords) ;; poss to have a filter sans keywords "" @@ -704,7 +705,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (let* ((id (mastodon-tl--property 'item-id :no-move)) (title (mastodon-tl--property 'filter-title :no-move)) (url (mastodon-http--api-v2 (format "filters/%s" id)))) - (if (null id) + (if (not (eq 'filter (mastodon-tl--property 'item-type))) (user-error "No filter at point?") (when (y-or-n-p (format "Delete filter %s? " title)) (let ((response (mastodon-http--delete url))) @@ -737,9 +738,45 @@ When t, whole words means only match whole words." (resp (mastodon-http--put url params))) (mastodon-http--triage resp - (lambda (resp) + (lambda (_resp) (message (format "Keyword %s updated!" keyword)))))) +(defun mastodon-views--add-filter-kw () + "Add a keyword to filter at point." + (interactive) + (if (not (eq 'filter (mastodon-tl--property 'item-type))) + (user-error "No filter at point?") + (let* ((kw (read-string "Keyword: ")) + (id (mastodon-tl--property 'item-id :no-move)) + (whole-word (if (y-or-n-p "Match whole words only? ") + "true" + "false")) + (params `(("keyword" . ,kw) + ("whole_word" . ,whole-word))) + (url (mastodon-http--api-v2 (format "filters/%s/keywords" id))) + (resp (mastodon-http--post url params))) + (mastodon-http--triage + resp + (lambda (_resp) + (message (format "Keyword %s added!" kw))))))) + +(defun mastodon-views--remove-filter-kw () + "Remove keyword from filter at point." + (interactive) + (if (not (eq 'filter (mastodon-tl--property 'item-type))) + (user-error "No filter at point?") + (let* ((kws (alist-get 'keywords + (mastodon-tl--property 'item-json :no-move))) + (alist (mastodon-tl--map-alist-vals-to-alist 'keyword 'id kws)) + (choice (completing-read "Remove keyword: " alist)) + (id (cdr (assoc choice alist #'equal))) + (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) + (resp (mastodon-http--delete url))) + (mastodon-http--triage + resp + (lambda (_resp) + (message (format "Keyword %s removed!" choice))))))) + ;;; FOLLOW SUGGESTIONS ;; No pagination: max 80 results -- cgit v1.2.3 From 96e7d2e5815e2d05ffff4ab6ee2188fc496c8ca9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 17:21:47 +0200 Subject: re-write update filter kw, refactor filter triage. #578 --- lisp/mastodon-views.el | 71 ++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 8b5d975..31bb6f0 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -646,7 +646,7 @@ JSON is the filters data." (concat "Context: " (mapconcat #'identity .context ", ")) ;; type (warn or hide): - (concat "\n\nType: " .filter_action)) + (concat "\nType: " .filter_action)) 'item-json filter 'item-id .id 'item-type 'filter)) @@ -693,11 +693,8 @@ Prompt for a context, must be a list containting at least one of \"home\", terms-processed contexts-processed)) (response (mastodon-http--post url params))) - (mastodon-http--triage response - (lambda (_) - (when (mastodon-tl--buffer-type-eq 'filters) - (mastodon-views--view-filters)) - (message "Filter %s created!" title))))) + (mastodon-views--filters-triage + (message "Filter %s created!" title)))) (defun mastodon-views--delete-filter () "Delete filter at point." @@ -708,11 +705,10 @@ Prompt for a context, must be a list containting at least one of \"home\", (if (not (eq 'filter (mastodon-tl--property 'item-type))) (user-error "No filter at point?") (when (y-or-n-p (format "Delete filter %s? " title)) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage - response (lambda (_) - (mastodon-views--view-filters) - (message "Filter \"%s\" deleted!" title)))))))) + (let ((resp (mastodon-http--delete url))) + (mastodon-views--filters-triage + resp + (message "Filter \"%s\" deleted!" title))))))) (defun mastodon-views--get-filter-kw (&optional id) "GET filter with ID." @@ -722,24 +718,36 @@ Prompt for a context, must be a list containting at least one of \"home\", resp)) (defun mastodon-views--update-filter-kw () - "Update filter keyword at point. + "Update filter keyword. Prmopt to change the term, and the whole words option. When t, whole words means only match whole words." (interactive) - (let* ((id (mastodon-tl--property 'kw-id :no-move)) - (kw (mastodon-views--get-filter-kw id)) - (keyword (read-string "Keyword: " (alist-get 'keyword kw))) - (whole-word (if (y-or-n-p "Match whole words only? ") - "true" - "false")) - (params `(("keyword" . ,keyword) - ("whole_word" . ,whole-word))) - (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) - (resp (mastodon-http--put url params))) - (mastodon-http--triage - resp - (lambda (_resp) - (message (format "Keyword %s updated!" keyword)))))) + (if (not (eq 'filter (mastodon-tl--property 'item-type))) + (user-error "No filter at point?") + (let* ((kws (alist-get 'keywords + (mastodon-tl--property 'item-json :no-move))) + (alist (mastodon-tl--map-alist-vals-to-alist 'keyword 'id kws)) + (choice (completing-read "Update keyword: " alist)) + (updated (read-string "Keyword: " choice)) + (whole-word (if (y-or-n-p "Match whole words only? ") + "true" + "false")) + (params `(("keyword" . ,updated) + ("whole_word" . ,whole-word))) + (id (cdr (assoc choice alist #'equal))) + (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) + (resp (mastodon-http--put url params))) + (mastodon-views--filters-triage resp + (format "Keyword %s updated!" updated))))) + +(defun mastodon-views--filters-triage (resp msg-str) + "Triage filter action response RESP, reload filters, message MSG-STR." + (mastodon-http--triage + resp + (lambda (_resp) + (when (mastodon-tl--buffer-type-eq 'filters) + (mastodon-views--view-filters)) + (message msg-str)))) (defun mastodon-views--add-filter-kw () "Add a keyword to filter at point." @@ -755,10 +763,8 @@ When t, whole words means only match whole words." ("whole_word" . ,whole-word))) (url (mastodon-http--api-v2 (format "filters/%s/keywords" id))) (resp (mastodon-http--post url params))) - (mastodon-http--triage - resp - (lambda (_resp) - (message (format "Keyword %s added!" kw))))))) + (mastodon-views--filters-triage resp + (format "Keyword %s added!" kw))))) (defun mastodon-views--remove-filter-kw () "Remove keyword from filter at point." @@ -772,10 +778,7 @@ When t, whole words means only match whole words." (id (cdr (assoc choice alist #'equal))) (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) (resp (mastodon-http--delete url))) - (mastodon-http--triage - resp - (lambda (_resp) - (message (format "Keyword %s removed!" choice))))))) + (mastodon-views--filters-triage resp (format "Keyword %s removed!" choice))))) ;;; FOLLOW SUGGESTIONS -- cgit v1.2.3 From 70dff6c4a70822bfc7502010682d3ab0a5002839 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 20:23:21 +0200 Subject: filters cleanup --- lisp/mastodon-views.el | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 31bb6f0..c1a6054 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -594,9 +594,10 @@ NO-CONFIRM means there is no ask or message, there is only do." JSON is the filters data." (mapc #'mastodon-views--insert-filter json)) +(require 'table) + (defun mastodon-views--insert-filter-kws (kws) "Insert filter keywords KWS." - ;; FIXME: make this a table (ideally upatable) (insert "\n\n") (let ((beg (point)) (whole-str "whole-words-only:")) @@ -628,10 +629,10 @@ JSON is the filters data." (defun mastodon-views--insert-filter (filter) "Insert a single FILTER." (let-alist filter - ;; heading: (insert (propertize (concat + ;; heading: (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " (propertize (upcase .title) @@ -650,8 +651,6 @@ JSON is the filters data." 'item-json filter 'item-id .id 'item-type 'filter)) - - ;; FIXME: return a string so we can propertize/insert in here: ;; terms list: (if (not .keywords) ;; poss to have a filter sans keywords "" @@ -665,8 +664,6 @@ JSON is the filters data." Prompt for a context, must be a list containting at least one of \"home\", \"notifications\", \"public\", \"thread\"." (interactive) - ;; FIXME: implement "keywords_attributes[][whole_word]" boolean for each - ;; term (let* ((url (mastodon-http--api "filters" "v2")) (title (read-string "Filter name: ")) (terms (read-string "Terms to filter (comma or space separated): ")) @@ -692,8 +689,9 @@ Prompt for a context, must be a list containting at least one of \"home\", ;; ("keywords_attributes[][whole_word]" . "false")) terms-processed contexts-processed)) - (response (mastodon-http--post url params))) + (resp (mastodon-http--post url params))) (mastodon-views--filters-triage + resp (message "Filter %s created!" title)))) (defun mastodon-views--delete-filter () -- cgit v1.2.3 From a72f227f2c371f838f189c12ea79442fd5572de0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 21:06:40 +0200 Subject: add update filter. #578 --- lisp/mastodon-views.el | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index c1a6054..608d13f 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -659,14 +659,17 @@ JSON is the filters data." (defvar mastodon-views--filter-types '("home" "notifications" "public" "thread" "profile")) -(defun mastodon-views--create-filter () +(defun mastodon-views--create-filter (&optional id title context type terms) "Create a filter for a word. Prompt for a context, must be a list containting at least one of \"home\", -\"notifications\", \"public\", \"thread\"." +\"notifications\", \"public\", \"thread\". +Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (interactive) - (let* ((url (mastodon-http--api "filters" "v2")) - (title (read-string "Filter name: ")) - (terms (read-string "Terms to filter (comma or space separated): ")) + (let* ((url (if id + (mastodon-http--api-v2 (format "filters/%s" id)) + (mastodon-http--api-v2 "filters"))) + (title (or title (read-string "Filter name: "))) + (terms (or terms (read-string "Terms to filter (comma or space separated): "))) (terms-split (split-string terms "[, ]")) (terms-processed (if (not terms) @@ -674,12 +677,14 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-http--build-array-params-alist "keywords_attributes[][keyword]" terms-split))) (warn-or-hide - (completing-read "Warn (like CW) or hide? " - '("warn" "hide") nil :match)) + (or type + (completing-read "Warn (like CW) or hide? " + '("warn" "hide") nil :match))) (contexts - (completing-read-multiple - "Filter contexts [TAB for options, comma separated]: " - mastodon-views--filter-types nil :match)) + (or context + (completing-read-multiple + "Filter contexts [TAB for options, comma separated]: " + mastodon-views--filter-types nil :match))) (contexts-processed (if (not contexts) (user-error "You must select at least one context for a filter") @@ -689,11 +694,33 @@ Prompt for a context, must be a list containting at least one of \"home\", ;; ("keywords_attributes[][whole_word]" . "false")) terms-processed contexts-processed)) - (resp (mastodon-http--post url params))) + (resp (if id + (mastodon-http--put url params) + (mastodon-http--post url params)))) (mastodon-views--filters-triage resp (message "Filter %s created!" title)))) +(defun mastodon-views--update-filter () + "Update filter at point." + (interactive) + (if (not (eq 'filter (mastodon-tl--property 'item-type))) + (user-error "No filter at point?") + (let* ((filter (mastodon-tl--property 'item-json)) + (id (mastodon-tl--property 'item-id)) + (name (read-string "Name: " (alist-get 'title filter))) + (contexts (completing-read-multiple + "Filter contexts [TAB for options, comma separated]: " + mastodon-views--filter-types nil :match + (mapconcat #'identity + (alist-get 'context filter) ","))) + (type (completing-read "Warn (like CW) or hide? " + '("warn" "hide") nil :match + (alist-get 'type filter))) + (terms (read-string "Terms to add (comma or space separated): "))) + (mastodon-views--create-filter id name contexts type terms)))) + + (defun mastodon-views--delete-filter () "Delete filter at point." (interactive) -- cgit v1.2.3 From 8226df7623a4697ec85d92bd0d508ad4c1bb4a0d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 21:13:07 +0200 Subject: filter kw table: en dashes if possible --- lisp/mastodon-views.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 608d13f..411d2d2 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -600,6 +600,9 @@ JSON is the filters data." "Insert filter keywords KWS." (insert "\n\n") (let ((beg (point)) + (table-cell-horizontal-chars (if (char-displayable-p ?–) ; ?– ?-) + "–" + "-")) (whole-str "whole-words-only:")) (insert (concat "Terms: | " whole-str "\n")) (mapc (lambda (kw) -- cgit v1.2.3 From a1b42fe543fbe952907c5b0a4fae71b2501d7f44 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 15 Aug 2024 22:06:02 +0200 Subject: add filter crud bindings --- lisp/mastodon-views.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 411d2d2..f033d3c 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -92,6 +92,11 @@ (define-key map (kbd "d") #'mastodon-views--delete-filter) (define-key map (kbd "c") #'mastodon-views--create-filter) (define-key map (kbd "g") #'mastodon-views--view-filters) + (define-key map (kbd "u") #'mastodon-views--update-filter) + (define-key map (kbd "k") #'mastodon-views--delete-filter) + (define-key map (kbd "a") #'mastodon-views--add-filter-kw) + (define-key map (kbd "r") #'mastodon-views--remove-filter-kw) + (define-key map (kbd "U") #'mastodon-views--update-filter-kw) map) "Keymap for viewing filters.") @@ -584,8 +589,9 @@ NO-CONFIRM means there is no ask or message, there is only do." 'mastodon-views--insert-filters nil nil nil "current filters" - "c - create filter\n d - delete filter at point\n\ - n/p - go to next/prev filter" "v2") + "c - create filter | d/k - delete filter at point\n\ + u - update filter\n a/r/U - add/remove/Update filter keyword\n + n/p - next/prev filter" "v2") (with-current-buffer "*mastodon-filters*" (use-local-map mastodon-views--view-filters-keymap))) @@ -604,7 +610,7 @@ JSON is the filters data." "–" "-")) (whole-str "whole-words-only:")) - (insert (concat "Terms: | " whole-str "\n")) + (insert (concat "Keywords: | " whole-str "\n")) (mapc (lambda (kw) (let ((whole (if (eq :json-false (alist-get 'whole_word kw)) "nil" -- cgit v1.2.3 From 8b82c650c5ec3286aa05b3a04d8ae09350c9d26e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 11:52:17 +0200 Subject: filters binding string / newlines --- lisp/mastodon-views.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index f033d3c..c3c372d 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -589,8 +589,8 @@ NO-CONFIRM means there is no ask or message, there is only do." 'mastodon-views--insert-filters nil nil nil "current filters" - "c - create filter | d/k - delete filter at point\n\ - u - update filter\n a/r/U - add/remove/Update filter keyword\n + "c/u - create/update filter | d/k - delete filter\ + at point\n a/r/U - add/remove/Update filter keyword\n\ n/p - next/prev filter" "v2") (with-current-buffer "*mastodon-filters*" (use-local-map mastodon-views--view-filters-keymap))) @@ -604,7 +604,7 @@ JSON is the filters data." (defun mastodon-views--insert-filter-kws (kws) "Insert filter keywords KWS." - (insert "\n\n") + (insert "\n") (let ((beg (point)) (table-cell-horizontal-chars (if (char-displayable-p ?–) ; ?– ?-) "–" -- cgit v1.2.3 From 248eead48f10f96dafa21463064a297809df6ca9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 11:57:28 +0200 Subject: create filter cleanup --- lisp/mastodon-views.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index c3c372d..5480e09 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -674,11 +674,11 @@ Prompt for a context, must be a list containting at least one of \"home\", \"notifications\", \"public\", \"thread\". Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (interactive) - (let* ((url (if id - (mastodon-http--api-v2 (format "filters/%s" id)) - (mastodon-http--api-v2 "filters"))) + (let* ((url (mastodon-http--api-v2 + (if id (format "filters/%s" id) "filters"))) (title (or title (read-string "Filter name: "))) - (terms (or terms (read-string "Terms to filter (comma or space separated): "))) + (terms (or terms + (read-string "Terms to filter (comma or space separated): "))) (terms-split (split-string terms "[, ]")) (terms-processed (if (not terms) @@ -708,7 +708,7 @@ Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (mastodon-http--post url params)))) (mastodon-views--filters-triage resp - (message "Filter %s created!" title)))) + (message "Filter %s %s!" title (if id "updated" "created"))))) (defun mastodon-views--update-filter () "Update filter at point." -- cgit v1.2.3 From c0714fdc408b0c6e482967d1eb5b2c5f26216215 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 12:05:22 +0200 Subject: filter props --- lisp/mastodon-views.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 5480e09..cdebc6e 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -645,9 +645,6 @@ JSON is the filters data." (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " (propertize (upcase .title) - 'item-id .id - 'item-type 'filter - 'filter-title .title 'byline t) " " "\n" " " mastodon-tl--horiz-bar "\n") @@ -659,6 +656,7 @@ JSON is the filters data." (concat "\nType: " .filter_action)) 'item-json filter 'item-id .id + 'filter-title .title 'item-type 'filter)) ;; terms list: (if (not .keywords) ;; poss to have a filter sans keywords -- cgit v1.2.3 From 9ba2b21fc391a1d732689e1dd06fe66fd0c6d8af Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 18:35:14 +0200 Subject: filters: fix no keywords check --- lisp/mastodon-views.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index cdebc6e..e47e0dc 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -659,8 +659,7 @@ JSON is the filters data." 'filter-title .title 'item-type 'filter)) ;; terms list: - (if (not .keywords) ;; poss to have a filter sans keywords - "" + (when .keywords ;; poss to have no keywords (mastodon-views--insert-filter-kws .keywords)))) (defvar mastodon-views--filter-types -- cgit v1.2.3 From 404f004a2ad9b81542571ec785fdbd948b9b2ee1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 18:35:24 +0200 Subject: filters: hack to fix nav --- lisp/mastodon-views.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index e47e0dc..cce43fc 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -639,22 +639,26 @@ JSON is the filters data." "Insert a single FILTER." (let-alist filter (insert + ;; FIXME: awful hack to fix nav: exclude horiz-bar from propertize then + ;; propertize rest of the filter text. if we add only byline prop to + ;; title, point will move to end of title, because at that byline-prop + ;; change, item-type prop is present. + (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n ") + 'success) (propertize (concat ;; heading: (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n " - (propertize (upcase .title) - 'byline t) - " " "\n" - " " mastodon-tl--horiz-bar "\n") + (concat (upcase .title) " " "\n " + mastodon-tl--horiz-bar "\n") 'success) ;; context: - (concat "Context: " - (mapconcat #'identity .context ", ")) + (concat "Context: " (mapconcat #'identity .context ", ")) ;; type (warn or hide): (concat "\nType: " .filter_action)) 'item-json filter + 'byline t 'item-id .id 'filter-title .title 'item-type 'filter)) -- cgit v1.2.3 From 0007f7daf8c6acf8611e3203e125c4785f58f4cd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Aug 2024 18:45:46 +0200 Subject: tiny audit of filters v2 code --- lisp/mastodon-views.el | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index cce43fc..ef91bd0 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -606,10 +606,10 @@ JSON is the filters data." "Insert filter keywords KWS." (insert "\n") (let ((beg (point)) - (table-cell-horizontal-chars (if (char-displayable-p ?–) ; ?– ?-) + (table-cell-horizontal-chars (if (char-displayable-p ?–) "–" "-")) - (whole-str "whole-words-only:")) + (whole-str "whole words only:")) (insert (concat "Keywords: | " whole-str "\n")) (mapc (lambda (kw) (let ((whole (if (eq :json-false (alist-get 'whole_word kw)) @@ -675,6 +675,7 @@ Prompt for a context, must be a list containting at least one of \"home\", \"notifications\", \"public\", \"thread\". Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (interactive) + ;; ID non-nil = we are updating (let* ((url (mastodon-http--api-v2 (if id (format "filters/%s" id) "filters"))) (title (or title (read-string "Filter name: "))) @@ -682,26 +683,23 @@ Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (read-string "Terms to filter (comma or space separated): "))) (terms-split (split-string terms "[, ]")) (terms-processed - (if (not terms) - (user-error "You must select at least one term to filter") + (if (not terms) ;; well actually it is poss to have no terms + (user-error "You must select at least one term") (mastodon-http--build-array-params-alist "keywords_attributes[][keyword]" terms-split))) (warn-or-hide - (or type - (completing-read "Warn (like CW) or hide? " - '("warn" "hide") nil :match))) + (or type (completing-read "Warn (like CW) or hide? " + '("warn" "hide") nil :match))) (contexts - (or context - (completing-read-multiple - "Filter contexts [TAB for options, comma separated]: " - mastodon-views--filter-types nil :match))) + (or context (completing-read-multiple + "Filter contexts [TAB for options, comma separated]: " + mastodon-views--filter-types nil :match))) (contexts-processed (if (not contexts) - (user-error "You must select at least one context for a filter") + (user-error "You must select at least one context") (mastodon-http--build-array-params-alist "context[]" contexts))) (params (append `(("title" . ,title) ("filter_action" . ,warn-or-hide)) - ;; ("keywords_attributes[][whole_word]" . "false")) terms-processed contexts-processed)) (resp (if id @@ -730,7 +728,6 @@ Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (terms (read-string "Terms to add (comma or space separated): "))) (mastodon-views--create-filter id name contexts type terms)))) - (defun mastodon-views--delete-filter () "Delete filter at point." (interactive) -- cgit v1.2.3 From beeb8f3b2ebe25e8e3fb92e6f030cec39b818cec Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 22 Aug 2024 11:06:07 +0200 Subject: eq for symbols, string= for strings --- lisp/mastodon-async.el | 16 +++++++------- lisp/mastodon-auth.el | 4 ++-- lisp/mastodon-client.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-media.el | 4 ++-- lisp/mastodon-notifications.el | 40 ++++++++++++++++----------------- lisp/mastodon-profile.el | 8 +++---- lisp/mastodon-search.el | 28 +++++++++++------------ lisp/mastodon-tl.el | 50 +++++++++++++++++++++--------------------- lisp/mastodon-toot.el | 34 ++++++++++++++-------------- lisp/mastodon-views.el | 8 +++---- 11 files changed, 98 insertions(+), 98 deletions(-) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 0c70560..317be93 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -88,7 +88,7 @@ (delete-process (get-buffer-process mastodon-async--http-buffer)) (kill-buffer mastodon-async--http-buffer) (setq mastodon-async--http-buffer "") - (when (not (equal "" mastodon-async--queue)) ; error handle on kill async buffer + (when (not (string= "" mastodon-async--queue)) ; error handle on kill async buffer (kill-buffer mastodon-async--queue)))) (defun mastodon-async--stream-notifications () @@ -207,8 +207,8 @@ ENDPOINT is the endpoint for the stream and timeline." ;; if user stream, we need "timelines/home" not "timelines/user" ;; if notifs, we need "notifications" not "timelines/notifications" (endpoint (cond - ((equal name "notifications") "notifications") - ((equal name "home") "timelines/home") + ((string= name "notifications") "notifications") + ((string= name "home") "timelines/home") (t (format "timelines/%s" endpoint))))) (mastodon-async--set-local-variables buffer-name http-buffer buffer-name queue-name) @@ -218,7 +218,7 @@ ENDPOINT is the endpoint for the stream and timeline." (make-local-variable 'mastodon-tl--enable-relative-timestamps) (make-local-variable 'mastodon-tl--display-media-p) (message (mastodon-http--api endpoint)) - (if (equal name "notifications") + (if (string= name "notifications") (mastodon-notifications--timeline (mastodon-http--get-json (mastodon-http--api "notifications"))) @@ -227,7 +227,7 @@ ENDPOINT is the endpoint for the stream and timeline." (mastodon-mode) (mastodon-tl--set-buffer-spec buffer-name endpoint - (if (equal name "notifications") + (if (string= name "notifications") 'mastodon-notifications--timeline 'mastodon-tl--timeline)) (setq-local mastodon-tl--enable-relative-timestamps nil) @@ -275,7 +275,7 @@ NAME is used for the queue and display buffer." (car split-strings))) (data (replace-regexp-in-string "^data: " "" (cadr split-strings)))) - (when (equal "update" event-type) + (when (string= "update" event-type) ;; in some casses the data is not fully formed ;; for now return nil if malformed using `ignore-errors' (ignore-errors (json-read-from-string data))))))) @@ -289,7 +289,7 @@ NAME is used for the queue and display buffer." (car split-strings))) (data (replace-regexp-in-string "^data: " "" (cadr split-strings)))) - (when (equal "notification" event-type) + (when (string= "notification" event-type) ;; in some casses the data is not fully formed ;; for now return nil if malformed using `ignore-errors' (ignore-errors (json-read-from-string data))))) @@ -324,7 +324,7 @@ NAME is used for the queue and display buffer." mastodon-instance-url "*")) (mastodon-notifications--timeline (list toot)) (mastodon-tl--timeline (list toot))) - (if (equal previous 1) + (if (eq previous 1) (goto-char 1) (goto-char (+ previous (- (point-max) old-max))))))))) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 404dd57..3796b7e 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -173,13 +173,13 @@ When ASK is absent return nil." Generate/save token if none known yet." (cond (mastodon-auth--token-alist ;; user variables are known and initialised. - (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil #'equal)) + (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil #'string=)) ((plist-get (mastodon-client--active-user) :access_token) ;; user variables need to be read from plstore. (push (cons mastodon-instance-url (plist-get (mastodon-client--active-user) :access_token)) mastodon-auth--token-alist) - (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil #'equal)) + (alist-get mastodon-instance-url mastodon-auth--token-alist nil nil #'string=)) ((null mastodon-active-user) ;; user not aware of 2FA-related changes and has not set ;; `mastodon-active-user'. Make user aware and error out. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 493f9df..6e55829 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -174,7 +174,7 @@ Otherwise return nil." (let ((username (mastodon-client--form-user-from-vars)) (user-details (mastodon-client--general-read "active-user"))) (when (and user-details - (equal (plist-get user-details :username) username)) + (string= (plist-get user-details :username) username)) user-details))) (defun mastodon-client--active-user () diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 39c1036..fbae8a7 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -365,7 +365,7 @@ item uploaded, and `mastodon-toot--update-status-fields' is run." ;; this is how the mangane akkoma web client does it ;; and it seems easier than the other options! (when (and caption - (not (equal caption (alist-get 'description data)))) + (not (string= caption (alist-get 'description data)))) (let ((url (mastodon-http--api (format "media/%s" id)))) ;; (message "PUTting image description") (mastodon-http--put url desc))) diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 620aa51..2ec498e 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -449,8 +449,8 @@ Replace them with the referenced image." (put-text-property start end 'media-state 'loading) (mastodon-media--load-image-from-url image-url media-type start (- end start)) - (when (or (equal type "gifv") - (equal type "video")) + (when (or (string= type "gifv") + (string= type "video")) (mastodon-media--moving-image-overlay start end)))))))) ;; (defvar-local mastodon-media--overlays nil diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1b93f1b..1c2aad7 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -204,7 +204,7 @@ Status notifications are given when ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' (let* ((id (alist-get 'id note)) (profile-note - (when (equal 'follow-request type) + (when (eq 'follow-request type) (let ((str (mastodon-tl--field 'note (mastodon-tl--field 'account note)))) @@ -221,15 +221,15 @@ Status notifications are given when nil (mastodon-tl--insert-status ;; toot - (cond ((or (equal type 'follow) - (equal type 'follow-request)) + (cond ((or (eq type 'follow) + (eq type 'follow-request)) ;; Using reblog with an empty id will mark this as something ;; non-boostable/non-favable. (cons '(reblog (id . nil)) note)) ;; reblogs/faves use 'note' to process their own json ;; not the toot's. this ensures following etc. work on such notifs - ((or (equal type 'favourite) - (equal type 'boost)) + ((or (eq type 'favourite) + (eq type 'boost)) note) (t status)) @@ -239,12 +239,12 @@ Status notifications are given when (mastodon-tl--clean-tabs-and-nl (if (mastodon-tl--has-spoiler status) (mastodon-tl--spoiler status) - (if (equal 'follow-request type) + (if (eq 'follow-request type) (mastodon-tl--render-text profile-note) (mastodon-tl--content status))))))) (cond ((or (eq type 'follow) (eq type 'follow-request)) - (if (equal type 'follow) + (if (eq type 'follow) (propertize "Congratulations, you have a new follower!" 'face 'default) (concat @@ -261,35 +261,35 @@ Status notifications are given when (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline - (if (or (equal type 'follow) - (equal type 'follow-request) - (equal type 'mention)) + (if (or (eq type 'follow) + (eq type 'follow-request) + (eq type 'mention)) 'mastodon-tl--byline-author (lambda (_status &rest _args) ; unbreak stuff (mastodon-tl--byline-author note))) ;; action-byline (lambda (_status) (mastodon-notifications--byline-concat - (cond ((equal type 'boost) + (cond ((eq type 'boost) "Boosted") - ((equal type 'favourite) + ((eq type 'favourite) "Favourited") - ((equal type 'follow-request) + ((eq type 'follow-request) "Requested to follow") - ((equal type 'follow) + ((eq type 'follow) "Followed") - ((equal type 'mention) + ((eq type 'mention) "Mentioned") - ((equal type 'status) + ((eq type 'status) "Posted") - ((equal type 'poll) + ((eq type 'poll) "Posted a poll") - ((equal type 'edit) + ((eq type 'edit) "Edited")))) id ;; base toot - (when (or (equal type 'favourite) - (equal type 'boost)) + (when (or (eq type 'favourite) + (eq type 'boost)) status))))) (defun mastodon-notifications--by-type (note) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5f33ce2..6410591 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -592,7 +592,7 @@ FIELDS means provide a fields vector fetched by other means." "T if you have any relationship with the accounts in LIST." (let (result) (dolist (x list result) - (when (not (equal :json-false x)) + (when (not (eq :json-false x)) (setq result x))))) (defun mastodon-profile--render-roles (roles) @@ -735,7 +735,7 @@ MAX-ID is a flag to include the max_id pagination parameter." (setq mastodon-tl--update-point (point)) (mastodon-media--inline-images (point-min) (point)) ;; insert pinned toots first - (when (and pinned (equal endpoint-type "statuses")) + (when (and pinned (string= endpoint-type "statuses")) (mastodon-profile--insert-statuses-pinned pinned) (setq mastodon-tl--update-point (point))) ; updates after pinned toots (funcall update-function json)) @@ -767,7 +767,7 @@ MAX-ID is a flag to include the max_id pagination parameter." "Return a avatar image from ACCOUNT. IMG-TYPE is the JSON key from the account data." (let ((img (alist-get img-type account))) - (unless (equal img "/avatars/original/missing.png") + (unless (string= img "/avatars/original/missing.png") (mastodon-media--get-media-link-rendering img)))) (defun mastodon-profile--show-user (user-handle) @@ -784,7 +784,7 @@ IMG-TYPE is the JSON key from the account data." nil ; predicate 'confirm))))) (if (not (or ; own profile has no need for item-json test: - (equal user-handle (mastodon-auth--get-account-name)) + (string= user-handle (mastodon-auth--get-account-name)) (mastodon-tl--profile-buffer-p) (mastodon-tl--property 'item-json :no-move))) (user-error "Looks like there's no toot or user at point?") diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index f51247b..7fc4de3 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -66,7 +66,7 @@ Returns a nested list containing user handle, display name, and URL." (mastodon-http--get-json url `(("q" . ,query) ;; NB: nil can break params (but works for me) - ,(when (equal "following" + ,(when (string= "following" mastodon-toot--completion-style-for-mentions) '("following" . "true"))) :silent))) @@ -103,7 +103,7 @@ TYPE is a string, either tags, statuses, or links. PRINT-FUN is the function used to print the data from the response." (let* ((url (mastodon-http--api (format "trends/%s" type))) ;; max for statuses = 40, for others = 20 - (limit (if (equal type "statuses") + (limit (if (string= type "statuses") '("limit" . "40") '("limit" . "20"))) (offset '(("offset" . "0"))) @@ -116,7 +116,7 @@ PRINT-FUN is the function used to print the data from the response." print-fun nil params) (mastodon-search--insert-heading "trending" type) (funcall print-fun data) - (unless (equal type "statuses") + (unless (string= type "statuses") (goto-char (point-min)))))) ;; functions for mastodon search @@ -153,10 +153,10 @@ is used for pagination." ;; TODO: handle no results (interactive "sSearch mastodon for: ") (let* ((url (mastodon-http--api-v2 "search")) - (following (when (or following (equal current-prefix-arg '(4))) + (following (when (or following (eq current-prefix-arg '(4))) "true")) (type (or type - (if (equal current-prefix-arg '(4)) + (if (eq current-prefix-arg '(4)) "accounts" ; if FOLLOWING, must be "accounts" (completing-read "Search type: " mastodon-search-types nil :match)))) @@ -175,15 +175,15 @@ is used for pagination." (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-search-mode) (mastodon-search--insert-heading type) - (cond ((equal type "accounts") + (cond ((string= type "accounts") (mastodon-search--render-response items type buffer params 'mastodon-views--insert-users-propertized-note 'mastodon-views--insert-users-propertized-note)) - ((equal type "hashtags") + ((string= type "hashtags") (mastodon-search--render-response items type buffer params 'mastodon-search--print-tags 'mastodon-search--print-tags)) - ((equal type "statuses") + ((string= type "statuses") (mastodon-search--render-response items type buffer params #'mastodon-tl--timeline #'mastodon-tl--timeline))) @@ -213,19 +213,19 @@ BUFFER, PARAMS, and UPDATE-FUN are for `mastodon-tl--buffer-spec'." "Return search buffer type, a member of `mastodon-search-types'." ;; called in `mastodon-tl--get-buffer-type' (let* ((spec (mastodon-tl--buffer-property 'update-params))) - (alist-get "type" spec nil nil #'equal))) + (alist-get "type" spec nil nil #'string=))) (defun mastodon-search--query-cycle () "Cycle through search types: accounts, hashtags, and statuses." (interactive) (let* ((spec (mastodon-tl--buffer-property 'update-params)) - (type (alist-get "type" spec nil nil #'equal)) - (query (alist-get "q" spec nil nil #'equal))) - (cond ((equal type "hashtags") + (type (alist-get "type" spec nil nil #'string=)) + (query (alist-get "q" spec nil nil #'string=))) + (cond ((string= type "hashtags") (mastodon-search--query query "accounts")) - ((equal type "accounts") + ((string= type "accounts") (mastodon-search--query query "statuses")) - ((equal type "statuses") + ((string= type "statuses") (mastodon-search--query query "hashtags"))))) (defun mastodon-search--query-accounts-followed (query) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2c1ef43..f400cc1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -574,7 +574,7 @@ Do so if type of status at poins is not follow_request/follow." (let ((type (alist-get 'type (mastodon-tl--property 'item-json :no-move))) (echo (mastodon-tl--property 'help-echo :no-move))) - (when (not (equal "" echo)) ; not for followers/following in profile + (when (not (string= "" echo)) ; not for followers/following in profile (unless (or (string= type "follow_request") (string= type "follow")) ; no counts for these (message "%s" echo))))) @@ -682,11 +682,11 @@ The result is added as an attachments property to author-byline." (defun mastodon-tl--format-faved-or-boosted-byline (letter) "Format the byline marker for a boosted or favourited status. LETTER is a string, F for favourited, B for boosted, or K for bookmarked." - (let ((help-string (cond ((equal letter "F") + (let ((help-string (cond ((string= letter "F") "favourited") - ((equal letter "B") + ((string= letter "B") "boosted") - ((equal letter (or "🔖" "K")) + ((string= letter (or "🔖" "K")) "bookmarked")))) (format "(%s) " (propertize letter 'face 'mastodon-boost-fave-face @@ -761,10 +761,10 @@ BASE-TOOT is JSON for the base toot, if any." ;; in `mastodon-tl--byline-author' (funcall author-byline toot nil domain) ;; visibility: - (cond ((equal visibility "direct") + (cond ((string= visibility "direct") (propertize (concat " " (mastodon-tl--symbol 'direct)) 'help-echo visibility)) - ((equal visibility "private") + ((string= visibility "private") (propertize (concat " " (mastodon-tl--symbol 'private)) 'help-echo visibility))) ;;action byline: @@ -1097,11 +1097,11 @@ content should be hidden." (user-error "Not in a thread") (save-excursion (goto-char (point-min)) - (while (not (equal "No more items" ; improve this hack test! + (while (not (string= "No more items" ; improve this hack test! (mastodon-tl--goto-next-item :no-refresh))) (let* ((json (mastodon-tl--property 'item-json :no-move)) (cw (alist-get 'spoiler_text json))) - (when (not (equal "" cw)) + (when (not (string= "" cw)) (mastodon-tl--toggle-spoiler-text-in-toot)))))))) (defun mastodon-tl--spoiler (toot &optional filter) @@ -1439,8 +1439,8 @@ EVENT is a mouse-click arg." "T if mastodon-media-type prop is \"gifv\" or \"video\". TYPE is a mastodon media type." (let ((type (or type (mastodon-tl--property 'mastodon-media-type :no-move)))) - (or (equal type "gifv") - (equal type "video")))) + (or (string= type "gifv") + (string= type "video")))) (defun mastodon-tl--mpv-play-video-at-point (&optional url type) "Play the video or gif at point with an mpv process. @@ -1767,13 +1767,13 @@ To disable showing the stats, customize (replies (format "%s %s" .replies_count (mastodon-tl--symbol 'reply))) (stats (concat (propertize faves - 'favourited-p (eq 't .favourited) + 'favourited-p (eq t .favourited) 'favourites-field t 'help-echo (format "%s favourites" .favourites_count) 'face 'font-lock-comment-face) (propertize " | " 'face 'font-lock-comment-face) (propertize boosts - 'boosted-p (eq 't .reblogged) + 'boosted-p (eq t .reblogged) 'boosts-field t 'help-echo (format "%s boosts" .reblogs_count) 'face 'font-lock-comment-face) @@ -1929,11 +1929,11 @@ call this function after it is set or use something else." 'preferences) ;; search ((mastodon-tl--search-buffer-p) - (cond ((equal "accounts" (mastodon-search--buf-type)) + (cond ((string= "accounts" (mastodon-search--buf-type)) 'search-accounts) - ((equal "hashtags" (mastodon-search--buf-type)) + ((string= "hashtags" (mastodon-search--buf-type)) 'search-hashtags) - ((equal "statuses" (mastodon-search--buf-type)) + ((string= "statuses" (mastodon-search--buf-type)) 'search-statuses))) ;; trends ((mastodon-tl--endpoint-str-= "trends/statuses") @@ -1993,7 +1993,7 @@ We hide replies if user explictly set the timeline." (and (mastodon-tl--timeline-proper-p) ; Only if we are in a proper timeline (or mastodon-tl--hide-replies ; User configured to hide replies - (equal '(4) prefix)))) ; Timeline called with C-u prefix + (eq '(4) prefix)))) ; Timeline called with C-u prefix ;;; UTILITIES @@ -2107,7 +2107,7 @@ ID is that of the toot to view." (let* ((buffer (format "*mastodon-toot-%s*" id)) (toot (mastodon-http--get-json (mastodon-http--api (concat "statuses/" id))))) - (if (equal (caar toot) 'error) + (if (eq (caar toot) 'error) (user-error "Error: %s" (cdar toot)) (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer (format "statuses/%s" id) @@ -2152,7 +2152,7 @@ view all branches of a thread." (mastodon-http--api (concat "statuses/" id)) nil :silent)) (context (mastodon-http--get-json url nil :silent))) - (if (equal (caar toot) 'error) + (if (eq (caar toot) 'error) (user-error "Error: %s" (cdar toot)) (when (member (alist-get 'type toot) '("reblog" "favourite")) (setq toot (alist-get 'status toot))) @@ -2291,7 +2291,7 @@ desired language if they are not marked as such (or as anything)." (interactive (list (mastodon-tl--user-handles-get "filter by language"))) (let ((langs (mastodon-tl--read-filter-langs))) (mastodon-tl--do-if-item - (if (equal "" (cdar langs)) + (if (string= "" (cdar langs)) (mastodon-tl--unfilter-user-languages user-handle) (mastodon-tl--follow-user user-handle nil langs))))) @@ -2465,7 +2465,7 @@ ARGS is an alist of any parameters to send with the request." (mastodon-http--process-json)))) ;; TODO: when > if, with failure msg (cond ((string= notify "true") - (when (eq 't (alist-get 'notifying json)) + (when (eq t (alist-get 'notifying json)) (message "Receiving notifications for user %s (@%s)!" name user-handle))) ((string= notify "false") @@ -2473,7 +2473,7 @@ ARGS is an alist of any parameters to send with the request." (message "Not receiving notifications for user %s (@%s)!" name user-handle))) ((string= reblogs "true") - (when (eq 't (alist-get 'showing_reblogs json)) + (when (eq t (alist-get 'showing_reblogs json)) (message "Receiving boosts by user %s (@%s)!" name user-handle))) ((string= reblogs "false") @@ -2483,14 +2483,14 @@ ARGS is an alist of any parameters to send with the request." ((or (string= action "mute") (string= action "unmute")) (message "User %s (@%s) %sd!" name user-handle action)) - ((equal args "languages[]") + ((string= args "languages[]") (message "User %s language filters removed!" name)) - ((assoc "languages[]" args #'equal) + ((assoc "languages[]" args #'string=) (message "User %s filtered by language(s): %s" name (mapconcat #'cdr args " "))) ((and (eq notify nil) (eq reblogs nil)) - (if (and (equal action "follow") + (if (and (string= action "follow") (eq t (alist-get 'requested json))) (message "Follow requested for user %s (@%s)!" name user-handle) (message "User %s (@%s) %sed!" name user-handle action))))))))) @@ -3092,7 +3092,7 @@ JSON and http headers, without it just the JSON." ;; so as a fallback, load trending statuses: ;; FIXME: this could possibly be a fallback for all timelines not ;; just home? - (when (equal endpoint "timelines/home") + (when (string= endpoint "timelines/home") (mastodon-search--trending-statuses))) ((eq (caar json) 'error) (user-error "Looks like the server bugged out: \"%s\"" (cdar json))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 5f4116f..762c313 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -284,7 +284,7 @@ data about the item boosted or favourited." Includes boosts, and notifications that display toots. This macro makes the local variable ID available." (declare (debug t)) - `(if (not (equal 'toot (mastodon-tl--property 'item-type :no-move))) + `(if (not (eq 'toot (mastodon-tl--property 'item-type :no-move))) (user-error "Looks like there's no toot at point?") (mastodon-tl--with-toot-helper (lambda (id) @@ -409,12 +409,12 @@ ACTION is a symbol, either `favourite' or `boost.'" ;; there's nothing wrong with faving/boosting own toots ;; & nothing wrong with faving/boosting own toots from notifs, ;; it boosts/faves the base toot, not the notif status - ((or (equal n-type "follow") - (equal n-type "follow_request")) + ((or (string= n-type "follow") + (string= n-type "follow_request")) (user-error "Can't %s %s notifications" action n-type)) ((and boost-p - (or (equal vis "direct") - (equal vis "private"))) + (or (string= vis "direct") + (string= vis "private"))) (user-error "Can't boost posts with visibility: %s" vis)) (t (let* ((boosted (when byline-region @@ -491,8 +491,8 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement." (bookmarked-p (when byline-region (get-text-property (car byline-region) 'bookmarked-p))) (action (if bookmarked-p "unbookmark" "bookmark"))) - (cond ((or (equal n-type "follow") - (equal n-type "follow_request")) + (cond ((or (string= n-type "follow") + (string= n-type "follow_request")) (user-error "Can't bookmark %s notifications" n-type)) ((not byline-region) (user-error "Nothing to %s here?!?" action)) @@ -595,8 +595,8 @@ Uses `lingva.el'." ;; this check needs to allow acting on own toots displayed as boosts, so we ;; call `mastodon-tl--toot-or-base'. (let ((json (mastodon-tl--toot-or-base toot))) - (equal (alist-get 'acct (alist-get 'account json)) - (mastodon-auth--user-acct)))) + (string= (alist-get 'acct (alist-get 'account json)) + (mastodon-auth--user-acct)))) (defun mastodon-toot--pin-toot-toggle () "Pin or unpin user's toot at point." @@ -717,7 +717,7 @@ CANCEL means the toot was not sent, so we save the toot text as a draft." (unless (eq mastodon-toot-current-toot-text nil) (when cancel (cl-pushnew mastodon-toot-current-toot-text - mastodon-toot-draft-toots-list :test 'equal))) + mastodon-toot-draft-toots-list :test #'string=))) ;; prevent some weird bug when cancelling a non-empty toot: (delete #'mastodon-toot--save-toot-text after-change-functions) (quit-window 'kill) @@ -931,7 +931,7 @@ instance to edit a toot." ;; (we don't reload in every case as it can be slow and we may ;; lose our place in a timeline.) (when (or edit-id - (equal 'thread (mastodon-tl--get-buffer-type))) + (eq 'thread (mastodon-tl--get-buffer-type))) (let ((pos (marker-position (cadr prev-window-config)))) (mastodon-tl--reload-timeline-or-profile pos)))))))))) @@ -1175,7 +1175,7 @@ prefixed by >." (alist-get 'account toot)))) (mentions (cond ((and booster ;; different booster, user and mentions: - (and (not (equal user booster)) + (and (not (string= user booster)) (not (member booster mentions)))) (mastodon-toot--mentions-to-string (append (list user booster) mentions nil))) @@ -1228,7 +1228,7 @@ Return its two letter ISO 639 1 code." (let* ((choice (completing-read "Language for this toot: " mastodon-iso-639-1))) (setq mastodon-toot--language - (alist-get choice mastodon-iso-639-1 nil nil 'equal)) + (alist-get choice mastodon-iso-639-1 nil nil #'string=)) (message "Language set to %s" choice) (mastodon-toot--update-status-fields))) @@ -1419,7 +1419,7 @@ Return a cons of a human readable string, and a seconds-from-now string." (let* ((options (mastodon-toot--poll-expiry-options-alist)) (response (completing-read "poll ends in [or enter seconds]: " options nil 'confirm))) - (or (assoc response options #'equal) + (or (assoc response options #'string=) (if (< (string-to-number response) 600) (car options))))) ;; min 5 mins @@ -1718,7 +1718,7 @@ REPLY-REGION is a string to be injected into the buffer." (mastodon-toot--render-reply-region-str reply-region) "\n")) (setq mastodon-toot--reply-to-id reply-to-id) - (unless (equal mastodon-toot--visibility reply-visibility) + (unless (string= mastodon-toot--visibility reply-visibility) (setq mastodon-toot--visibility reply-visibility)) (mastodon-toot--set-cw reply-cw)))) @@ -1752,7 +1752,7 @@ REPLY-REGION is a string to be injected into the buffer." (mastodon-toot--apply-fields-props vis-region (format "%s" - (if (equal "private" mastodon-toot--visibility) + (if (string= "private" mastodon-toot--visibility) "followers-only" mastodon-toot--visibility))) ;; WHEN clauses don't work here, we need "" as display arg: @@ -1783,7 +1783,7 @@ REPLY-REGION is a string to be injected into the buffer." (mastodon-toot--apply-fields-props cw-region (if (and mastodon-toot--content-warning - (not (equal "" mastodon-toot--content-warning))) + (not (string= "" mastodon-toot--content-warning))) (format "CW: %s" mastodon-toot--content-warning) " ") ;; hold the blank space 'mastodon-cw-face)))) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index ef91bd0..989a614 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -766,7 +766,7 @@ When t, whole words means only match whole words." "false")) (params `(("keyword" . ,updated) ("whole_word" . ,whole-word))) - (id (cdr (assoc choice alist #'equal))) + (id (cdr (assoc choice alist #'string=))) (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) (resp (mastodon-http--put url params))) (mastodon-views--filters-triage resp @@ -807,7 +807,7 @@ When t, whole words means only match whole words." (mastodon-tl--property 'item-json :no-move))) (alist (mastodon-tl--map-alist-vals-to-alist 'keyword 'id kws)) (choice (completing-read "Remove keyword: " alist)) - (id (cdr (assoc choice alist #'equal))) + (id (cdr (assoc choice alist #'string=))) (url (mastodon-http--api-v2 (format "filters/keywords/%s" id))) (resp (mastodon-http--delete url))) (mastodon-views--filters-triage resp (format "Keyword %s removed!" choice))))) @@ -1022,9 +1022,9 @@ IND is the optional indentation level to print at." (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) + (let ((val (cond ((eq (cdr el) :json-false) "no") - ((equal (cdr el) 't) + ((eq (cdr el) t) "yes") (t (cdr el))))) -- cgit v1.2.3 From 4a6200be2e98b68e0869400ae21f89f2c1fa618a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 16 Sep 2024 08:54:11 +0200 Subject: filter lists like "home". FIX #575. --- lisp/mastodon-tl.el | 2 ++ lisp/mastodon-views.el | 1 + 2 files changed, 3 insertions(+) (limited to 'lisp/mastodon-views.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3e488f0..0e98015 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1608,6 +1608,8 @@ Returns a member of `mastodon-views--filter-types'." "public") ((mastodon-tl--profile-buffer-p) "profile") + ((eq buf 'list-timeline) + "home") ;; lists are "home" filter (t ;; thread, notifs, home: (symbol-name buf))))) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 989a614..ac62b1f 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -690,6 +690,7 @@ Optionally, provide ID, TITLE, CONTEXT, TYPE, and TERMS to update a filter." (warn-or-hide (or type (completing-read "Warn (like CW) or hide? " '("warn" "hide") nil :match))) + ;; TODO: display "home (and lists)" but just use "home" for API (contexts (or context (completing-read-multiple "Filter contexts [TAB for options, comma separated]: " -- cgit v1.2.3