From 2a3255c48f8e3538a7604d96ebadb9e21b0b9c50 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 20 Sep 2024 20:40:47 +0200 Subject: bump version --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 3eff126..faeae61 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -6,7 +6,7 @@ ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -;; Version: 1.0.24 +;; Version: 1.0.27 ;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) ;; Homepage: https://codeberg.org/martianh/mastodon.el -- cgit v1.2.3 From db078f72b7d176f18e24792e93319322b02795bb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 1 Oct 2024 22:20:45 +0200 Subject: rewrite http--patch (+ json confusion) --- lisp/mastodon-http.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index fbae8a7..546d5bd 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -298,11 +298,26 @@ Optionally specify the PARAMS to send." (with-current-buffer (mastodon-http--patch url params) (mastodon-http--process-json))) -(defun mastodon-http--patch (base-url &optional params) - "Make synchronous PATCH request to BASE-URL. +(defun mastodon-http--patch (url &optional params json) + "Make synchronous PATCH request to URL. Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" - (let ((url (mastodon-http--concat-params-to-url base-url params))) + ;; NB: unlike POST, PATCHing only works if we use query params! + ;; so here, unless JSON arg, we use query params and do not set + ;; `url-request-data'. this is probably an error, i don't understand it. + (let* ((url-request-data + (when (and params json) + (encode-coding-string + (json-encode params) 'utf-8))) + ;; (mastodon-http--build-params-string params)))) + (url (unless json + (mastodon-http--concat-params-to-url url params))) + (headers (when json + '(("Content-Type" . "application/json") + ("Accept" . "application/json")))) + (url-request-extra-headers + (append url-request-extra-headers headers))) + (message "Data: %s" url-request-data) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions -- cgit v1.2.3 From 2487b589292976f830325eea39765beb44e4036a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 1 Oct 2024 22:21:32 +0200 Subject: http--post: if :json, supply required headers --- lisp/mastodon-http.el | 10 ++++++---- lisp/mastodon-profile.el | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 546d5bd..c1b0599 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -157,16 +157,18 @@ the request data. If it is :raw, just use the plain params." (let* ((url-request-data (when params (cond ((eq json :json) - (json-encode - params)) + (json-encode params)) ((eq json :raw) params) (t (mastodon-http--build-params-string params))))) (url-request-extra-headers (append url-request-extra-headers ; auth set in macro - (unless (assoc "Content-Type" headers) ; pleroma compat: - '(("Content-Type" . "application/x-www-form-urlencoded"))) + (if json + '(("Content-Type" . "application/json") + ("Accept" . "application/json")) + (unless (assoc "Content-Type" headers) ; pleroma compat: + '(("Content-Type" . "application/x-www-form-urlencoded")))) headers))) (with-temp-buffer (mastodon-http--url-retrieve-synchronously url))) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 6410591..ce7fddd 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -386,6 +386,8 @@ This is done after changing the setting on the server." Only do so if `mastodon-profile-account-settings' is nil." (mastodon-profile--fetch-server-account-settings :no-force)) +;; FIXME: this does one request per setting! should just do one request then +;; parse (defun mastodon-profile--fetch-server-account-settings (&optional no-force) "Fetch basic account settings from the server. Store the values in `mastodon-profile-account-settings'. -- cgit v1.2.3 From 41f5bd5199c6d132dc6312746ac2ff150aba094c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 1 Oct 2024 22:21:56 +0200 Subject: add mastodon-toot-visibility-settings-list --- lisp/mastodon-toot.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 832d03f..8dfee74 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -178,6 +178,11 @@ width fonts")) '(direct private unlisted public) "A list of the available toot visibility settings.") +(defvar mastodon-toot-visibility-settings-list + '("public" "unlisted" "private") + "A list of the available default toot visibility settings. +Like `mastodon-toot-visibility-list' but without 'direct.") + (defvar-local mastodon-toot--visibility nil "A string indicating the visibility of the toot being composed. Valid values are \"direct\", \"private\" (followers-only), -- cgit v1.2.3 From 951ad5d60e4ff24ad108f60a9f45df8e241ef7c2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 2 Oct 2024 10:15:45 +0200 Subject: add mastodon-transient.el --- lisp/mastodon-transient.el | 111 +++++++++++++++++++++++++++++++++++++++++++++ lisp/mastodon.el | 8 ++-- 2 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 lisp/mastodon-transient.el (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el new file mode 100644 index 0000000..7de780c --- /dev/null +++ b/lisp/mastodon-transient.el @@ -0,0 +1,111 @@ +;;; mastodon-transient.el --- transient menus for mastodon.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 martian hiatus + +;; Author: martian hiatus +;; Keywords: convenience + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(require 'tp) + +(defun mastodon-transient-parse-source-key (key) + "Parse mastodon source KEY. +If KEY needs to be source[key], format like so, else just return +the inner key part." + (let* ((split (split-string key "[][]")) + (array-key (cadr split))) + (if (or (= 1 (length split)) ;; no split + (member array-key '("privacy" "sensitive" "language"))) + key + array-key))) + +(defun mastodon-transient-parse-source-keys (alist) + "Parse ALIST containing source[key] keys." + (cl-loop for a in alist + collect (cons (mastodon-transient-parse-source-key (car a)) + (cdr a)))) + +;; FIXME: PATCHing source vals as JSON request body doesn't work! +;; existing `mastodon-profile--update-preference' doesn't use it! it just uses +;; query params! strange thing is it works for non-source params +(transient-define-suffix mastodon-user-settings-update (&optional args) + "Update current user settings on the server." + :transient 'transient--do-exit + ;; interactive receives args from the prefix: + (interactive (list (transient-args 'mastodon-user-settings))) + (let* ((alist (tp-transient-to-alist args)) + (only-changed (tp-only-changed-args alist)) + (arrays (tp-dots-to-arrays only-changed)) + (parsed-source (mastodon-transient-parse-source-keys arrays)) + (endpoint "accounts/update_credentials") + (url (mastodon-http--api endpoint)) + (resp (mastodon-http--patch url parsed-source))) ; :json))) + (mastodon-http--triage + resp + (lambda (_) + (message "Settings updated!\n%s" parsed-source))))) + +(defun mastodon-transient-get-creds () + "Fetch account data." + (mastodon-http--get-json + (mastodon-http--api "accounts/verify_credentials") + nil :silent)) + +(transient-define-prefix mastodon-user-settings () + "A transient for setting current user settings." + :value (lambda () (tp-return-data + #'mastodon-transient-get-creds)) + [:description + ;; '() + (lambda () + "Settings") + ;; (format "User settings for %s" mastodon-active-user)) + (:info + "Note: use the empty string (\"\") to remove a value from an option.") + ] + ;; strings + ["Account info" + ("n" "display name" "display_name=" :class tp-option-str)] + ;; "choice" booleans (so we can PATCH :json-false explicitly): + ["Account options" + ("l" "locked" "locked=" :class tp-choice-bool) + ("b" "bot" "bot=" :class tp-choice-bool) + ("d" "discoverable" "discoverable=" :class tp-choice-bool) + + ("c" "hide follower/following lists" "source.hide_collections=" :class tp-choice-bool) + ("i" "indexable" "source.indexable=" :class tp-choice-bool)] + ["Tooting options" + ("p" "default privacy" "source.privacy=" :class tp-option + :choices (lambda () mastodon-toot-visibility-settings-list)) + ("s" "mark sensitive" "source.sensitive=" :class tp-choice-bool) + ("g" "default language" "source.language=" :class tp-option + :choices (lambda () mastodon-iso-639-regional))] + ["Update" + ("C-c C-c" "Save settings" mastodon-user-settings-update) + ;; ("C-c C-k" :info "to revert all changes") + ] + (interactive) + (if (not mastodon-active-user) + (user-error "User not set") + (transient-setup 'mastodon-user-settings))) + +(provide 'mastodon-transient) +;;; mastodon-transient.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index faeae61..6e9586b 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -38,13 +38,15 @@ ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon (eval-when-compile (require 'subr-x)) -(require 'mastodon-http) -(require 'mastodon-toot) -(require 'mastodon-search) (require 'url) (require 'thingatpt) (require 'shr) +(require 'mastodon-http) +(require 'mastodon-toot) +(require 'mastodon-search) +(require 'mastodon-transient) + (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") (declare-function request "request") -- cgit v1.2.3 From 113d998201546e13d924d6ac00ab0657a99cf2f3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 14:08:05 +0200 Subject: add fields transient and profile note suffix --- lisp/mastodon-transient.el | 156 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 136 insertions(+), 20 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 7de780c..533dc8c 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -26,6 +26,8 @@ (require 'tp) +;;; UTILS + (defun mastodon-transient-parse-source-key (key) "Parse mastodon source KEY. If KEY needs to be source[key], format like so, else just return @@ -43,8 +45,55 @@ the inner key part." collect (cons (mastodon-transient-parse-source-key (car a)) (cdr a)))) -;; FIXME: PATCHing source vals as JSON request body doesn't work! -;; existing `mastodon-profile--update-preference' doesn't use it! it just uses +(defun mastodon-transient-get-creds () + "Fetch account data." + (mastodon-http--get-json + (mastodon-http--api "accounts/verify_credentials") + nil :silent)) + +;; fields utils: +;; to PATCH fields, we just need fields[x][name] and fields[x][value] + +(defun mastodon-transient-fields-to-transient () + "Convert fields in `tp-server-settings' to transient key=val args." + (flatten-tree + (let-alist tp-server-settings + (cl-loop + for f in .source.fields + for count from 1 to 5 + collect + (cl-loop for x in f + collect + (concat "fields." (number-to-string count) + "." (symbol-name (car x)) + "=" (cdr x))))))) + +(defun mastodon-transient-field-dot-to-array (key) + "Convert KEY from tp dot annotation to array[key] annotation." + (let* ((split (split-string key "\\.")) + (count (length split))) + (cond ((not key) nil) + ((= 1 count) key) + (t + (concat ;; first item + (car split) + "_attributes" + ;; but last item + "[" (car (last split (1- count))) + ;; last item: + "][" (car (last split)) "]"))))) + +(defun mastodon-transient-dot-fields-to-arrays (alist) + "Parse fields ALIST in dot notation to array notation." + (cl-loop for y in alist + collect + (cons (mastodon-transient-field-dot-to-array (car y)) + (cdr y)))) + +;;; TRANSIENTS + +;; FIXME: PATCHing source vals as JSON request body doesn't work! existing +;; `mastodon-profile--update-preference' doesn't use it! it just uses ;; query params! strange thing is it works for non-source params (transient-define-suffix mastodon-user-settings-update (&optional args) "Update current user settings on the server." @@ -61,51 +110,118 @@ the inner key part." (mastodon-http--triage resp (lambda (_) - (message "Settings updated!\n%s" parsed-source))))) - -(defun mastodon-transient-get-creds () - "Fetch account data." - (mastodon-http--get-json - (mastodon-http--api "accounts/verify_credentials") - nil :silent)) + (message "Settings updated!\n%s" (pp-to-string parsed-source)))))) (transient-define-prefix mastodon-user-settings () "A transient for setting current user settings." :value (lambda () (tp-return-data #'mastodon-transient-get-creds)) [:description - ;; '() (lambda () - "Settings") - ;; (format "User settings for %s" mastodon-active-user)) + (format "User settings for %s" mastodon-active-user)) (:info - "Note: use the empty string (\"\") to remove a value from an option.") - ] + "Note: use the empty string (\"\") to remove a value from an option.")] ;; strings ["Account info" - ("n" "display name" "display_name=" :class tp-option-str)] + ("n" "display name" "display_name=" :class tp-option-str) + ("t" "update profile note" mastodon-update-profile-note) + ("f" "update profile fields" mastodon-profile-fields)] ;; "choice" booleans (so we can PATCH :json-false explicitly): ["Account options" ("l" "locked" "locked=" :class tp-choice-bool) ("b" "bot" "bot=" :class tp-choice-bool) ("d" "discoverable" "discoverable=" :class tp-choice-bool) - ("c" "hide follower/following lists" "source.hide_collections=" :class tp-choice-bool) ("i" "indexable" "source.indexable=" :class tp-choice-bool)] ["Tooting options" ("p" "default privacy" "source.privacy=" :class tp-option - :choices (lambda () mastodon-toot-visibility-settings-list)) + :choices mastodon-toot-visibility-settings-list) + ;; ("public" "unlisted" "private")) + ;; (lambda () mastodon-toot-visibility-settings-list)) ("s" "mark sensitive" "source.sensitive=" :class tp-choice-bool) ("g" "default language" "source.language=" :class tp-option - :choices (lambda () mastodon-iso-639-regional))] + :choices mastodon-iso-639-regional)] ["Update" ("C-c C-c" "Save settings" mastodon-user-settings-update) - ;; ("C-c C-k" :info "to revert all changes") - ] + ("C-c C-k" :info "to revert all changes")] (interactive) (if (not mastodon-active-user) (user-error "User not set") (transient-setup 'mastodon-user-settings))) +(transient-define-suffix mastodon-update-profile-note () + "Update current user profile note." + :transient 'transient--do-exit + (interactive) + (mastodon-profile--update-user-profile-note)) + +(transient-define-suffix mastodon-profile-fields-update (args) + "Update current user profile fields." + :transient 'transient--do-exit + (interactive (list (transient-args 'mastodon-profile-fields))) + (let* ((alist (tp-transient-to-alist args)) + ;; FIXME: maybe only changed also won't work with fields, as + ;; perhaps what is PATCHed overwrites whatever is on the server? + ;; (only-changed (tp-only-changed-args alist)) + (arrays (mastodon-transient-dot-fields-to-arrays alist)) + (endpoint "accounts/update_credentials") + (url (mastodon-http--api endpoint)) + (resp (mastodon-http--patch url arrays))) ; :json))) + (mastodon-http--triage + resp + (lambda (_) + (message "Fields updated!\n%s" (pp-to-string arrays)))))) + +(transient-define-prefix mastodon-profile-fields () + "A transient for setting profile fields." + :value (lambda () + (tp-return-data #'mastodon-transient-get-creds) + (mastodon-transient-fields-to-transient)) + ["Field 1" + :class transient-row + ("1n" "name:" "fields.1.name=" :class mastodon-transient-field) + ("1v" "value:" "fields.1.value=" :class mastodon-transient-field)] + ["Field 2" + :class transient-row + ("2n" "name:" "fields.2.name=" :class mastodon-transient-field) + ("2v" "value:" "fields.2.value=" :class mastodon-transient-field)] + ["Field 3" + :class transient-row + ("3n" "name:" "fields.3.name=" :class mastodon-transient-field) + ("3v" "value:" "fields.3.value=" :class mastodon-transient-field)] + ["Field 4" + :class transient-row + ("4n" "name:" "fields.4.name=" :class mastodon-transient-field) + ("4v" "value:" "fields.4.value=" :class mastodon-transient-field)] + ["Update" + ("C-c C-c" "Save settings" mastodon-profile-fields-update) + ("C-c C-k" :info "to revert all changes")] + (interactive) + (if (not mastodon-active-user) + (user-error "User not set") + (transient-setup 'mastodon-profile-fields))) + +;;; CLASSES + +(defclass mastodon-transient-field (tp-option-str) + ((always-read :initarg :always-read :initform t)) + "An infix option class for our options. +We always read.") + +(cl-defmethod transient-format-value ((obj mastodon-transient-field)) + "Format the value of OBJ. +Format should just be a string, highlighted green if it has been +changed from the server value." + (let* ((pair (transient-infix-value obj)) + (value (when pair (cadr (split-string pair "="))))) + (if (not pair) + "" + ;; FIXME: not sure how to compare with server, as fields are not + ;; numbered in the JSON? + (propertize value + 'face (if (tp-arg-changed-p pair) + 'transient-value + 'transient-inactive-value))))) + (provide 'mastodon-transient) ;;; mastodon-transient.el ends here -- cgit v1.2.3 From 0607ad7305ed12ea5dac2e0f2f331c77ba3c91c9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 14:45:24 +0200 Subject: C-c C-k info str --- lisp/mastodon-transient.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 533dc8c..bb036b8 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -143,7 +143,7 @@ the inner key part." :choices mastodon-iso-639-regional)] ["Update" ("C-c C-c" "Save settings" mastodon-user-settings-update) - ("C-c C-k" :info "to revert all changes")] + ("C-c C-k" :info "Revert all changes")] (interactive) (if (not mastodon-active-user) (user-error "User not set") @@ -195,7 +195,7 @@ the inner key part." ("4v" "value:" "fields.4.value=" :class mastodon-transient-field)] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) - ("C-c C-k" :info "to revert all changes")] + ("C-c C-k" :info "Revert all changes")] (interactive) (if (not mastodon-active-user) (user-error "User not set") -- cgit v1.2.3 From 3c6d817a9cc244b3f38dd9634d3b00b2e415f397 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 15:43:55 +0200 Subject: highligh fields in transient only if changed --- lisp/mastodon-transient.el | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index bb036b8..22e5fcc 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -54,19 +54,18 @@ the inner key part." ;; fields utils: ;; to PATCH fields, we just need fields[x][name] and fields[x][value] -(defun mastodon-transient-fields-to-transient () - "Convert fields in `tp-server-settings' to transient key=val args." +(defun mastodon-transient-fields-to-transient (fields) + "Convert fields in FIELDS to transient key=val args." (flatten-tree - (let-alist tp-server-settings - (cl-loop - for f in .source.fields - for count from 1 to 5 - collect - (cl-loop for x in f - collect - (concat "fields." (number-to-string count) - "." (symbol-name (car x)) - "=" (cdr x))))))) + (cl-loop + for f in fields + for count from 1 to 5 + collect + (cl-loop for x in f + collect + (concat "fields." (number-to-string count) + "." (symbol-name (car x)) + "=" (cdr x)))))) (defun mastodon-transient-field-dot-to-array (key) "Convert KEY from tp dot annotation to array[key] annotation." @@ -208,18 +207,26 @@ the inner key part." "An infix option class for our options. We always read.") +(defun mastodon-transient-field-changed-p (value key num) + "T if VALUE is not equal corresponding value in `tp-server-settings'. +The latter is fetched from alist number NUM, using KEY, a symbol." + (let ((elt (nth num) tp-server-settings)) + (not (equal value (alist-get key elt))))) + (cl-defmethod transient-format-value ((obj mastodon-transient-field)) "Format the value of OBJ. Format should just be a string, highlighted green if it has been changed from the server value." (let* ((pair (transient-infix-value obj)) - (value (when pair (cadr (split-string pair "="))))) + (arg (oref obj argument)) + (value (when pair (cadr (split-string pair "=")))) + (split (split-string arg "\\.")) + (num (1- (string-to-number (nth 1 split)))) + (key (intern (substring (nth 2 split) nil -1)))) (if (not pair) "" - ;; FIXME: not sure how to compare with server, as fields are not - ;; numbered in the JSON? (propertize value - 'face (if (tp-arg-changed-p pair) + 'face (if (mastodon-transient-field-changed-p value key num) 'transient-value 'transient-inactive-value))))) -- cgit v1.2.3 From d5d6a71ce556aae293a9b407a0993d0ba140e78b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 15:44:16 +0200 Subject: layout of fields transient --- lisp/mastodon-transient.el | 52 +++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 22e5fcc..7269848 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -173,25 +173,39 @@ the inner key part." (transient-define-prefix mastodon-profile-fields () "A transient for setting profile fields." - :value (lambda () - (tp-return-data #'mastodon-transient-get-creds) - (mastodon-transient-fields-to-transient)) - ["Field 1" - :class transient-row - ("1n" "name:" "fields.1.name=" :class mastodon-transient-field) - ("1v" "value:" "fields.1.value=" :class mastodon-transient-field)] - ["Field 2" - :class transient-row - ("2n" "name:" "fields.2.name=" :class mastodon-transient-field) - ("2v" "value:" "fields.2.value=" :class mastodon-transient-field)] - ["Field 3" - :class transient-row - ("3n" "name:" "fields.3.name=" :class mastodon-transient-field) - ("3v" "value:" "fields.3.value=" :class mastodon-transient-field)] - ["Field 4" - :class transient-row - ("4n" "name:" "fields.4.name=" :class mastodon-transient-field) - ("4v" "value:" "fields.4.value=" :class mastodon-transient-field)] + :value + (lambda () + (tp-return-data #'mastodon-transient-get-creds nil 'fields) + (setq tp-settings-as-transient + (mastodon-transient-fields-to-transient + tp-server-settings))) + [:description + "Fields" + ["Name" + ;; :class transient-row + ("n1" "" "fields.1.name=" :class mastodon-transient-field) + ("n2" "" "fields.2.name=" :class mastodon-transient-field) + ("n3" "" "fields.3.name=" :class mastodon-transient-field) + ("n4" "" "fields.4.name=" :class mastodon-transient-field)] + ["Value" + ("v1" "" "fields.1.value=" :class mastodon-transient-field) + ("v2" "" "fields.2.value=" :class mastodon-transient-field) + ("v3" "" "fields.3.value=" :class mastodon-transient-field) + ("v4" "" "fields.4.value=" :class mastodon-transient-field)]] + ;; ["Field" + ;; :class transient-row + ;; :pad-keys t + ;; ;; ("2n" "name:" "fields.2.name=" :class mastodon-transient-field) + ;; ("2v" "value:" "fields.2.value=" :class mastodon-transient-field)] + ;; ["Field 3" + ;; :class transient-row + ;; :pad-keys t + ;; ;; ("3n" "name:" "fields.3.name=" :class mastodon-transient-field) + ;; ("3v" "value:" "fields.3.value=" :class mastodon-transient-field)] + ;; ["Field 4" + ;; :class transient-row + ;; ;; ("4n" "name:" "fields.4.name=" :class mastodon-transient-field) + ;; ("4v" "value:" "fields.4.value=" :class mastodon-transient-field)] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) ("C-c C-k" :info "Revert all changes")] -- cgit v1.2.3 From ca3c9bed31f030288bc95ef31ec0b8f3624a40cb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 17:32:37 +0200 Subject: rename tp-bool --- lisp/mastodon-transient.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 7269848..20a1404 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -127,17 +127,17 @@ the inner key part." ("f" "update profile fields" mastodon-profile-fields)] ;; "choice" booleans (so we can PATCH :json-false explicitly): ["Account options" - ("l" "locked" "locked=" :class tp-choice-bool) - ("b" "bot" "bot=" :class tp-choice-bool) - ("d" "discoverable" "discoverable=" :class tp-choice-bool) - ("c" "hide follower/following lists" "source.hide_collections=" :class tp-choice-bool) - ("i" "indexable" "source.indexable=" :class tp-choice-bool)] + ("l" "locked" "locked=" :class tp-bool) + ("b" "bot" "bot=" :class tp-bool) + ("d" "discoverable" "discoverable=" :class tp-bool) + ("c" "hide follower/following lists" "source.hide_collections=" :class tp-bool) + ("i" "indexable" "source.indexable=" :class tp-bool)] ["Tooting options" ("p" "default privacy" "source.privacy=" :class tp-option :choices mastodon-toot-visibility-settings-list) ;; ("public" "unlisted" "private")) ;; (lambda () mastodon-toot-visibility-settings-list)) - ("s" "mark sensitive" "source.sensitive=" :class tp-choice-bool) + ("s" "mark sensitive" "source.sensitive=" :class tp-bool) ("g" "default language" "source.language=" :class tp-option :choices mastodon-iso-639-regional)] ["Update" -- cgit v1.2.3 From d57b733b3a55cf6f341ac561db7fa028c9923f65 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 19:05:52 +0200 Subject: change fields bindings --- lisp/mastodon-transient.el | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 20a1404..7738958 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -182,30 +182,15 @@ the inner key part." [:description "Fields" ["Name" - ;; :class transient-row - ("n1" "" "fields.1.name=" :class mastodon-transient-field) - ("n2" "" "fields.2.name=" :class mastodon-transient-field) - ("n3" "" "fields.3.name=" :class mastodon-transient-field) - ("n4" "" "fields.4.name=" :class mastodon-transient-field)] + ("1 n" "" "fields.1.name=" :class mastodon-transient-field) + ("2 n" "" "fields.2.name=" :class mastodon-transient-field) + ("3 n" "" "fields.3.name=" :class mastodon-transient-field) + ("4 n" "" "fields.4.name=" :class mastodon-transient-field)] ["Value" - ("v1" "" "fields.1.value=" :class mastodon-transient-field) - ("v2" "" "fields.2.value=" :class mastodon-transient-field) - ("v3" "" "fields.3.value=" :class mastodon-transient-field) - ("v4" "" "fields.4.value=" :class mastodon-transient-field)]] - ;; ["Field" - ;; :class transient-row - ;; :pad-keys t - ;; ;; ("2n" "name:" "fields.2.name=" :class mastodon-transient-field) - ;; ("2v" "value:" "fields.2.value=" :class mastodon-transient-field)] - ;; ["Field 3" - ;; :class transient-row - ;; :pad-keys t - ;; ;; ("3n" "name:" "fields.3.name=" :class mastodon-transient-field) - ;; ("3v" "value:" "fields.3.value=" :class mastodon-transient-field)] - ;; ["Field 4" - ;; :class transient-row - ;; ;; ("4n" "name:" "fields.4.name=" :class mastodon-transient-field) - ;; ("4v" "value:" "fields.4.value=" :class mastodon-transient-field)] + ("1 v" "" "fields.1.value=" :class mastodon-transient-field) + ("2 v" "" "fields.2.value=" :class mastodon-transient-field) + ("3 v" "" "fields.3.value=" :class mastodon-transient-field) + ("4 v" "" "fields.4.value=" :class mastodon-transient-field)]] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) ("C-c C-k" :info "Revert all changes")] -- cgit v1.2.3 From fe27477d19cb78c75e0e9508041f58ff722ab8ca Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 20:03:10 +0200 Subject: do-return (to parent) for fields update --- lisp/mastodon-transient.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 7738958..cc314f8 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -156,7 +156,7 @@ the inner key part." (transient-define-suffix mastodon-profile-fields-update (args) "Update current user profile fields." - :transient 'transient--do-exit + :transient 'transient--do-return (interactive (list (transient-args 'mastodon-profile-fields))) (let* ((alist (tp-transient-to-alist args)) ;; FIXME: maybe only changed also won't work with fields, as @@ -167,9 +167,7 @@ the inner key part." (url (mastodon-http--api endpoint)) (resp (mastodon-http--patch url arrays))) ; :json))) (mastodon-http--triage - resp - (lambda (_) - (message "Fields updated!\n%s" (pp-to-string arrays)))))) + resp (lambda (_) (message "Fields updated!"))))) (transient-define-prefix mastodon-profile-fields () "A transient for setting profile fields." -- cgit v1.2.3 From e8195a833944ca088a7b0d9146afa12ce551178d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Oct 2024 20:03:27 +0200 Subject: add method tp-arg-changed-p for fields --- lisp/mastodon-transient.el | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index cc314f8..05c3d13 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -204,28 +204,30 @@ the inner key part." "An infix option class for our options. We always read.") -(defun mastodon-transient-field-changed-p (value key num) - "T if VALUE is not equal corresponding value in `tp-server-settings'. -The latter is fetched from alist number NUM, using KEY, a symbol." - (let ((elt (nth num) tp-server-settings)) - (not (equal value (alist-get key elt))))) +(cl-defmethod tp-arg-changed-p ((_obj mastodon-transient-field) pair) + "T if value of OBJ is changed. +PAIR is a transient arg of the form \"fields.1.name=val\"." + (let* ((pair-split (split-string pair "=")) + (keys-split (split-string (car pair-split) "\\.")) + (num (1- (string-to-number (nth 1 keys-split)))) + (server-key (intern (nth 2 keys-split))) + (server-elt (nth num tp-server-settings)) + (value (when pair (cadr pair-split)))) + (not (equal value (alist-get server-key server-elt))))) (cl-defmethod transient-format-value ((obj mastodon-transient-field)) "Format the value of OBJ. Format should just be a string, highlighted green if it has been changed from the server value." (let* ((pair (transient-infix-value obj)) - (arg (oref obj argument)) - (value (when pair (cadr (split-string pair "=")))) - (split (split-string arg "\\.")) - (num (1- (string-to-number (nth 1 split)))) - (key (intern (substring (nth 2 split) nil -1)))) + (value (when pair (cadr (split-string pair "="))))) (if (not pair) "" - (propertize value - 'face (if (mastodon-transient-field-changed-p value key num) - 'transient-value - 'transient-inactive-value))))) + (propertize + value + 'face (if (tp-arg-changed-p obj pair) + 'transient-value + 'transient-inactive-value))))) (provide 'mastodon-transient) ;;; mastodon-transient.el ends here -- cgit v1.2.3 From dc69faaa1ba9de3c640291970f7fdf25329f5640 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 08:13:06 +0200 Subject: lambdas for choices lists --- lisp/mastodon-transient.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 05c3d13..4929a42 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -134,12 +134,12 @@ the inner key part." ("i" "indexable" "source.indexable=" :class tp-bool)] ["Tooting options" ("p" "default privacy" "source.privacy=" :class tp-option - :choices mastodon-toot-visibility-settings-list) + :choices (lambda () mastodon-toot-visibility-settings-list)) ;; ("public" "unlisted" "private")) ;; (lambda () mastodon-toot-visibility-settings-list)) ("s" "mark sensitive" "source.sensitive=" :class tp-bool) ("g" "default language" "source.language=" :class tp-option - :choices mastodon-iso-639-regional)] + :choices (lambda () mastodon-iso-639-regional))] ["Update" ("C-c C-c" "Save settings" mastodon-user-settings-update) ("C-c C-k" :info "Revert all changes")] -- cgit v1.2.3 From 4d9651981887d9de424ad0250f9be2894d813e3c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 08:14:44 +0200 Subject: add tp to Package-Requires --- lisp/mastodon.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6e9586b..f5822b1 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -7,7 +7,8 @@ ;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.27 -;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) +;; Package-Requires: ((emacs "27.1") (request "0.3.0") +;; (persist "0.4") (tp "0.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3 From f8345e6f1d9f4d5037a2aa00ba0c21f5682d25ad Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 08:21:02 +0200 Subject: binding for settings transient --- lisp/mastodon.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f5822b1..a8714f3 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -230,6 +230,7 @@ while emojify,el has this feature and mastodon.el implements it.") (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) (define-key map (kbd "V") #'mastodon-profile--view-favourites) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) + (define-key map (kbd ":") #'mastodon-user-settings) ;; minor views (define-key map (kbd "R") #'mastodon-views--view-follow-requests) (define-key map (kbd "S") #'mastodon-views--view-scheduled-toots) -- cgit v1.2.3 From 71c68ba64c5be9d6bcf473d46aea2c0977b80048 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 11:42:52 +0200 Subject: add images in notifs customize --- lisp/mastodon-notifications.el | 6 ++++++ lisp/mastodon-tl.el | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1c2aad7..1a1c4ed 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -70,6 +70,10 @@ If unset, profile notes of any size will be displayed, which may make them unweildy." :type '(integer)) +(defcustom mastodon-notifications--images-in-notifs nil + "Whether to display attached images in notifications." + :type '(boolean)) + (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) @@ -301,6 +305,8 @@ Call its function in that list on NOTE." (when fun (funcall fun note) (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4058abc..f8088e6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -96,6 +96,7 @@ (defvar mastodon-toot--visibility) (defvar mastodon-toot-mode) (defvar mastodon-active-user) +(defvar mastodon-notifications--images-in-notifs) (when (require 'mpv nil :no-error) (declare-function mpv-start "mpv")) @@ -1184,7 +1185,12 @@ SENSITIVE is a flag from the item's JSON data." .description) .description) .preview_url))) - (if mastodon-tl--display-media-p + (if (and mastodon-tl--display-media-p + ;; if in notifs, also check notifs images custom: + (if (or (mastodon-tl--buffer-type-eq 'notifications) + (mastodon-tl--buffer-type-eq 'mentions)) + mastodon-notifications--images-in-notifs + t)) (mastodon-media--get-media-link-rendering ; placeholder: "[img]" .preview_url (or .remote_url .url) ; for shr-browse-url .type .description sensitive) -- cgit v1.2.3 From ba6e06361655398144b1cbb9005eb4846f0f3d70 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 11:43:09 +0200 Subject: move call to mastodon-media--inline-images from tl--insert-status to tl--timeline, so its called once per timeline not once per status! --- lisp/mastodon-tl.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f8088e6..1068a8c 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1538,8 +1538,7 @@ 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." - (let* ((start-pos (point)) - (reply-to-id (alist-get 'in_reply_to_id toot)) + (let* ((reply-to-id (alist-get 'in_reply_to_id toot)) (after-reply-status-p (when (and thread reply-to-id) (mastodon-tl--after-reply-status reply-to-id))) @@ -1587,10 +1586,7 @@ NO-BYLINE means just insert toot body, used for folding." 'notification-type type 'toot-foldable toot-foldable 'toot-folded (and toot-foldable (not unfolded))) - (if no-byline "" "\n")) - ;; media: - (when mastodon-tl--display-media-p - (mastodon-media--inline-images start-pos (point))))) + (if no-byline "" "\n")))) (defun mastodon-tl--is-reply (toot) "Check if the TOOT is a reply to another one (and not boosted). @@ -1668,7 +1664,8 @@ NO-BYLINE means just insert toot body, used for folding." 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." - (let ((toots ;; hack to *not* filter replies on profiles: + (let ((start-pos (point)) + (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*: @@ -1680,6 +1677,9 @@ When DOMAIN, force inclusion of user's domain in their handle." (mapc (lambda (toot) (mastodon-tl--toot toot nil thread domain)) toots) + ;; media: + (when mastodon-tl--display-media-p + (mastodon-media--inline-images start-pos (point))) (goto-char (point-min)))) ;;; FOLDING -- cgit v1.2.3 From 567b116357143488980e0294caf900624b48468a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 11:46:56 +0200 Subject: notifs: don't require mastodon! require subr-x, autoloads --- lisp/mastodon-notifications.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1a1c4ed..bab2e13 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -30,7 +30,7 @@ ;;; Code: -(require 'mastodon) +(eval-when-compile (require 'subr-x)) (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-params-async-json "mastodon-http") @@ -52,6 +52,10 @@ (autoload 'mastodon-tl--item-id "mastodon-tl") (autoload 'mastodon-tl--update "mastodon-tl") (autoload 'mastodon-views--view-follow-requests "mastodon-views") +(autoload 'mastodon-tl--current-filters "mastodon-views") +(autoload 'mastodon-tl--render-text "mastodon-tl") +(autoload 'mastodon-notifications-get "mastodon") + (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -76,6 +80,7 @@ make them unweildy." (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) +(defvar mastodon-mode-map) (defvar mastodon-notifications--types-alist '(("follow" . mastodon-notifications--follow) -- cgit v1.2.3 From d3f7046a083623d0e3788af00fc7006eee45fa3f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 13:47:38 +0200 Subject: transient: improve field-dot-to-array --- lisp/mastodon-transient.el | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 4929a42..481a68e 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -69,18 +69,7 @@ the inner key part." (defun mastodon-transient-field-dot-to-array (key) "Convert KEY from tp dot annotation to array[key] annotation." - (let* ((split (split-string key "\\.")) - (count (length split))) - (cond ((not key) nil) - ((= 1 count) key) - (t - (concat ;; first item - (car split) - "_attributes" - ;; but last item - "[" (car (last split (1- count))) - ;; last item: - "][" (car (last split)) "]"))))) + (tp-dot-to-array key nil "_attributes")) (defun mastodon-transient-dot-fields-to-arrays (alist) "Parse fields ALIST in dot notation to array notation." -- cgit v1.2.3 From 1c1a195b09c995b2a1f17dcc3f6830e7f0737c69 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 16:09:28 +0200 Subject: fix display/links of Media: links with captions --- lisp/mastodon-tl.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1068a8c..2e0588f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1183,8 +1183,9 @@ SENSITIVE is a flag from the item's JSON data." (concat "Media:: " (if (and mastodon-tl--display-caption-not-url-when-no-media .description) - .description) - .preview_url))) + .description + .preview_url))) + (remote-url (or .remote_url .url))) (if (and mastodon-tl--display-media-p ;; if in notifs, also check notifs images custom: (if (or (mastodon-tl--buffer-type-eq 'notifications) @@ -1192,12 +1193,12 @@ SENSITIVE is a flag from the item's JSON data." mastodon-notifications--images-in-notifs t)) (mastodon-media--get-media-link-rendering ; placeholder: "[img]" - .preview_url (or .remote_url .url) ; for shr-browse-url + .preview_url remote-url ; for shr-browse-url .type .description sensitive) ;; return URL/caption: (concat (mastodon-tl--propertize-img-str-or-url (concat "Media:: " .preview_url) ; string - .preview_url .remote_url .type .description + .preview_url remote-url .type .description display-str 'shr-link .description sensitive) "\n"))))) @@ -1220,7 +1221,7 @@ SENSITIVE is a flag from the item's JSON data." 'face face 'mouse-face 'highlight 'mastodon-tab-stop 'image ; for do-link-action-at-point - 'image-url full-remote-url ; for shr-browse-image + 'image-url (or full-remote-url media-url) ; for shr-browse-image 'keymap mastodon-tl--shr-image-map-replacement 'image-description caption 'sensitive sensitive -- cgit v1.2.3 From 2bfd601b88d5fc5a53bce104ba8fda938da45382 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 7 Oct 2024 19:01:56 +0200 Subject: transient working with tp alist args --- lisp/mastodon-transient.el | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 481a68e..1c5890f 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -88,17 +88,15 @@ the inner key part." :transient 'transient--do-exit ;; interactive receives args from the prefix: (interactive (list (transient-args 'mastodon-user-settings))) - (let* ((alist (tp-transient-to-alist args)) - (only-changed (tp-only-changed-args alist)) + (let* ((only-changed (tp-only-changed-args args)) (arrays (tp-dots-to-arrays only-changed)) - (parsed-source (mastodon-transient-parse-source-keys arrays)) - (endpoint "accounts/update_credentials") - (url (mastodon-http--api endpoint)) - (resp (mastodon-http--patch url parsed-source))) ; :json))) + (strs (tp-bools-to-strs arrays)) ;; we can't PATCH json + (url (mastodon-http--api "accounts/update_credentials")) + (resp (mastodon-http--patch url strs))) ;; :json fails (mastodon-http--triage resp (lambda (_) - (message "Settings updated!\n%s" (pp-to-string parsed-source)))))) + (message "Settings updated!\n%s" (pp-to-string strs)))))) (transient-define-prefix mastodon-user-settings () "A transient for setting current user settings." @@ -111,29 +109,33 @@ the inner key part." "Note: use the empty string (\"\") to remove a value from an option.")] ;; strings ["Account info" - ("n" "display name" "display_name=" :class tp-option-str) + ("n" "display name" "display_name" :alist-key display_name :class tp-option-str) ("t" "update profile note" mastodon-update-profile-note) ("f" "update profile fields" mastodon-profile-fields)] ;; "choice" booleans (so we can PATCH :json-false explicitly): ["Account options" - ("l" "locked" "locked=" :class tp-bool) - ("b" "bot" "bot=" :class tp-bool) - ("d" "discoverable" "discoverable=" :class tp-bool) - ("c" "hide follower/following lists" "source.hide_collections=" :class tp-bool) - ("i" "indexable" "source.indexable=" :class tp-bool)] + ("l" "locked" "locked" :alist-key locked :class tp-bool) + ("b" "bot" "bot" :alist-key bot :class tp-bool) + ("d" "discoverable" "discoverable" :alist-key discoverable :class tp-bool) + ("c" "hide follower/following lists" "source.hide_collections" + :alist-key source.hide_collections :class tp-bool) + ("i" "indexable" "source.indexable" :alist-key source.indexable :class tp-bool) + ] ["Tooting options" - ("p" "default privacy" "source.privacy=" :class tp-option + ("p" "default privacy" "source.privacy" :alist-key source.privacy + :class tp-option :choices (lambda () mastodon-toot-visibility-settings-list)) - ;; ("public" "unlisted" "private")) - ;; (lambda () mastodon-toot-visibility-settings-list)) - ("s" "mark sensitive" "source.sensitive=" :class tp-bool) - ("g" "default language" "source.language=" :class tp-option - :choices (lambda () mastodon-iso-639-regional))] + ("s" "mark sensitive" "source.sensitive" :alist-key source.sensitive :class tp-bool) + ("g" "default language" "source.language" :alist-key source.language :class tp-option + :choices (lambda () mastodon-iso-639-regional)) + ] ["Update" + ("C-c g" "Show args" masto-show-args) ("C-c C-c" "Save settings" mastodon-user-settings-update) ("C-c C-k" :info "Revert all changes")] (interactive) - (if (not mastodon-active-user) + (if (or (not (boundp 'mastodon-active-user)) + (not mastodon-active-user)) (user-error "User not set") (transient-setup 'mastodon-user-settings))) -- cgit v1.2.3 From f557e030fc65b88f135987fac3ef950f8e6c52be Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 7 Oct 2024 20:27:18 +0200 Subject: start on masto fields transient --- lisp/mastodon-transient.el | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 1c5890f..060e9ad 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -171,15 +171,15 @@ the inner key part." [:description "Fields" ["Name" - ("1 n" "" "fields.1.name=" :class mastodon-transient-field) - ("2 n" "" "fields.2.name=" :class mastodon-transient-field) - ("3 n" "" "fields.3.name=" :class mastodon-transient-field) - ("4 n" "" "fields.4.name=" :class mastodon-transient-field)] + ("1 n" "" "fields.1.name" :alist-key fields.1.name :class mastodon-transient-field) + ("2 n" "" "fields.2.name" :alist-key fields.2.name :class mastodon-transient-field) + ("3 n" "" "fields.3.name" :alist-key fields.3.name :class mastodon-transient-field) + ("4 n" "" "fields.4.name" :alist-key fields.4.name :class mastodon-transient-field)] ["Value" - ("1 v" "" "fields.1.value=" :class mastodon-transient-field) - ("2 v" "" "fields.2.value=" :class mastodon-transient-field) - ("3 v" "" "fields.3.value=" :class mastodon-transient-field) - ("4 v" "" "fields.4.value=" :class mastodon-transient-field)]] + ("1 v" "" "fields.1.value" :alist-key fields.1.value :class mastodon-transient-field) + ("2 v" "" "fields.2.value" :alist-key fields.2.value :class mastodon-transient-field) + ("3 v" "" "fields.3.value" :alist-key fields.3.value :class mastodon-transient-field) + ("4 v" "" "fields.4.value" :alist-key fields.4.value :class mastodon-transient-field)]] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) ("C-c C-k" :info "Revert all changes")] @@ -206,19 +206,5 @@ PAIR is a transient arg of the form \"fields.1.name=val\"." (value (when pair (cadr pair-split)))) (not (equal value (alist-get server-key server-elt))))) -(cl-defmethod transient-format-value ((obj mastodon-transient-field)) - "Format the value of OBJ. -Format should just be a string, highlighted green if it has been -changed from the server value." - (let* ((pair (transient-infix-value obj)) - (value (when pair (cadr (split-string pair "="))))) - (if (not pair) - "" - (propertize - value - 'face (if (tp-arg-changed-p obj pair) - 'transient-value - 'transient-inactive-value))))) - (provide 'mastodon-transient) ;;; mastodon-transient.el ends here -- cgit v1.2.3 From 2e129d90fb90fbd1ecef6d6bf2bbf1ec86a3ad9a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 8 Oct 2024 16:11:57 +0200 Subject: transient: remove testing fun --- lisp/mastodon-transient.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 060e9ad..5d1f026 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -130,7 +130,6 @@ the inner key part." :choices (lambda () mastodon-iso-639-regional)) ] ["Update" - ("C-c g" "Show args" masto-show-args) ("C-c C-c" "Save settings" mastodon-user-settings-update) ("C-c C-k" :info "Revert all changes")] (interactive) -- cgit v1.2.3 From 4bef5506c12495861def5507660397f49c89cb29 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 8 Oct 2024 17:16:30 +0200 Subject: fields transient: set tp-server-settings only --- lisp/mastodon-transient.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 5d1f026..abb845a 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -164,7 +164,7 @@ the inner key part." :value (lambda () (tp-return-data #'mastodon-transient-get-creds nil 'fields) - (setq tp-settings-as-transient + (setq tp-server-settings (mastodon-transient-fields-to-transient tp-server-settings))) [:description -- cgit v1.2.3 From 6d2865f5034043be7f3653f44f533ebb969e79c5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 8 Oct 2024 18:06:18 +0200 Subject: add mastodon-notifications--get-unread-count --- lisp/mastodon-notifications.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bab2e13..ce3aea8 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -380,5 +380,12 @@ Status notifications are created when you call (mastodon-tl--reload-timeline-or-profile)) (message "Notification dismissed!"))))) +(defun mastodon-notifications--get-unread-count () + "Return the number of unread notifications for the current account." + ;; params: limit - max 1000, default 100, types[], exclude_types[], account_id + (let* ((endpoint "notifications/unread_count") + (url (mastodon-http--api endpoint))) + (mastodon-http--get-json url))) + (provide 'mastodon-notifications) ;;; mastodon-notifications.el ends here -- cgit v1.2.3 From 228a00c273ad9ded168ec77736d3cbdde36bd80b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 8 Oct 2024 21:17:28 +0200 Subject: transient: fix profile fields using alist args --- lisp/mastodon-transient.el | 80 +++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 30 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index abb845a..9b8d738 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -55,21 +55,22 @@ the inner key part." ;; to PATCH fields, we just need fields[x][name] and fields[x][value] (defun mastodon-transient-fields-to-transient (fields) - "Convert fields in FIELDS to transient key=val args." - (flatten-tree - (cl-loop - for f in fields - for count from 1 to 5 - collect - (cl-loop for x in f - collect - (concat "fields." (number-to-string count) - "." (symbol-name (car x)) - "=" (cdr x)))))) + "Convert fields in FIELDS to numbered conses. +The keys in the data are not numbered, so we convert the key into +the format fields.X.keyname." + (cl-loop + for f in fields + for count from 1 to 5 + collect + (cl-loop for x in f + collect + (cons (concat "fields." (number-to-string count) + "." (symbol-name (car x))) + (cdr x))))) (defun mastodon-transient-field-dot-to-array (key) "Convert KEY from tp dot annotation to array[key] annotation." - (tp-dot-to-array key nil "_attributes")) + (tp-dot-to-array (symbol-name key) nil "_attributes")) (defun mastodon-transient-dot-fields-to-arrays (alist) "Parse fields ALIST in dot notation to array notation." @@ -148,25 +149,26 @@ the inner key part." "Update current user profile fields." :transient 'transient--do-return (interactive (list (transient-args 'mastodon-profile-fields))) - (let* ((alist (tp-transient-to-alist args)) - ;; FIXME: maybe only changed also won't work with fields, as + (let* (;; FIXME: maybe only changed also won't work with fields, as ;; perhaps what is PATCHed overwrites whatever is on the server? ;; (only-changed (tp-only-changed-args alist)) - (arrays (mastodon-transient-dot-fields-to-arrays alist)) + (arrays (mastodon-transient-dot-fields-to-arrays args)) (endpoint "accounts/update_credentials") (url (mastodon-http--api endpoint)) (resp (mastodon-http--patch url arrays))) ; :json))) (mastodon-http--triage resp (lambda (_) (message "Fields updated!"))))) +(defun mastodon-transient-fetch-fields () + "Fetch profile fields (metadata)." + (tp-return-data #'mastodon-transient-get-creds nil 'fields) + (setq tp-server-settings + (mastodon-transient-fields-to-transient tp-server-settings))) + (transient-define-prefix mastodon-profile-fields () "A transient for setting profile fields." :value - (lambda () - (tp-return-data #'mastodon-transient-get-creds nil 'fields) - (setq tp-server-settings - (mastodon-transient-fields-to-transient - tp-server-settings))) + (lambda () (mastodon-transient-fetch-fields)) [:description "Fields" ["Name" @@ -194,16 +196,34 @@ the inner key part." "An infix option class for our options. We always read.") -(cl-defmethod tp-arg-changed-p ((_obj mastodon-transient-field) pair) - "T if value of OBJ is changed. -PAIR is a transient arg of the form \"fields.1.name=val\"." - (let* ((pair-split (split-string pair "=")) - (keys-split (split-string (car pair-split) "\\.")) - (num (1- (string-to-number (nth 1 keys-split)))) - (server-key (intern (nth 2 keys-split))) - (server-elt (nth num tp-server-settings)) - (value (when pair (cadr pair-split)))) - (not (equal value (alist-get server-key server-elt))))) +(cl-defmethod transient-init-value ((obj mastodon-transient-field)) + "Initialize value of OBJ." + (let* ((prefix-val (oref transient--prefix value)) + (arg (oref obj alist-key))) + (oset obj value + (tp-get-server-val obj prefix-val)))) + +(cl-defmethod tp-get-server-val ((obj mastodon-transient-field) data) + "Return the server value for OBJ from DATA. +If OBJ's key has dotted notation, drill down into the alist. Currently +only one level of nesting is supported." + ;; TODO: handle nested alist keys + (let* ((key (oref obj alist-key)) + (split (split-string (symbol-name key) "\\.")) + (num (string-to-number (cadr split)))) + (alist-get key + (nth (1- num) data) nil nil #'string=))) + +(cl-defmethod tp-arg-changed-p ((_obj mastodon-transient-field) cons) + "T if value of OBJ is changed from the server value. +CONS is a cons of the form \"(fields.1.name . val)\"." + (let* ((key-split (split-string + (symbol-to-string (car cons)) "\\.")) + (num (1- (string-to-number (nth 1 key-split)))) + (server-key (symbol-name (car cons))) + (server-elt (nth num tp-server-settings))) + (not (equal (cdr cons) + (alist-get server-key server-elt nil nil #'string=))))) (provide 'mastodon-transient) ;;; mastodon-transient.el ends here -- cgit v1.2.3 From 553b3dc5e4ebd0b83ec34fa18407fec343c1422c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 08:29:57 +0200 Subject: user settings transient: use new tp-parse-args-for-send --- lisp/mastodon-transient.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 9b8d738..bbc8bc2 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -89,9 +89,7 @@ the format fields.X.keyname." :transient 'transient--do-exit ;; interactive receives args from the prefix: (interactive (list (transient-args 'mastodon-user-settings))) - (let* ((only-changed (tp-only-changed-args args)) - (arrays (tp-dots-to-arrays only-changed)) - (strs (tp-bools-to-strs arrays)) ;; we can't PATCH json + (let* ((strs (tp-parse-args-for-send args :strings)) (url (mastodon-http--api "accounts/update_credentials")) (resp (mastodon-http--patch url strs))) ;; :json fails (mastodon-http--triage -- cgit v1.2.3 From 9cd74926daf000ea36c1ecf4da2a129b3a66e69f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 09:01:14 +0200 Subject: http: remove msg call --- lisp/mastodon-http.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index c1b0599..c0402f0 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -319,7 +319,6 @@ Optionally specify the PARAMS to send." ("Accept" . "application/json")))) (url-request-extra-headers (append url-request-extra-headers headers))) - (message "Data: %s" url-request-data) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions -- cgit v1.2.3 From 1968cacb26593ca00f79637c73af1e9079cc6656 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 09:13:46 +0200 Subject: rename a util --- lisp/mastodon-transient.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index bbc8bc2..946d28a 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -28,6 +28,9 @@ ;;; UTILS +;; some JSON fields that are returned under the "source" field need to be +;; sent back in the format source[key], while some others are sent kust as +;; key: (defun mastodon-transient-parse-source-key (key) "Parse mastodon source KEY. If KEY needs to be source[key], format like so, else just return @@ -54,7 +57,7 @@ the inner key part." ;; fields utils: ;; to PATCH fields, we just need fields[x][name] and fields[x][value] -(defun mastodon-transient-fields-to-transient (fields) +(defun mastodon-transient--fields-alist (fields) "Convert fields in FIELDS to numbered conses. The keys in the data are not numbered, so we convert the key into the format fields.X.keyname." @@ -161,7 +164,7 @@ the format fields.X.keyname." "Fetch profile fields (metadata)." (tp-return-data #'mastodon-transient-get-creds nil 'fields) (setq tp-server-settings - (mastodon-transient-fields-to-transient tp-server-settings))) + (mastodon-transient--fields-alist tp-server-settings))) (transient-define-prefix mastodon-profile-fields () "A transient for setting profile fields." -- cgit v1.2.3 From 30a3f5606b5eb9b10f48a1e358e1415b7bb016e8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 09:13:53 +0200 Subject: transient: fix user settings sending source keys --- lisp/mastodon-transient.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index 946d28a..fe70eac 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -90,9 +90,9 @@ the format fields.X.keyname." (transient-define-suffix mastodon-user-settings-update (&optional args) "Update current user settings on the server." :transient 'transient--do-exit - ;; interactive receives args from the prefix: (interactive (list (transient-args 'mastodon-user-settings))) - (let* ((strs (tp-parse-args-for-send args :strings)) + (let* ((parsed (tp-parse-args-for-send args :strings)) + (strs (mastodon-transient-parse-source-keys parsed)) (url (mastodon-http--api "accounts/update_credentials")) (resp (mastodon-http--patch url strs))) ;; :json fails (mastodon-http--triage -- cgit v1.2.3 From 7af2f459b7ed7375fd9df1a960d78aeba7e27351 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 12:11:35 +0200 Subject: toot: try double newline btw compose docs and body, for paragraph break maybe, seeing as thus sucks so bad, it cd be customize. but we really shouldn't have any interaction/overlap between docs and body. --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8dfee74..fd7e298 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1673,7 +1673,7 @@ REPLY-TEXT is the text of the toot being replied to." 'read-only "Edit your message below." 'toot-post-header t)) ;; allow us to enter text after read-only header: - (propertize "\n" + (propertize "\n\n" 'rear-nonsticky t)))) (defun mastodon-toot--most-restrictive-visibility (reply-visibility) -- cgit v1.2.3 From 5b8d8f7c0f21c1a8428c2c8ad1b3f4e71ca5ffd4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 9 Oct 2024 12:38:52 +0200 Subject: FIX filling in formatting reply quote! hurrah! --- lisp/mastodon-toot.el | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index fd7e298..9aeb790 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1686,22 +1686,17 @@ The default is given by `mastodon-toot--default-reply-visibility'." mastodon-toot--default-reply-visibility reply-visibility)))) -(defun mastodon-toot--fill-buffer () - "Mark buffer, call `fill-region'." - (mark-whole-buffer) ; lisp code should not set mark - ;; (fill-region (point-min) (point-max)) ; but this doesn't work - (fill-region (region-beginning) (region-end))) - (defun mastodon-toot--render-reply-region-str (str) "Refill STR and prefix all lines with >, as reply-quote text." (with-temp-buffer (insert str) ;; unfill first: (let ((fill-column (point-max))) - (mastodon-toot--fill-buffer)) + (fill-region (point-min) (point-max))) ;; then fill: - (mastodon-toot--fill-buffer) + (fill-region (point-min) (point-max)) ;; add our own prefix, pauschal: + (goto-char (point-min)) (save-match-data (while (re-search-forward "^" nil t) (replace-match " > "))) -- cgit v1.2.3 From 4b37b7c908ab1ebfa03ccdeafea42494c9c82614 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 10:29:59 +0200 Subject: unread notifs: return number directly --- lisp/mastodon-notifications.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index ce3aea8..0c56cbb 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -384,8 +384,9 @@ Status notifications are created when you call "Return the number of unread notifications for the current account." ;; params: limit - max 1000, default 100, types[], exclude_types[], account_id (let* ((endpoint "notifications/unread_count") - (url (mastodon-http--api endpoint))) - (mastodon-http--get-json url))) + (url (mastodon-http--api endpoint)) + (resp (mastodon-http--get-json url))) + (alist-get 'count resp))) (provide 'mastodon-notifications) ;;; mastodon-notifications.el ends here -- cgit v1.2.3 From 353afcad0f2a6802719eb987be6de861de3e2e8e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 11:39:50 +0200 Subject: WIP. display fediverse account of link authors if available. --- lisp/mastodon-tl.el | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2e0588f..3f06756 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -875,17 +875,46 @@ links in the text. If TOOT is nil no parsing occurs." 0 (- (window-width) 3))))) (shr-render-region (point-min) (point-max))) - ;; Make all links a tab stop recognized by our own logic, make things point - ;; to our own logic (e.g. hashtags), and update keymaps where needed: + ;; Make all links a tab stop recognized by our own logic, make + ;; things point to our own logic (e.g. hashtags), and update keymaps + ;; where needed: (when toot (let (region) (while (setq region (mastodon-tl--find-property-range 'shr-url (or (cdr region) (point-min)))) (mastodon-tl--process-link toot (car region) (cdr region) - (get-text-property (car region) 'shr-url))))) + (get-text-property (car region) 'shr-url)) + (when (proper-list-p toot) ;; not on profile fields cons cells + (let* ((card (alist-get 'card toot)) + (card-url (alist-get 'url card)) + (authors (alist-get 'authors card)) + (url (buffer-substring (car region) (cdr region))) + (url-no-query (car (split-string url "?")))) + (when (and (string= url-no-query card-url) + ;; only if we have an account's data: + (alist-get 'account (car authors))) + (goto-char (point-max)) ;;(cdr region)) + (mastodon-tl--insert-card-authors authors))))))) (buffer-string)))) +(defun mastodon-tl--insert-card-authors (authors) + "Insert a string of card AUTHORS." + (insert + (concat + "\n(Authors: " + (cl-loop for x in authors + concat + (mastodon-tl--format-card-author x)) + ")\n"))) + +(defun mastodon-tl--format-card-author (data) + "Render card author DATA." + ;; FIXME: update as needed, data contains "name" "url" and "account" + (let-alist data + (when .account + (mastodon-search--propertize-user .account)))) + (defun mastodon-tl--process-link (toot start end url) "Process link URL in TOOT as hashtag, userhandle, or normal link. START and END are the boundaries of the link in the toot." @@ -1553,7 +1582,7 @@ NO-BYLINE means just insert toot body, used for folding." (propertize ;; body only: (concat "\n" - ;; relpy symbol (broken): + ;; relpy symbol: (when (and after-reply-status-p thread) (concat (mastodon-tl--symbol 'replied) "\n")) -- cgit v1.2.3 From 119bca6c441ef5fbed95ed8000a76ec8f7612796 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 19:48:33 +0200 Subject: add mastodon-notifications--action-alist, use reblog in notifications.el --- lisp/mastodon-notifications.el | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 0c56cbb..db8b842 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -180,7 +180,7 @@ Can be called in notifications view or in follow-requests view." (defun mastodon-notifications--reblog (note) "Format for a `boost' NOTE." - (mastodon-notifications--format-note note 'boost)) + (mastodon-notifications--format-note note 'reblog)) (defun mastodon-notifications--status (note) "Format for a `status' NOTE. @@ -208,6 +208,16 @@ Status notifications are given when '(face (font-lock-comment-face shr-text))))) (buffer-string))) +(defvar mastodon-notifications--action-alist + '((reblog . "Boosted") + (favourite . "Favourited") + (follow-request . "Requested to follow") + (follow . "Followed") + (mention . "Mentioned") + (status . "Posted") + (poll . "Posted a poll") + (edit . "Edited"))) + (defun mastodon-notifications--format-note (note type) "Format for a NOTE of TYPE." ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' @@ -238,7 +248,7 @@ Status notifications are given when ;; reblogs/faves use 'note' to process their own json ;; not the toot's. this ensures following etc. work on such notifs ((or (eq type 'favourite) - (eq type 'boost)) + (eq type 'reblog)) note) (t status)) @@ -266,7 +276,7 @@ Status notifications are given when ":\n" (mastodon-notifications--comment-note-text body)))))) ((or (eq type 'favourite) - (eq type 'boost)) + (eq type 'reblog)) (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline @@ -279,26 +289,11 @@ Status notifications are given when ;; action-byline (lambda (_status) (mastodon-notifications--byline-concat - (cond ((eq type 'boost) - "Boosted") - ((eq type 'favourite) - "Favourited") - ((eq type 'follow-request) - "Requested to follow") - ((eq type 'follow) - "Followed") - ((eq type 'mention) - "Mentioned") - ((eq type 'status) - "Posted") - ((eq type 'poll) - "Posted a poll") - ((eq type 'edit) - "Edited")))) + (alist-get type mastodon-notifications--action-alist))) id ;; base toot (when (or (eq type 'favourite) - (eq type 'boost)) + (eq type 'reblog)) status))))) (defun mastodon-notifications--by-type (note) -- cgit v1.2.3 From 7ed54ce921e357d2b7d655921b694a5599cd9be0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 19:57:48 +0200 Subject: clean up cond predicates - use member! --- lisp/mastodon-notifications.el | 43 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index db8b842..2091118 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -240,18 +240,15 @@ Status notifications are given when nil (mastodon-tl--insert-status ;; toot - (cond ((or (eq type 'follow) - (eq type 'follow-request)) + (cond ((member type '(follow 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 (eq type 'favourite) - (eq type 'reblog)) + ((member type '(favourite reblog)) note) - (t - status)) + (t status)) ;; body (let ((body (if-let ((match (assoc "warn" filters))) (mastodon-tl--spoiler toot (cadr match)) @@ -261,28 +258,25 @@ Status notifications are given when (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 (eq type 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default) - (concat - (propertize - (format "You have a follow request from... %s" - follower) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs + (cond ((eq type 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type 'follow-request) + (concat + (propertize + (format "You have a follow request from... %s" + follower) + 'face 'default) + (if mastodon-notifications--profile-note-in-foll-reqs (concat ":\n" - (mastodon-notifications--comment-note-text body)))))) - ((or (eq type 'favourite) - (eq type 'reblog)) + (mastodon-notifications--comment-note-text body)) + ""))) + ((member type '(favourite reblog)) (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline - (if (or (eq type 'follow) - (eq type 'follow-request) - (eq type 'mention)) + (if (member type '(follow follow-request mention)) 'mastodon-tl--byline-author (lambda (_status &rest _args) ; unbreak stuff (mastodon-tl--byline-author note))) @@ -292,8 +286,7 @@ Status notifications are given when (alist-get type mastodon-notifications--action-alist))) id ;; base toot - (when (or (eq type 'favourite) - (eq type 'reblog)) + (when (member type '(favourite reblog)) status))))) (defun mastodon-notifications--by-type (note) -- cgit v1.2.3 From fbcec02f9072bd61908deef311b322f6b0719410 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 19:45:40 +0200 Subject: 1st mockup of grouped notifs --- lisp/mastodon-notifications.el | 281 ++++++++++++++++++++++++----------------- lisp/mastodon.el | 3 +- 2 files changed, 164 insertions(+), 120 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 0c56cbb..0e27ca0 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -162,39 +162,39 @@ Can be called in notifications view or in follow-requests view." (interactive) (mastodon-notifications--follow-request-process :reject)) -(defun mastodon-notifications--mention (note) +(defun mastodon-notifications--mention (group json) "Format for a `mention' NOTE." - (mastodon-notifications--format-note note 'mention)) + (mastodon-notifications--format-note group json 'mention)) -(defun mastodon-notifications--follow (note) +(defun mastodon-notifications--follow (group json) "Format for a `follow' NOTE." - (mastodon-notifications--format-note note 'follow)) + (mastodon-notifications--format-note group json 'follow)) -(defun mastodon-notifications--follow-request (note) +(defun mastodon-notifications--follow-request (group json) "Format for a `follow-request' NOTE." - (mastodon-notifications--format-note note 'follow-request)) + (mastodon-notifications--format-note group json 'follow-request)) -(defun mastodon-notifications--favourite (note) +(defun mastodon-notifications--favourite (group json) "Format for a `favourite' NOTE." - (mastodon-notifications--format-note note 'favourite)) + (mastodon-notifications--format-note group json 'favourite)) -(defun mastodon-notifications--reblog (note) +(defun mastodon-notifications--reblog (group json) "Format for a `boost' NOTE." - (mastodon-notifications--format-note note 'boost)) + (mastodon-notifications--format-note group json 'reblog)) -(defun mastodon-notifications--status (note) +(defun mastodon-notifications--status (group json) "Format for a `status' NOTE. Status notifications are given when `mastodon-tl--enable-notify-user-posts' has been set." - (mastodon-notifications--format-note note 'status)) + (mastodon-notifications--format-note group json 'status)) -(defun mastodon-notifications--poll (note) +(defun mastodon-notifications--poll (group json) "Format for a `poll' NOTE." - (mastodon-notifications--format-note note 'poll)) + (mastodon-notifications--format-note group json 'poll)) -(defun mastodon-notifications--edit (note) +(defun mastodon-notifications--edit (group json) "Format for an `edit' NOTE." - (mastodon-notifications--format-note note 'edit)) + (mastodon-notifications--format-note group json 'edit)) (defun mastodon-notifications--comment-note-text (str) "Add comment face to all text in STR with `shr-text' face only." @@ -208,118 +208,161 @@ Status notifications are given when '(face (font-lock-comment-face shr-text))))) (buffer-string))) -(defun mastodon-notifications--format-note (note type) +(defvar mastodon-notifications-grouped-types + '(follow boost favourite) + "List of notification types for which grouping is implemented.") + +(defvar mastodon-notifications--action-alist + '((reblog . "Boosted") + (favourite . "Favourited") + (follow-request . "Requested to follow") + (follow . "Followed") + (mention . "Mentioned") + (status . "Posted") + (poll . "Posted a poll") + (edit . "Edited"))) + +(defun mastodon-notifications--alist-by-value (str field json) + "From JSON, return the alist whose FIELD value matches STR. +JSON is a list of alists." + (cl-some (lambda (y) + (when (string= str (alist-get field y)) + y)) + json)) + +(defun mastodon-notifications--group-accounts (ids json) + "For IDS, return account data in JSON." + (cl-loop + for x in ids + collect (mastodon-notifications--alist-by-value x 'id json))) + +(defun mastodon-notifications--format-note (group json 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 (eq 'follow-request type) - (let ((str (mastodon-tl--field - 'note - (mastodon-tl--field 'account note)))) - (if mastodon-notifications--profile-note-in-foll-reqs-max-length - (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) - str)))) - (status (mastodon-tl--field 'status note)) - (follower (alist-get 'username (alist-get 'account note))) - (toot (alist-get 'status note)) - (filtered (mastodon-tl--field 'filtered toot)) - (filters (when filtered - (mastodon-tl--current-filters filtered)))) - (if (and filtered (assoc "hide" filters)) - nil - (mastodon-tl--insert-status - ;; toot - (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 (eq type 'favourite) - (eq type 'boost)) - note) - (t - status)) - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler toot (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (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 (eq type 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default) - (concat - (propertize - (format "You have a follow request from... %s" - follower) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body)))))) - ((or (eq type 'favourite) - (eq type 'boost)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - (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 ((eq type 'boost) - "Boosted") - ((eq type 'favourite) - "Favourited") - ((eq type 'follow-request) - "Requested to follow") - ((eq type 'follow) - "Followed") - ((eq type 'mention) - "Mentioned") - ((eq type 'status) - "Posted") - ((eq type 'poll) - "Posted a poll") - ((eq type 'edit) - "Edited")))) - id - ;; base toot - (when (or (eq type 'favourite) - (eq type 'boost)) - status))))) - -(defun mastodon-notifications--by-type (note) + ;; (if (member type mastodon-notifications-grouped-types) + (let-alist group + ;; .sample_account_ids .status_id .notifications_count + ;; .most_recent_notifiation_id + (let* ((status (mastodon-notifications--alist-by-value + .status_id 'id (alist-get 'statuses json))) + (accounts (mastodon-notifications--group-accounts + .sample_account_ids (alist-get 'accounts json)))) + (insert (symbol-name type) "\n" + "accounts: " (mapconcat 'identity .sample_account_ids ", ") "\n" + (if (not (> .notifications_count (length .sample_account_ids))) + "" + (concat + "and" + (number-to-string + (- .notifications_count + (length .sample_account_ids)))) + "others \n") + ;; "count: " (number-to-string .notifications_count) + (alist-get type mastodon-notifications--action-alist) + "\n toot: " (or .status_id "") "\n" + "\n\n")) + )) + +;; non-grouped notifs: +;; (let* ((id (alist-get 'id note)) +;; (profile-note +;; (when (eq 'follow-request type) +;; (let ((str (mastodon-tl--field +;; 'note +;; (mastodon-tl--field 'account note)))) +;; (if mastodon-notifications--profile-note-in-foll-reqs-max-length +;; (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) +;; str)))) +;; (status (mastodon-tl--field 'status note)) +;; (follower (alist-get 'username (alist-get 'account note))) +;; (toot (alist-get 'status note)) +;; (filtered (mastodon-tl--field 'filtered toot)) +;; (filters (when filtered +;; (mastodon-tl--current-filters filtered)))) +;; (if (and filtered (assoc "hide" filters)) +;; nil +;; (mastodon-tl--insert-status +;; ;; toot +;; (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 (eq type 'favourite) +;; (eq type 'boost)) +;; note) +;; (t +;; status)) +;; ;; body +;; (let ((body (if-let ((match (assoc "warn" filters))) +;; (mastodon-tl--spoiler toot (cadr match)) +;; (mastodon-tl--clean-tabs-and-nl +;; (if (mastodon-tl--has-spoiler status) +;; (mastodon-tl--spoiler status) +;; (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 (eq type 'follow) +;; (propertize "Congratulations, you have a new follower!" +;; 'face 'default) +;; (concat +;; (propertize +;; (format "You have a follow request from... %s" +;; follower) +;; 'face 'default) +;; (when mastodon-notifications--profile-note-in-foll-reqs +;; (concat +;; ":\n" +;; (mastodon-notifications--comment-note-text body)))))) +;; ((or (eq type 'favourite) +;; (eq type 'boost)) +;; (mastodon-notifications--comment-note-text body)) +;; (t body))) +;; ;; author-byline +;; (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 +;; (alist-get type mastodon-notifications--action-alist) +;; )) +;; id +;; ;; base toot +;; (when (or (eq type 'favourite) +;; (eq type 'boost)) +;; status)))))) + +(defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. Call its function in that list on NOTE." - (let* ((type (mastodon-tl--field 'type note)) - (fun (cdr (assoc type mastodon-notifications--types-alist))) - (start-pos (point))) - (when fun - (funcall fun note) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point)))))) + (cl-loop for g in groups + for type = (alist-get 'type g) + for fun = (cdr (assoc type mastodon-notifications--types-alist)) + for start-pos = (point) + do (when fun + (funcall fun g json) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." (if (seq-empty-p json) (user-error "Looks like you have no (more) notifications for now") - (mapc #'mastodon-notifications--by-type json) - (goto-char (point-min)))) + (let ((groups (alist-get 'notification_groups json))) + ;; (mapc (lambda (x) + (mastodon-notifications--by-type groups json) + ;; grouped) + (goto-char (point-min))))) (defun mastodon-notifications--get-mentions () "Display mention notifications in buffer." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a8714f3..cc02e8a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -366,7 +366,8 @@ from the server and load anew." 'mastodon-notifications--timeline type (when max-id - `(("max_id" . ,(mastodon-tl--buffer-property 'max-id))))) + `(("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) + nil nil nil "v2") (with-current-buffer buffer (use-local-map mastodon-notifications--map))))) -- cgit v1.2.3 From 7edfe0c4828145c75e5cb2e260c60463f8b24a4d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:20:56 +0200 Subject: remove notifs type funs --- lisp/mastodon-notifications.el | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 0e27ca0..6e21744 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -162,40 +162,6 @@ Can be called in notifications view or in follow-requests view." (interactive) (mastodon-notifications--follow-request-process :reject)) -(defun mastodon-notifications--mention (group json) - "Format for a `mention' NOTE." - (mastodon-notifications--format-note group json 'mention)) - -(defun mastodon-notifications--follow (group json) - "Format for a `follow' NOTE." - (mastodon-notifications--format-note group json 'follow)) - -(defun mastodon-notifications--follow-request (group json) - "Format for a `follow-request' NOTE." - (mastodon-notifications--format-note group json 'follow-request)) - -(defun mastodon-notifications--favourite (group json) - "Format for a `favourite' NOTE." - (mastodon-notifications--format-note group json 'favourite)) - -(defun mastodon-notifications--reblog (group json) - "Format for a `boost' NOTE." - (mastodon-notifications--format-note group json 'reblog)) - -(defun mastodon-notifications--status (group json) - "Format for a `status' NOTE. -Status notifications are given when -`mastodon-tl--enable-notify-user-posts' has been set." - (mastodon-notifications--format-note group json 'status)) - -(defun mastodon-notifications--poll (group json) - "Format for a `poll' NOTE." - (mastodon-notifications--format-note group json 'poll)) - -(defun mastodon-notifications--edit (group json) - "Format for an `edit' NOTE." - (mastodon-notifications--format-note group json 'edit)) - (defun mastodon-notifications--comment-note-text (str) "Add comment face to all text in STR with `shr-text' face only." (with-temp-buffer -- cgit v1.2.3 From f3af53067b7cd7827ccf133e5e729aeed72ce807 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:21:08 +0200 Subject: update notifs action alist: match server types --- lisp/mastodon-notifications.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6e21744..46f2423 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -181,12 +181,14 @@ Can be called in notifications view or in follow-requests view." (defvar mastodon-notifications--action-alist '((reblog . "Boosted") (favourite . "Favourited") - (follow-request . "Requested to follow") + (follow_request . "Requested to follow") (follow . "Followed") (mention . "Mentioned") (status . "Posted") (poll . "Posted a poll") - (edit . "Edited"))) + (update . "Edited")) + "Action strings keyed by notification type. +Types are those of the Mastodon API.") (defun mastodon-notifications--alist-by-value (str field json) "From JSON, return the alist whose FIELD value matches STR. -- cgit v1.2.3 From 64fa8d9066b3a58895e595fc3ca44249edada5df Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:26:57 +0200 Subject: working v rough grouped notifs --- lisp/mastodon-notifications.el | 245 +++++++++++++++++++++++------------------ lisp/mastodon-tl.el | 28 +++-- 2 files changed, 153 insertions(+), 120 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 46f2423..a2c0453 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -204,123 +204,150 @@ JSON is a list of alists." for x in ids collect (mastodon-notifications--alist-by-value x 'id json))) -(defun mastodon-notifications--format-note (group json type) - "Format for a NOTE of TYPE." +(defun mastodon-notifications--format-note (group status accounts) + "Format for a GROUP notification. +JSON is the full notifications JSON." ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' - ;; (if (member type mastodon-notifications-grouped-types) (let-alist group ;; .sample_account_ids .status_id .notifications_count ;; .most_recent_notifiation_id - (let* ((status (mastodon-notifications--alist-by-value - .status_id 'id (alist-get 'statuses json))) - (accounts (mastodon-notifications--group-accounts - .sample_account_ids (alist-get 'accounts json)))) - (insert (symbol-name type) "\n" - "accounts: " (mapconcat 'identity .sample_account_ids ", ") "\n" - (if (not (> .notifications_count (length .sample_account_ids))) - "" - (concat - "and" - (number-to-string - (- .notifications_count - (length .sample_account_ids)))) - "others \n") - ;; "count: " (number-to-string .notifications_count) - (alist-get type mastodon-notifications--action-alist) - "\n toot: " (or .status_id "") "\n" - "\n\n")) - )) - -;; non-grouped notifs: -;; (let* ((id (alist-get 'id note)) -;; (profile-note -;; (when (eq 'follow-request type) -;; (let ((str (mastodon-tl--field -;; 'note -;; (mastodon-tl--field 'account note)))) -;; (if mastodon-notifications--profile-note-in-foll-reqs-max-length -;; (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) -;; str)))) -;; (status (mastodon-tl--field 'status note)) -;; (follower (alist-get 'username (alist-get 'account note))) -;; (toot (alist-get 'status note)) -;; (filtered (mastodon-tl--field 'filtered toot)) -;; (filters (when filtered -;; (mastodon-tl--current-filters filtered)))) -;; (if (and filtered (assoc "hide" filters)) -;; nil -;; (mastodon-tl--insert-status -;; ;; toot -;; (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 (eq type 'favourite) -;; (eq type 'boost)) -;; note) -;; (t -;; status)) -;; ;; body -;; (let ((body (if-let ((match (assoc "warn" filters))) -;; (mastodon-tl--spoiler toot (cadr match)) -;; (mastodon-tl--clean-tabs-and-nl -;; (if (mastodon-tl--has-spoiler status) -;; (mastodon-tl--spoiler status) -;; (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 (eq type 'follow) -;; (propertize "Congratulations, you have a new follower!" -;; 'face 'default) -;; (concat -;; (propertize -;; (format "You have a follow request from... %s" -;; follower) -;; 'face 'default) -;; (when mastodon-notifications--profile-note-in-foll-reqs -;; (concat -;; ":\n" -;; (mastodon-notifications--comment-note-text body)))))) -;; ((or (eq type 'favourite) -;; (eq type 'boost)) -;; (mastodon-notifications--comment-note-text body)) -;; (t body))) -;; ;; author-byline -;; (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 -;; (alist-get type mastodon-notifications--action-alist) -;; )) -;; id -;; ;; base toot -;; (when (or (eq type 'favourite) -;; (eq type 'boost)) -;; status)))))) + (let* ((type .type) + (type-sym (intern .type)) + (profile-note + (when (eq type-sym 'follow-request) + (let ((str (mastodon-tl--field + 'note + (car accounts)))) + (if mastodon-notifications--profile-note-in-foll-reqs-max-length + (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) + str)))) + (follower (car .sample_account_ids)) + (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (filters (when filtered + (mastodon-tl--current-filters filtered)))) + (if (and filtered (assoc "hide" filters)) + nil + (mastodon-tl--insert-status + ;; toot + (if (member type-sym '(follow follow_request)) + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + (cons '(reblog (id . nil)) status) ;;note)) + ;; reblogs/faves use 'note' to process their own json not the + ;; toot's. this ensures following etc. work on such notifs + status) ;; FIXME: fix following on these notifs + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler toot (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type 'follow-request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow-request) + (concat + (propertize + (format "You have a follow request from... %s" + follower) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite boost)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + (lambda (&rest _args) + (mastodon-notifications--byline-account accounts status)) + ;; action-byline + (lambda (_status) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + .status_id + ;; base toot + (when (member type-sym '(favourite boost)) + status) + nil nil nil nil + nil group))))) ;; insert status still needs our group data + +;; FIXME: REFACTOR with -tl--byline: +;; we provide account directly, rather than let-alisting toot +;; almost everything is .account.field anyway +;; but toot still needed also, for attachments, etc. +(defun mastodon-notifications--byline-account + (accounts toot &optional avatar domain) + "Propertize author byline ACCOUNT for TOOT, the item responded to. +With arg AVATAR, include the account's avatar image. +When DOMAIN, force inclusion of user's domain in their handle." + (cl-loop + for account in accounts + concat + (let-alist account + (concat + ;; avatar insertion moved up to `mastodon-tl--byline' by default to + ;; be outside 'byline propt. + (when (and avatar ; used by `mastodon-profile--format-user' + mastodon-tl--show-avatars + mastodon-tl--display-media-p + (mastodon-tl--image-trans-check)) + (mastodon-media--get-avatar-rendering .avatar)) + ;; username: + (propertize (if (not (string-empty-p .display_name)) + .display_name + .username) + 'face 'mastodon-display-name-face + ;; enable playing of videos when point is on byline: + 'attachments (mastodon-tl--get-attachments-for-byline toot) + 'keymap mastodon-tl--byline-link-keymap + ;; echo faves count when point on post author name: + ;; which is where --goto-next-toot puts point. + 'help-echo + ;; but don't add it to "following"/"follows" on profile views: + ;; we don't have a tl--buffer-spec yet: + (unless (or (string-suffix-p "-followers*" (buffer-name)) + (string-suffix-p "-following*" (buffer-name))) + (mastodon-tl--format-byline-help-echo toot))) + ;; handle: + " (" + (propertize (concat "@" .acct + (when domain + (concat "@" + (url-host + (url-generic-parse-url .url))))) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'account account + 'shr-url .url + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" .acct) + 'help-echo (concat "Browse user profile of @" .acct)) + ")" + (if (< 1 (length accounts)) "\n" ""))))) (defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. Call its function in that list on NOTE." - (cl-loop for g in groups - for type = (alist-get 'type g) - for fun = (cdr (assoc type mastodon-notifications--types-alist)) - for start-pos = (point) - do (when fun - (funcall fun g json) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point)))))) + (setq masto-grouped-notifs json) + (cl-loop + for g in groups + for start-pos = (point) + for accounts = (mastodon-notifications--group-accounts + (alist-get 'sample_account_ids g) + (alist-get 'accounts json)) + for status = (mastodon-notifications--alist-by-value + (alist-get 'status_id g) 'id + (alist-get 'statuses json)) + do (mastodon-notifications--format-note g status accounts) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2e0588f..f611c89 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -711,7 +711,8 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (image-transforms-p))) (defun mastodon-tl--byline (toot author-byline action-byline - &optional detailed-p domain base-toot) + &optional detailed-p domain base-toot + group) "Generate byline for TOOT. AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. @@ -723,13 +724,15 @@ this just means displaying toot client. When DOMAIN, force inclusion of user's domain in their handle. BASE-TOOT is JSON for the base toot, if any." (let* ((created-time - ;; bosts and faves in notifs view - ;; (makes timestamps be for the original toot not the boost/fave): - (or (mastodon-tl--field 'created_at - (mastodon-tl--field 'status toot)) - ;; all other toots, inc. boosts/faves in timelines: - ;; (mastodon-tl--field auto fetches from reblogs if needed): - (mastodon-tl--field 'created_at toot))) + (if group + (mastodon-tl--field 'latest_page_notification_at group) + ;; bosts and faves in notifs view + ;; (makes timestamps be for the original toot not the boost/fave): + (or (mastodon-tl--field 'created_at + (mastodon-tl--field 'status toot)) + ;; all other toots, inc. boosts/faves in timelines: + ;; (mastodon-tl--field auto fetches from reblogs if needed): + (mastodon-tl--field 'created_at toot)))) (parsed-time (date-to-time created-time)) (faved (eq t (mastodon-tl--field 'favourited toot))) (boosted (eq t (mastodon-tl--field 'reblogged toot))) @@ -1519,7 +1522,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id base-toot - detailed-p thread domain unfolded no-byline) + detailed-p thread domain unfolded no-byline group) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author @@ -1539,7 +1542,10 @@ 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." - (let* ((reply-to-id (alist-get 'in_reply_to_id toot)) + (let* ((reply-to-id + (if group + (alist-get 'status_id group) + (alist-get 'in_reply_to_id toot))) (after-reply-status-p (when (and thread reply-to-id) (mastodon-tl--after-reply-status reply-to-id))) @@ -1572,7 +1578,7 @@ NO-BYLINE means just insert toot body, used for folding." "\n" (unless no-byline (mastodon-tl--byline toot author-byline action-byline - detailed-p domain base-toot))) + detailed-p domain base-toot group))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id -- cgit v1.2.3 From c714d1524d2f369228252d265f0a23fe1c166b14 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 10:05:28 +0200 Subject: fix foll_reqs, add group/accounts props to notifs --- lisp/mastodon-notifications.el | 15 +++++++-------- lisp/mastodon-tl.el | 10 ++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a2c0453..a67ec0f 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -214,14 +214,13 @@ JSON is the full notifications JSON." (let* ((type .type) (type-sym (intern .type)) (profile-note - (when (eq type-sym 'follow-request) - (let ((str (mastodon-tl--field - 'note - (car accounts)))) + (when (eq type-sym 'follow_request) + (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) (follower (car .sample_account_ids)) + (follower-name (mastodon-tl--field 'username (car accounts))) (filtered (mastodon-tl--field 'filtered status)) ;;toot)) (filters (when filtered (mastodon-tl--current-filters filtered)))) @@ -242,17 +241,17 @@ JSON is the full notifications JSON." (mastodon-tl--clean-tabs-and-nl (if (mastodon-tl--has-spoiler status) (mastodon-tl--spoiler status) - (if (eq type 'follow-request) + (if (eq type-sym 'follow_request) (mastodon-tl--render-text profile-note) (mastodon-tl--content status))))))) (cond ((eq type-sym 'follow) (propertize "Congratulations, you have a new follower!" 'face 'default)) - ((eq type-sym 'follow-request) + ((eq type-sym 'follow_request) (concat (propertize (format "You have a follow request from... %s" - follower) + follower-name) 'face 'default) (when mastodon-notifications--profile-note-in-foll-reqs (concat @@ -273,7 +272,7 @@ JSON is the full notifications JSON." (when (member type-sym '(favourite boost)) status) nil nil nil nil - nil group))))) ;; insert status still needs our group data + nil group accounts))))) ;; insert status still needs our group data ;; FIXME: REFACTOR with -tl--byline: ;; we provide account directly, rather than let-alisting toot diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f611c89..1b3b9ec 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1522,7 +1522,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id base-toot - detailed-p thread domain unfolded no-byline group) + detailed-p thread domain unfolded no-byline group accounts) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author @@ -1549,7 +1549,7 @@ NO-BYLINE means just insert toot body, used for folding." (after-reply-status-p (when (and thread reply-to-id) (mastodon-tl--after-reply-status reply-to-id))) - (type (alist-get 'type toot)) + (type (alist-get 'type (or group toot))) (toot-foldable (and mastodon-tl--fold-toots-at-length (length> body mastodon-tl--fold-toots-at-length)))) @@ -1590,9 +1590,11 @@ NO-BYLINE means just insert toot body, used for folding." 'item-json toot 'base-toot base-toot 'cursor-face 'mastodon-cursor-highlight-face - 'notification-type type 'toot-foldable toot-foldable - 'toot-folded (and toot-foldable (not unfolded))) + 'toot-folded (and toot-foldable (not unfolded)) + 'notification-type type + 'notification-group group + 'notification-accounts accounts) (if no-byline "" "\n")))) (defun mastodon-tl--is-reply (toot) -- cgit v1.2.3 From 17ba291ba8b8d1231116af5654f40b80806f4260 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 10:56:58 +0200 Subject: mastodon.el: remove force logic from mastodon-notifications-get. we have an update function in notifs view. i think if we run this command, we always want to also check for new notifs. --- lisp/mastodon.el | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index cc02e8a..80b6d8c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -347,29 +347,25 @@ If REPLY-JSON is the json of the toot being replied to." (mastodon-toot--compose-buffer user reply-to-id reply-json)) ;;;###autoload -(defun mastodon-notifications-get (&optional type buffer-name force max-id) +(defun mastodon-notifications-get (&optional type buffer-name max-id) "Display NOTIFICATIONS in buffer. Optionally only print notifications of type TYPE, a string. BUFFER-NAME is added to \"*mastodon-\" to create the buffer name. -FORCE means do not try to update an existing buffer, but fetch -from the server and load anew." +MAX-ID is a request parameter for pagination." (interactive) (let* ((buffer-name (or buffer-name "notifications")) (buffer (concat "*mastodon-" buffer-name "*"))) - (if (and (not force) (get-buffer buffer)) - (progn (pop-to-buffer buffer '(display-buffer-same-window)) - (mastodon-tl--update)) - (message "Loading your notifications...") - (mastodon-tl--init-sync - buffer-name - "notifications" - 'mastodon-notifications--timeline - type - (when max-id - `(("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) - nil nil nil "v2") - (with-current-buffer buffer - (use-local-map mastodon-notifications--map))))) + (message "Loading your notifications...") + (mastodon-tl--init-sync + buffer-name + "notifications" + 'mastodon-notifications--timeline + type + (when max-id + `(("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) + nil nil nil "v2") + (with-current-buffer (get-buffer-create buffer) + (use-local-map mastodon-notifications--map)))) ;; URL lookup: should be available even if `mastodon.el' not loaded: @@ -379,7 +375,8 @@ from the server and load anew." Does a WebFinger lookup on the server. URL can be arg QUERY-URL, or URL at point, or provided by the user. If a status or account is found, load it in `mastodon.el', if -not, just browse the URL in the normal fashion." +not, just browse the URL in the normal fashion. +If FORCE, do a lookup regardless of the result of `mastodon--fedi-url-p'." (interactive) (let* ((query (or query-url (mastodon-tl--property 'shr-url :no-move) -- cgit v1.2.3 From 95940ee54de27f4a76860c8932ac339db2b664f3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 11:16:44 +0200 Subject: notifs: type always reblog, not boost --- lisp/mastodon-notifications.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a67ec0f..73c20f1 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -175,7 +175,7 @@ Can be called in notifications view or in follow-requests view." (buffer-string))) (defvar mastodon-notifications-grouped-types - '(follow boost favourite) + '(follow reblog favourite) "List of notification types for which grouping is implemented.") (defvar mastodon-notifications--action-alist @@ -257,7 +257,7 @@ JSON is the full notifications JSON." (concat ":\n" (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite boost)) + ((member type-sym '(favourite reblog)) (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline @@ -269,7 +269,7 @@ JSON is the full notifications JSON." (alist-get type-sym mastodon-notifications--action-alist))) .status_id ;; base toot - (when (member type-sym '(favourite boost)) + (when (member type-sym '(favourite reblog)) status) nil nil nil nil nil group accounts))))) ;; insert status still needs our group data -- cgit v1.2.3 From 27c3165f7ffb4c52f3a8b0d65cb360ceda43aeff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 11:58:50 +0200 Subject: tl.el: cull :force arg for notifs reload --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1b3b9ec..d08baf2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2757,7 +2757,7 @@ Aims to respect any pagination in effect." ((eq type 'mentions) (mastodon-notifications--get-mentions)) ((eq type 'notifications) - (mastodon-notifications-get nil nil :force max-id)) + (mastodon-notifications-get nil nil max-id)) ((eq type 'profile-statuses-no-boosts) ;; TODO: max-id arg needed here also (mastodon-profile--open-statuses-no-reblogs)) -- cgit v1.2.3 From 0c371eb6da2f34850050501e00ab7e4974d62690 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 14:59:39 +0200 Subject: notifs list boosters/favers, use local notif data if poss --- lisp/mastodon-toot.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9aeb790..386b720 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -522,21 +522,33 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement." (defun mastodon-toot--list-boosters () "List the boosters of toot at point." (interactive) - (mastodon-toot--list-boosters-or-favers)) + ;; use grouped notifs data if present: + ;; only send accounts as arg if type matches notif type we are acting + ;; on, to prevent showing accounts for a boost notif when asking for + ;; favers, and vice versa. + (let* ((type (mastodon-tl--property 'notification-type :no-move)) + (accounts (when (string= type "reblog") + (mastodon-tl--property 'notification-accounts :no-move)))) + (mastodon-toot--list-boosters-or-favers nil accounts))) (defun mastodon-toot--list-favouriters () "List the favouriters of toot at point." (interactive) - (mastodon-toot--list-boosters-or-favers :favourite)) + (let* ((type (mastodon-tl--property 'notification-type :no-move)) + (accounts (when (string= type "favourite") + (mastodon-tl--property 'notification-accounts :no-move)))) + (mastodon-toot--list-boosters-or-favers :favourite accounts))) -(defun mastodon-toot--list-boosters-or-favers (&optional favourite) +(defun mastodon-toot--list-boosters-or-favers (&optional favourite accounts) "List the favouriters or boosters of toot at point. With FAVOURITE, list favouriters, else list boosters." (mastodon-toot--with-toot-item - (let* ((endpoint (if favourite "favourited_by" "reblogged_by")) - (url (mastodon-http--api (format "statuses/%s/%s" id endpoint))) - (params '(("limit" . "80"))) - (json (mastodon-http--get-json url params))) + (let* ((endpoint (unless accounts + (if favourite "favourited_by" "reblogged_by"))) + (url (unless accounts + (mastodon-http--api (format "statuses/%s/%s" id endpoint)))) + (params (unless accounts '(("limit" . "80")))) + (json (or accounts (mastodon-http--get-json url params)))) (if (eq (caar json) 'error) (user-error "%s (Status does not exist or is private)" (alist-get 'error json)) -- cgit v1.2.3 From 3190c2833a1fbaeafe82585e7e6d494f8081b597 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Oct 2024 12:43:06 +0200 Subject: tl.el: reorg byline author/action byline logic the base idea is to separate our logic of author byline, and action byline. previously author-byline function would indifferently handle booster if a boost, else author. now it is always an author, and we implement booster byline separately. this should pave the way for bylines at top of posts, and should be clearer and simpler also. - move booster action-byline elt from byline to insert-status (outside byline proper) - factor out byline-handle/byline-username funs - factor our byline-booster/byline-booster-str funs this breaks notifs byline logic. we will fix it subsequently. --- lisp/mastodon-tl.el | 154 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 93 insertions(+), 61 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d08baf2..0f04e58 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -589,51 +589,68 @@ Do so if type of status at poins is not follow_request/follow." (string= type "follow")) ; no counts for these (message "%s" echo))))) -(defun mastodon-tl--byline-author (toot &optional avatar domain) +(defun mastodon-tl--byline-username (toot) + "Format a byline username from account in TOOT." + (let-alist (alist-get 'account toot) + (propertize (if (not (string-empty-p .display_name)) + .display_name + .username) + 'face 'mastodon-display-name-face + ;; enable playing of videos when point is on byline: + 'attachments (mastodon-tl--get-attachments-for-byline toot) + 'keymap mastodon-tl--byline-link-keymap + ;; echo faves count when point on post author name: + ;; which is where --goto-next-toot puts point. + 'help-echo + ;; but don't add it to "following"/"follows" on + ;; profile views: we don't have a tl--buffer-spec + ;; yet: + (unless (or (string-suffix-p "-followers*" (buffer-name)) + (string-suffix-p "-following*" (buffer-name))) + (mastodon-tl--format-byline-help-echo toot))))) + +(defun mastodon-tl--byline-handle (toot &optional domain) + "Format a byline handle from account in TOOT. +DOMAIN is optionally added to the handle." + (let-alist (alist-get 'account toot) + (propertize (concat "@" .acct + (when domain + (concat "@" + (url-host + (url-generic-parse-url .url))))) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'account .account + 'shr-url .url + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" .acct) + 'help-echo (concat "Browse user profile of @" .acct)))) + +(defun mastodon-tl--byline-author (toot &optional avatar domain base) "Propertize author of TOOT. +If TOOT contains a reblog, return author of reblogged item. With arg AVATAR, include the account's avatar image. -When DOMAIN, force inclusion of user's domain in their handle." - (let-alist toot +When DOMAIN, force inclusion of user's domain in their handle. +BASE means to use data from the base item (reblog slot) if possible. +If BASE is nil, we are a boosted byline, so show less info." + (let* ((data (if base + (mastodon-tl--toot-or-base toot) + toot))) (concat - ;; avatar insertion moved up to `mastodon-tl--byline' by default to be - ;; outside 'byline propt. + ;; avatar insertion moved up to `mastodon-tl--byline' by default to + ;; be outside 'byline propt. (when (and avatar ; used by `mastodon-profile--format-user' mastodon-tl--show-avatars mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) - (mastodon-media--get-avatar-rendering .account.avatar)) - ;; username: - (propertize (if (not (string-empty-p .account.display_name)) - .account.display_name - .account.username) - 'face 'mastodon-display-name-face - ;; enable playing of videos when point is on byline: - 'attachments (mastodon-tl--get-attachments-for-byline toot) - 'keymap mastodon-tl--byline-link-keymap - ;; echo faves count when point on post author name: - ;; which is where --goto-next-toot puts point. - 'help-echo - ;; but don't add it to "following"/"follows" on profile views: - ;; we don't have a tl--buffer-spec yet: - (unless (or (string-suffix-p "-followers*" (buffer-name)) - (string-suffix-p "-following*" (buffer-name))) - (mastodon-tl--format-byline-help-echo toot))) - ;; handle: - " (" - (propertize (concat "@" .account.acct - (when domain - (concat "@" - (url-host - (url-generic-parse-url .account.url))))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'account .account - 'shr-url .account.url - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" .account.acct) - 'help-echo (concat "Browse user profile of @" .account.acct)) - ")"))) + (mastodon-media--get-avatar-rendering + (alist-get 'avatar + (alist-get 'account data)))) + (if (not base) + (mastodon-tl--byline-handle data domain) + (concat (mastodon-tl--byline-username data) + " (" (mastodon-tl--byline-handle data domain) ")"))))) (defun mastodon-tl--format-byline-help-echo (toot) "Format a help-echo for byline of TOOT. @@ -681,13 +698,28 @@ The result is added as an attachments property to author-byline." :type .type))) media))) -(defun mastodon-tl--byline-boosted (toot) - "Add byline for boosted data from TOOT." +(defun mastodon-tl--byline-booster (toot) + "Add author byline for booster from TOOT. +Only return something if TOOT contains a reblog." (let ((reblog (alist-get 'reblog toot))) - (when reblog - (concat - "\n " (propertize "Boosted" 'face 'mastodon-boosted-face) - " " (mastodon-tl--byline-author reblog))))) + (if reblog + (concat + " " (mastodon-tl--byline-author toot)) + ""))) + +(defun mastodon-tl--byline-booster-str (toot) + "Format boosted string for action byline. +Only return string if TOOT contains a reblog." + (let ((reblog (alist-get 'reblog toot))) + (if reblog + (concat + " " (propertize "boosted" 'face 'mastodon-boosted-face) "\n") + ""))) + +(defun mastodon-tl--byline-boost (toot) + "Format a boost action-byline element for TOOT." + (concat (mastodon-tl--byline-booster toot) + (mastodon-tl--byline-booster-str toot))) (defun mastodon-tl--format-faved-or-boosted-byline (letter) "Format the byline marker for a boosted or favourited status. @@ -710,9 +742,8 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (image-type-available-p 'imagemagick) (image-transforms-p))) -(defun mastodon-tl--byline (toot author-byline action-byline - &optional detailed-p domain base-toot - group) +(defun mastodon-tl--byline (toot author-byline &optional detailed-p + domain base-toot group) "Generate byline for TOOT. AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. @@ -738,11 +769,11 @@ BASE-TOOT is JSON for the base toot, if any." (boosted (eq t (mastodon-tl--field 'reblogged toot))) (bookmarked (eq t (mastodon-tl--field 'bookmarked toot))) (visibility (mastodon-tl--field 'visibility toot)) - (account (alist-get 'account toot)) - (avatar-url (alist-get 'avatar account)) (type (alist-get 'type toot)) (base-toot-maybe (or base-toot ;; show edits for notifs (mastodon-tl--toot-or-base toot))) ;; for boosts + (account (alist-get 'account base-toot-maybe)) + (avatar-url (alist-get 'avatar account)) (edited-time (alist-get 'edited_at base-toot-maybe)) (edited-parsed (when edited-time (date-to-time edited-time)))) (concat @@ -762,17 +793,16 @@ BASE-TOOT is JSON for the base toot, if any." (when bookmarked (mastodon-tl--format-faved-or-boosted-byline (mastodon-tl--symbol 'bookmark)))) - ;; we remove avatars from the byline also, so that they also do not mess - ;; with `mastodon-tl--goto-next-item': + ;; we remove avatars from the byline also, so that they also do not + ;; mess with `mastodon-tl--goto-next-item': (when (and mastodon-tl--show-avatars mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering avatar-url)) (propertize (concat - ;; we propertize help-echo format faves for author name - ;; in `mastodon-tl--byline-author' - (funcall author-byline toot nil domain) + ;; NB: action-byline (boost) is now added in insert-status, so no + ;; longer part of the byline. ;; visibility: (cond ((string= visibility "direct") (propertize (concat " " (mastodon-tl--symbol 'direct)) @@ -780,8 +810,8 @@ BASE-TOOT is JSON for the base toot, if any." ((string= visibility "private") (propertize (concat " " (mastodon-tl--symbol 'private)) 'help-echo visibility))) - ;;action byline: - (funcall action-byline toot) + ;; (base) author byline: + (funcall author-byline toot nil domain :base) " " ;; timestamp: (propertize @@ -1112,7 +1142,7 @@ content should be hidden." (save-excursion (goto-char (point-min)) (while (not (string= "No more items" ; improve this hack test! - (mastodon-tl--goto-next-item :no-refresh))) + (mastodon-tl--goto-next-item :no-refresh))) (let* ((json (mastodon-tl--property 'item-json :no-move)) (cw (alist-get 'spoiler_text json))) (when (not (string= "" cw)) @@ -1576,9 +1606,11 @@ NO-BYLINE means just insert toot body, used for folding." 'toot-body t) ;; includes newlines etc. for folding ;; byline: "\n" - (unless no-byline - (mastodon-tl--byline toot author-byline action-byline - detailed-p domain base-toot group))) + (if no-byline + "" + (concat (funcall action-byline toot) + (mastodon-tl--byline toot author-byline detailed-p + domain base-toot group)))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -1665,7 +1697,7 @@ NO-BYLINE means just insert toot body, used for folding." (mastodon-tl--insert-status toot (mastodon-tl--clean-tabs-and-nl spoiler-or-content) - 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted + #'mastodon-tl--byline-author #'mastodon-tl--byline-boost nil nil detailed-p thread domain unfolded no-byline)))) (defun mastodon-tl--timeline (toots &optional thread domain) -- cgit v1.2.3 From 64a0a0a276b5cadc8b4d98ee28ef1c23b4a799b7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Oct 2024 17:30:41 +0200 Subject: use byline-username/-handle in notifications--byline-accounts --- lisp/mastodon-notifications.el | 71 ++++++++++++++---------------------------- lisp/mastodon-tl.el | 10 +++--- 2 files changed, 29 insertions(+), 52 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 73c20f1..7632173 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -278,56 +278,33 @@ JSON is the full notifications JSON." ;; we provide account directly, rather than let-alisting toot ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. -(defun mastodon-notifications--byline-account - (accounts toot &optional avatar domain) +(defun mastodon-notifications--byline-accounts + (accounts toot group &optional avatar domain) "Propertize author byline ACCOUNT for TOOT, the item responded to. With arg AVATAR, include the account's avatar image. When DOMAIN, force inclusion of user's domain in their handle." - (cl-loop - for account in accounts - concat - (let-alist account - (concat - ;; avatar insertion moved up to `mastodon-tl--byline' by default to - ;; be outside 'byline propt. - (when (and avatar ; used by `mastodon-profile--format-user' - mastodon-tl--show-avatars - mastodon-tl--display-media-p - (mastodon-tl--image-trans-check)) - (mastodon-media--get-avatar-rendering .avatar)) - ;; username: - (propertize (if (not (string-empty-p .display_name)) - .display_name - .username) - 'face 'mastodon-display-name-face - ;; enable playing of videos when point is on byline: - 'attachments (mastodon-tl--get-attachments-for-byline toot) - 'keymap mastodon-tl--byline-link-keymap - ;; echo faves count when point on post author name: - ;; which is where --goto-next-toot puts point. - 'help-echo - ;; but don't add it to "following"/"follows" on profile views: - ;; we don't have a tl--buffer-spec yet: - (unless (or (string-suffix-p "-followers*" (buffer-name)) - (string-suffix-p "-following*" (buffer-name))) - (mastodon-tl--format-byline-help-echo toot))) - ;; handle: - " (" - (propertize (concat "@" .acct - (when domain - (concat "@" - (url-host - (url-generic-parse-url .url))))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'account account - 'shr-url .url - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" .acct) - 'help-echo (concat "Browse user profile of @" .acct)) - ")" - (if (< 1 (length accounts)) "\n" ""))))) + (let ((others-count (- (alist-get 'notifications_count group) + (length accounts)))) + (concat + (cl-loop + for account in accounts + concat + (let-alist account + (concat + ;; avatar insertion moved up to `mastodon-tl--byline' by default to + ;; be outside 'byline propt. + (when (and avatar ; used by `mastodon-profile--format-user' + mastodon-tl--show-avatars + mastodon-tl--display-media-p + (mastodon-tl--image-trans-check)) + (mastodon-media--get-avatar-rendering .avatar)) + ;; username: + (mastodon-tl--byline-username toot account) + ;; handle: + " (" (mastodon-tl--byline-handle toot nil account) ")" + (if (< 1 (length accounts)) "\n" "")))) + (if (< 0 others-count) + (format "and %s others" others-count))))) (defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 0f04e58..ca5ec6f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -589,9 +589,9 @@ Do so if type of status at poins is not follow_request/follow." (string= type "follow")) ; no counts for these (message "%s" echo))))) -(defun mastodon-tl--byline-username (toot) +(defun mastodon-tl--byline-username (toot &optional account) "Format a byline username from account in TOOT." - (let-alist (alist-get 'account toot) + (let-alist (or account (alist-get 'account toot)) (propertize (if (not (string-empty-p .display_name)) .display_name .username) @@ -609,10 +609,10 @@ Do so if type of status at poins is not follow_request/follow." (string-suffix-p "-following*" (buffer-name))) (mastodon-tl--format-byline-help-echo toot))))) -(defun mastodon-tl--byline-handle (toot &optional domain) +(defun mastodon-tl--byline-handle (toot &optional domain account) "Format a byline handle from account in TOOT. DOMAIN is optionally added to the handle." - (let-alist (alist-get 'account toot) + (let-alist (or account (alist-get 'account toot)) (propertize (concat "@" .acct (when domain (concat "@" @@ -621,7 +621,7 @@ DOMAIN is optionally added to the handle." 'face 'mastodon-handle-face 'mouse-face 'highlight 'mastodon-tab-stop 'user-handle - 'account .account + 'account account 'shr-url .url 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .acct) -- cgit v1.2.3 From 56e555945b06662bad0d687c1bc53fabe4beafed Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Oct 2024 18:05:29 +0200 Subject: WIP: hacking for grouped notifs to work w new byline code. --- lisp/mastodon-notifications.el | 13 ++++++++++--- lisp/mastodon-tl.el | 13 +++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 7632173..b758c6f 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -231,6 +231,7 @@ JSON is the full notifications JSON." (if (member type-sym '(follow follow_request)) ;; Using reblog with an empty id will mark this as something ;; non-boostable/non-favable. + ;; status (cons '(reblog (id . nil)) status) ;;note)) ;; reblogs/faves use 'note' to process their own json not the ;; toot's. this ensures following etc. work on such notifs @@ -261,10 +262,16 @@ JSON is the full notifications JSON." (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline - (lambda (&rest _args) - (mastodon-notifications--byline-account accounts status)) + (cond ((member type-sym '(favourite reblog mention)) + (lambda (&rest _args) + (mastodon-notifications--byline-accounts accounts status group))) + ((eq type-sym 'follow_request) + (lambda (&rest _args) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + (t #'mastodon-tl--byline-author)) + ;; #'mastodon-tl--byline-author ;; action-byline - (lambda (_status) + (lambda (&rest _args) (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist))) .status_id diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ca5ec6f..cf7f9aa 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -589,6 +589,11 @@ Do so if type of status at poins is not follow_request/follow." (string= type "follow")) ; no counts for these (message "%s" echo))))) +;; FIXME: now that this can also be used for non byline rendering, let's remove +;; the toot arg, and deal with attachments higher up (on real author +;; byline only) +;; removing toot arg makes it easier to render notifs that have no status +;; (foll_reqs) (defun mastodon-tl--byline-username (toot &optional account) "Format a byline username from account in TOOT." (let-alist (or account (alist-get 'account toot)) @@ -627,6 +632,11 @@ DOMAIN is optionally added to the handle." 'mastodon-handle (concat "@" .acct) 'help-echo (concat "Browse user profile of @" .acct)))) +(defun mastodon-tl--byline-uname-+-handle (data &optional domain account) + "" + (concat (mastodon-tl--byline-username data account) + " (" (mastodon-tl--byline-handle data domain account) ")")) + (defun mastodon-tl--byline-author (toot &optional avatar domain base) "Propertize author of TOOT. If TOOT contains a reblog, return author of reblogged item. @@ -649,8 +659,7 @@ If BASE is nil, we are a boosted byline, so show less info." (alist-get 'account data)))) (if (not base) (mastodon-tl--byline-handle data domain) - (concat (mastodon-tl--byline-username data) - " (" (mastodon-tl--byline-handle data domain) ")"))))) + (mastodon-tl--byline-uname-+-handle data domain))))) (defun mastodon-tl--format-byline-help-echo (toot) "Format a help-echo for byline of TOOT. -- cgit v1.2.3 From 96057a1b090b93adf4e72781e8894aae9f158588 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 13 Oct 2024 11:00:11 +0200 Subject: transient: factor out a field infix, to simplify mastodon-profile-fields --- lisp/mastodon-transient.el | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index fe70eac..dcf8fa4 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -173,15 +173,15 @@ the format fields.X.keyname." [:description "Fields" ["Name" - ("1 n" "" "fields.1.name" :alist-key fields.1.name :class mastodon-transient-field) - ("2 n" "" "fields.2.name" :alist-key fields.2.name :class mastodon-transient-field) - ("3 n" "" "fields.3.name" :alist-key fields.3.name :class mastodon-transient-field) - ("4 n" "" "fields.4.name" :alist-key fields.4.name :class mastodon-transient-field)] + ("1 n" "" mastodon-transient-field-infix :alist-key fields.1.name) + ("2 n" "" mastodon-transient-field-infix :alist-key fields.2.name) + ("3 n" "" mastodon-transient-field-infix :alist-key fields.3.name) + ("4 n" "" mastodon-transient-field-infix :alist-key fields.4.name)] ["Value" - ("1 v" "" "fields.1.value" :alist-key fields.1.value :class mastodon-transient-field) - ("2 v" "" "fields.2.value" :alist-key fields.2.value :class mastodon-transient-field) - ("3 v" "" "fields.3.value" :alist-key fields.3.value :class mastodon-transient-field) - ("4 v" "" "fields.4.value" :alist-key fields.4.value :class mastodon-transient-field)]] + ("1 v" "" mastodon-transient-field-infix :alist-key fields.1.value) + ("2 v" "" mastodon-transient-field-infix :alist-key fields.2.value) + ("3 v" "" mastodon-transient-field-infix :alist-key fields.3.value) + ("4 v" "" mastodon-transient-field-infix :alist-key fields.4.value)]] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) ("C-c C-k" :info "Revert all changes")] @@ -193,9 +193,12 @@ the format fields.X.keyname." ;;; CLASSES (defclass mastodon-transient-field (tp-option-str) - ((always-read :initarg :always-read :initform t)) - "An infix option class for our options. -We always read.") + () + "An infix for our fields options.") + +(transient-define-infix mastodon-transient-field-infix () + :class 'mastodon-transient-field + :argument "junk") (cl-defmethod transient-init-value ((obj mastodon-transient-field)) "Initialize value of OBJ." -- cgit v1.2.3 From 11fc4f01c4934e5d687382f3ccb301cb8343a6d9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 13 Oct 2024 17:01:32 +0200 Subject: re-do display of card (link) author. #596 --- lisp/mastodon-tl.el | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3f06756..c4abbf0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -886,6 +886,7 @@ links in the text. If TOOT is nil no parsing occurs." (car region) (cdr region) (get-text-property (car region) 'shr-url)) (when (proper-list-p toot) ;; not on profile fields cons cells + ;; render card author maybe: (let* ((card (alist-get 'card toot)) (card-url (alist-get 'url card)) (authors (alist-get 'authors card)) @@ -894,7 +895,7 @@ links in the text. If TOOT is nil no parsing occurs." (when (and (string= url-no-query card-url) ;; only if we have an account's data: (alist-get 'account (car authors))) - (goto-char (point-max)) ;;(cdr region)) + (goto-char (point-max)) (mastodon-tl--insert-card-authors authors))))))) (buffer-string)))) @@ -903,17 +904,30 @@ links in the text. If TOOT is nil no parsing occurs." (insert (concat "\n(Authors: " - (cl-loop for x in authors - concat - (mastodon-tl--format-card-author x)) + (mapconcat #'mastodon-tl--format-card-author authors "\n") ")\n"))) (defun mastodon-tl--format-card-author (data) "Render card author DATA." ;; FIXME: update as needed, data contains "name" "url" and "account" - (let-alist data - (when .account - (mastodon-search--propertize-user .account)))) + (when (alist-get 'account data) ;.account + (let-alist (alist-get 'account data) ;.account + ;; FIXME: replace with refactored handle render fun + ;; in byline refactor branch: + (concat + (propertize .username + 'face 'mastodon-display-name-face + 'byline t + 'item-type 'user + 'item-id .id) + " " + (propertize (concat "@" .acct) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" .acct) + 'help-echo (concat "Browse user profile of @" .acct)))))) (defun mastodon-tl--process-link (toot start end url) "Process link URL in TOOT as hashtag, userhandle, or normal link. -- cgit v1.2.3 From f77c3b6334362c4bb7f8b41eb0a542eef2d19b64 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 09:57:15 +0200 Subject: flymake load-path dir-locals --- lisp/.dir-locals.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/.dir-locals.el b/lisp/.dir-locals.el index bcb8ba5..da012d6 100644 --- a/lisp/.dir-locals.el +++ b/lisp/.dir-locals.el @@ -1,7 +1,6 @@ -;;; Directory Local Variables +;;; Directory Local Variables -*- no-byte-compile: t -*- ;;; For more information see (info "(emacs) Directory Variables") -;; Preferred indentation style: ((nil . ((indent-tabs-mode . nil))) - ;; setting this makes package-lint look in the main file for deps: - (emacs-lisp-mode . ((package-lint-main-file . "mastodon.el")))) + (emacs-lisp-mode . ((elisp-flymake-byte-compile-load-path . load-path) + (package-lint-main-file . "mastodon.el")))) -- cgit v1.2.3 From 8b4d1cbf0727879e5cbeb2f8af985cea1683c771 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 10:04:52 +0200 Subject: no byline prop for card author --- lisp/mastodon-tl.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c4abbf0..b32fe70 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -917,7 +917,6 @@ links in the text. If TOOT is nil no parsing occurs." (concat (propertize .username 'face 'mastodon-display-name-face - 'byline t 'item-type 'user 'item-id .id) " " -- cgit v1.2.3 From 9b6769040e55b1c6372ee38266af42f92edf8a9c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 09:57:15 +0200 Subject: flymake load-path dir-locals --- lisp/.dir-locals.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/.dir-locals.el b/lisp/.dir-locals.el index bcb8ba5..da012d6 100644 --- a/lisp/.dir-locals.el +++ b/lisp/.dir-locals.el @@ -1,7 +1,6 @@ -;;; Directory Local Variables +;;; Directory Local Variables -*- no-byte-compile: t -*- ;;; For more information see (info "(emacs) Directory Variables") -;; Preferred indentation style: ((nil . ((indent-tabs-mode . nil))) - ;; setting this makes package-lint look in the main file for deps: - (emacs-lisp-mode . ((package-lint-main-file . "mastodon.el")))) + (emacs-lisp-mode . ((elisp-flymake-byte-compile-load-path . load-path) + (package-lint-main-file . "mastodon.el")))) -- cgit v1.2.3 From 652c17da292065d760d8ad455dba9dd26ac49ba1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 13:26:29 +0200 Subject: card authors tiny clean up. #596. --- lisp/mastodon-tl.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b32fe70..e2cba94 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -901,17 +901,18 @@ links in the text. If TOOT is nil no parsing occurs." (defun mastodon-tl--insert-card-authors (authors) "Insert a string of card AUTHORS." - (insert - (concat - "\n(Authors: " - (mapconcat #'mastodon-tl--format-card-author authors "\n") - ")\n"))) + (let ((authors-str (format "Author%s: " + (if (< 1 (length authors)) "s" "")))) + (insert + (concat + "\n(" authors-str + (mapconcat #'mastodon-tl--format-card-author authors "\n") + ")\n")))) (defun mastodon-tl--format-card-author (data) "Render card author DATA." - ;; FIXME: update as needed, data contains "name" "url" and "account" - (when (alist-get 'account data) ;.account - (let-alist (alist-get 'account data) ;.account + (when-let ((account (alist-get 'account data))) ;.account + (let-alist account ;.account ;; FIXME: replace with refactored handle render fun ;; in byline refactor branch: (concat -- cgit v1.2.3 From 17bcc1ff7659b4eb6845a564a094bb3cae4fadd9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 15:32:30 +0200 Subject: byline: help echo timestamps in numbers --- lisp/mastodon-tl.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2e0588f..81be479 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -781,12 +781,15 @@ BASE-TOOT is JSON for the base toot, if any." (funcall action-byline toot) " " ;; timestamp: - (propertize - (format-time-string mastodon-toot-timestamp-format parsed-time) - 'timestamp parsed-time - 'display (if mastodon-tl--enable-relative-timestamps - (mastodon-tl--relative-time-description parsed-time) - parsed-time)) + (let ((ts (format-time-string + mastodon-toot-timestamp-format parsed-time))) + (propertize ts + 'timestamp parsed-time + 'display + (if mastodon-tl--enable-relative-timestamps + (mastodon-tl--relative-time-description parsed-time) + parsed-time) + 'help-echo ts)) ;; detailed: (when detailed-p (let* ((app (alist-get 'application toot)) -- cgit v1.2.3 From e07fc229966a978fb22c741f40526301f204299f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 17:16:50 +0200 Subject: Revert "transient: factor out a field infix, to simplify mastodon-profile-fields" This reverts commit 96057a1b090b93adf4e72781e8894aae9f158588. --- lisp/mastodon-transient.el | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index dcf8fa4..fe70eac 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -173,15 +173,15 @@ the format fields.X.keyname." [:description "Fields" ["Name" - ("1 n" "" mastodon-transient-field-infix :alist-key fields.1.name) - ("2 n" "" mastodon-transient-field-infix :alist-key fields.2.name) - ("3 n" "" mastodon-transient-field-infix :alist-key fields.3.name) - ("4 n" "" mastodon-transient-field-infix :alist-key fields.4.name)] + ("1 n" "" "fields.1.name" :alist-key fields.1.name :class mastodon-transient-field) + ("2 n" "" "fields.2.name" :alist-key fields.2.name :class mastodon-transient-field) + ("3 n" "" "fields.3.name" :alist-key fields.3.name :class mastodon-transient-field) + ("4 n" "" "fields.4.name" :alist-key fields.4.name :class mastodon-transient-field)] ["Value" - ("1 v" "" mastodon-transient-field-infix :alist-key fields.1.value) - ("2 v" "" mastodon-transient-field-infix :alist-key fields.2.value) - ("3 v" "" mastodon-transient-field-infix :alist-key fields.3.value) - ("4 v" "" mastodon-transient-field-infix :alist-key fields.4.value)]] + ("1 v" "" "fields.1.value" :alist-key fields.1.value :class mastodon-transient-field) + ("2 v" "" "fields.2.value" :alist-key fields.2.value :class mastodon-transient-field) + ("3 v" "" "fields.3.value" :alist-key fields.3.value :class mastodon-transient-field) + ("4 v" "" "fields.4.value" :alist-key fields.4.value :class mastodon-transient-field)]] ["Update" ("C-c C-c" "Save settings" mastodon-profile-fields-update) ("C-c C-k" :info "Revert all changes")] @@ -193,12 +193,9 @@ the format fields.X.keyname." ;;; CLASSES (defclass mastodon-transient-field (tp-option-str) - () - "An infix for our fields options.") - -(transient-define-infix mastodon-transient-field-infix () - :class 'mastodon-transient-field - :argument "junk") + ((always-read :initarg :always-read :initform t)) + "An infix option class for our options. +We always read.") (cl-defmethod transient-init-value ((obj mastodon-transient-field)) "Initialize value of OBJ." -- cgit v1.2.3 From c1c0d3a71d5bf81ac9e6f0169716c9903e54df06 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 14 Oct 2024 19:19:38 +0200 Subject: implement rough trending links, and link timeline --- lisp/mastodon-search.el | 38 +++++++++++++++++++++++++++++++++++++- lisp/mastodon-tl.el | 13 ++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 7fc4de3..90519ed 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -97,6 +97,41 @@ QUERY is the string to search." (mastodon-search--view-trending "statuses" #'mastodon-tl--timeline)) +(defun mastodon-search--trending-links () + "Display a list of links trending on your instance." + (interactive) + (mastodon-search--view-trending "links" + #'mastodon-search--render-links)) + +(defun mastodon-search--render-links (links) + "Render trending LINKS." + (cl-loop for l in links + do (mastodon-search--render-link l))) + +(defun mastodon-search--render-link (link) + "Render a trending LINK." + (let-alist link + (insert + (propertize + (mastodon-tl--render-text + (concat "" .url "\n" .title) + link) + 'item-type 'link + 'item-json link + 'shr-url .url + 'byline t ;; nav + 'help-echo + (substitute-command-keys + "\\[`mastodon-search--load-link-posts'] to view a link's timeline")) + ;; TODO: display card link author here + "\n\n"))) + +(defun mastodon-search--load-link-posts () + "Load timeline of posts containing link at point." + (interactive) + (let* ((url (mastodon-tl--property 'shr-url))) + (mastodon-tl--link-timeline url))) + (defun mastodon-search--view-trending (type print-fun) "Display a list of tags trending on your instance. TYPE is a string, either tags, statuses, or links. @@ -109,7 +144,8 @@ PRINT-FUN is the function used to print the data from the response." (offset '(("offset" . "0"))) (params (push limit offset)) (data (mastodon-http--get-json url params)) - (buffer (get-buffer-create (format "*mastodon-trending-%s*" type)))) + (buffer (get-buffer-create + (format "*mastodon-trending-%s*" type)))) (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec (buffer-name buffer) (format "trends/%s" type) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 81be479..75bde95 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -279,6 +279,7 @@ etc.") ;; is already bound to w also (define-key map (kbd "u") #'mastodon-tl--update) (define-key map [remap shr-browse-url] #'mastodon-url-lookup) + (define-key map (kbd "M-RET") #'mastodon-search--load-link-posts) map) "The keymap to be set for shr.el generated links that are not images. We need to override the keymap so tabbing will navigate to all @@ -575,6 +576,14 @@ With a double PREFIX arg, limit results to your own instance." (concat "timelines/tag/" (if (listp tag) (car tag) tag)) ; must be /tag/:sth 'mastodon-tl--timeline nil params))) +(defun mastodon-tl--link-timeline (url) + "Load a link timeline, displaying posts containing URL." + (let ((endpoint (mastodon-http--api "timelines/link")) + (params `(("url" . ,url)))) + (mastodon-tl--init "links" "timelines/link" + 'mastodon-tl--timeline nil + params))) + ;;; BYLINES, etc. @@ -1987,7 +1996,9 @@ call this function after it is set or use something else." ((string= "*mastodon-toot-edits*" buffer-name) 'toot-edits) ((string= "*masto-image*" (buffer-name)) - 'mastodon-image)))) + 'mastodon-image) + ((mastodon-tl--endpoint-str-= "timelines/link") + 'link-timeline)))) (defun mastodon-tl--buffer-type-eq (type) "Return t if current buffer type is equal to symbol TYPE." -- cgit v1.2.3 From 03f308c695452e1d831d50e542f4760e2c29bbb5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 12:48:14 +0200 Subject: rough overhaul of notifs byline code for grouped notifications --- lisp/mastodon-notifications.el | 310 +++++++++++++++++++++++++---------------- lisp/mastodon-tl.el | 17 ++- 2 files changed, 199 insertions(+), 128 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b758c6f..aa38302 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -31,6 +31,7 @@ ;;; Code: (eval-when-compile (require 'subr-x)) +(require 'cl-lib) (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-params-async-json "mastodon-http") @@ -55,7 +56,12 @@ (autoload 'mastodon-tl--current-filters "mastodon-views") (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-notifications-get "mastodon") - +(autoload 'mastodon-tl--byline-uname-+-handle "mastodon-tl") +(autoload 'mastodon-tl--byline-username "mastodon-tl") +(autoload 'mastodon-tl--byline-handle "mastodon-tl") +(autoload 'mastodon-http--get-json "mastodon-http") +(autoload 'mastodon-media--get-avatar-rendering "mastodon-media") +(autoload 'mastodon-tl--image-trans-check "mastodon-tl") (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -81,6 +87,8 @@ make them unweildy." (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) (defvar mastodon-mode-map) +(defvar mastodon-tl--fold-toots-at-length) +(defvar mastodon-tl--show-avatars) (defvar mastodon-notifications--types-alist '(("follow" . mastodon-notifications--follow) @@ -95,13 +103,13 @@ make them unweildy." (defvar mastodon-notifications--response-alist '(("Followed" . "you") - ("Favourited" . "your status from") - ("Boosted" . "your status from") + ("Favourited" . "your post") + ("Boosted" . "your post") ("Mentioned" . "you") ("Posted a poll" . "that has now ended") ("Requested to follow" . "you") ("Posted" . "a post") - ("Edited" . "a post from")) + ("Edited" . "their post")) "Alist of subjects for notification types.") (defvar mastodon-notifications--map @@ -115,8 +123,9 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat " " (propertize message 'face 'highlight) - " " (cdr (assoc message mastodon-notifications--response-alist)))) + (concat "\n " (propertize message 'face 'highlight) + " " (cdr (assoc message mastodon-notifications--response-alist)) + "\n")) (defun mastodon-notifications--follow-request-process (&optional reject) "Process the follow request at point. @@ -206,141 +215,204 @@ JSON is a list of alists." (defun mastodon-notifications--format-note (group status accounts) "Format for a GROUP notification. -JSON is the full notifications JSON." - ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' - (let-alist group - ;; .sample_account_ids .status_id .notifications_count - ;; .most_recent_notifiation_id - (let* ((type .type) - (type-sym (intern .type)) - (profile-note - (when (eq type-sym 'follow_request) - (let ((str (mastodon-tl--field 'note (car accounts)))) - (if mastodon-notifications--profile-note-in-foll-reqs-max-length - (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) - str)))) - (follower (car .sample_account_ids)) - (follower-name (mastodon-tl--field 'username (car accounts))) - (filtered (mastodon-tl--field 'filtered status)) ;;toot)) - (filters (when filtered - (mastodon-tl--current-filters filtered)))) - (if (and filtered (assoc "hide" filters)) - nil - (mastodon-tl--insert-status - ;; toot - (if (member type-sym '(follow follow_request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; status - (cons '(reblog (id . nil)) status) ;;note)) - ;; reblogs/faves use 'note' to process their own json not the - ;; toot's. this ensures following etc. work on such notifs - status) ;; FIXME: fix following on these notifs - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler toot (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - (cond ((member type-sym '(favourite reblog mention)) - (lambda (&rest _args) - (mastodon-notifications--byline-accounts accounts status group))) - ((eq type-sym 'follow_request) - (lambda (&rest _args) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) - (t #'mastodon-tl--byline-author)) - ;; #'mastodon-tl--byline-author - ;; action-byline - (lambda (&rest _args) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) - .status_id - ;; base toot - (when (member type-sym '(favourite reblog)) - status) - nil nil nil nil - nil group accounts))))) ;; insert status still needs our group data - -;; FIXME: REFACTOR with -tl--byline: +STATUS is the status's JSON. +ACCOUNTS is data of the accounts that have reacted to the notification." + (let ((folded nil)) + ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' + (let-alist group + ;; .sample_account_ids .status_id .notifications_count + ;; .most_recent_notifiation_id + (let* (;(type .type) + (type-sym (intern .type)) + (profile-note + (when (eq type-sym 'follow_request) + (let ((str (mastodon-tl--field 'note (car accounts)))) + (if mastodon-notifications--profile-note-in-foll-reqs-max-length + (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) + str)))) + ;; (follower (car .sample_account_ids)) + (follower-name (mastodon-tl--field 'username (car accounts))) + (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (filters (when filtered + (mastodon-tl--current-filters filtered)))) + (unless (and filtered (assoc "hide" filters)) + (if (member type-sym '(follow follow_request)) + ;; FIXME: handle follow requests, polls + (insert "TODO: follow-req\n") + (mastodon-notifications--insert-note + ;; toot + (if (member type-sym '(follow follow_request)) + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + ;; status + status + ;; (cons '(reblog (id . nil)) status) ;;note)) + ;; reblogs/faves use 'note' to process their own json not the + ;; toot's. this ensures following etc. work on such notifs + status) ;; FIXME: fix following on these notifs + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler status (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow_request) + (concat + (propertize + (format "You have a follow request from... %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + #'mastodon-tl--byline-author + ;; action-byline + (unless (member type-sym '(mention)) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + ;; action authors + (cond ((member type-sym '(mention)) + "") ;; mentions are normal statuses + ((member type-sym '(favourite reblog update)) + (mastodon-notifications--byline-accounts accounts status group)) + ((eq type-sym 'follow_request) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + .status_id + ;; base toot + (when (member type-sym '(favourite reblog)) + status) + folded group accounts))))))) ;; insert status still needs our group data + +;; FIXME: this is copied from `mastodon-tl--insert-status' +;; we could probably cull a lot of the code so its just for notifs +(defun mastodon-notifications--insert-note + (toot body author-byline action-byline action-authors + &optional id base-toot unfolded group accounts) + "Display the content and byline of timeline element TOOT. +BODY will form the section of the toot above the byline. +AUTHOR-BYLINE is an optional function for adding the author +portion of the byline that takes one variable. By default it is +`mastodon-tl--byline-author'. +ACTION-BYLINE is also an optional function for adding an action, +such as boosting favouriting and following to the byline. It also +takes a single function. By default it is +`mastodon-tl--byline-boosted'. +ID is that of the status if it is a notification, which is +attached as a `item-id' property if provided. If the +status is a favourite or boost notification, BASE-TOOT is the +JSON of the toot responded to. +UNFOLDED is a boolean meaning whether to unfold or fold item if foldable. +NO-BYLINE means just insert toot body, used for folding." + (let* ((type (alist-get 'type (or group toot))) + (toot-foldable + (and mastodon-tl--fold-toots-at-length + (length> body mastodon-tl--fold-toots-at-length)))) + (insert + (propertize ;; body + byline: + (concat + (concat action-authors + action-byline) + (propertize ;; body only: + body + 'toot-body t) ;; includes newlines etc. for folding + ;; byline: + "\n" + (mastodon-tl--byline toot author-byline nil nil + base-toot group)) + 'item-type 'toot + 'item-id (or id ; notification's own id + (alist-get 'id toot)) ; toot id + 'base-item-id (mastodon-tl--item-id + ;; if status is a notif, get id from base-toot + ;; (-tl--item-id toot) will not work here: + (or base-toot + toot)) ; else normal toot with reblog check + 'item-json toot + 'base-toot base-toot + 'cursor-face 'mastodon-cursor-highlight-face + 'toot-foldable toot-foldable + 'toot-folded (and toot-foldable (not unfolded)) + 'notification-type type + 'notification-group group + 'notification-accounts accounts) + "\n"))) + +;; FIXME: REFACTOR with -tl--byline?: ;; we provide account directly, rather than let-alisting toot ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. (defun mastodon-notifications--byline-accounts - (accounts toot group &optional avatar domain) - "Propertize author byline ACCOUNT for TOOT, the item responded to. + (accounts toot group &optional avatar compact) + "Propertize author byline ACCOUNTS for TOOT, the item responded to. With arg AVATAR, include the account's avatar image. When DOMAIN, force inclusion of user's domain in their handle." - (let ((others-count (- (alist-get 'notifications_count group) - (length accounts)))) + (let ((total (alist-get 'notifications_count group)) + (accts 2)) (concat (cl-loop for account in accounts + repeat accts concat (let-alist account (concat - ;; avatar insertion moved up to `mastodon-tl--byline' by default to - ;; be outside 'byline propt. + ;; avatar insertion moved up to `mastodon-tl--byline' by + ;; default to be outside 'byline propt. (when (and avatar ; used by `mastodon-profile--format-user' mastodon-tl--show-avatars mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering .avatar)) - ;; username: - (mastodon-tl--byline-username toot account) - ;; handle: - " (" (mastodon-tl--byline-handle toot nil account) ")" - (if (< 1 (length accounts)) "\n" "")))) - (if (< 0 others-count) - (format "and %s others" others-count))))) - -(defun mastodon-notifications--by-type (groups json) - "Filter NOTE for those listed in `mastodon-notifications--types-alist'. -Call its function in that list on NOTE." - (setq masto-grouped-notifs json) - (cl-loop - for g in groups - for start-pos = (point) - for accounts = (mastodon-notifications--group-accounts - (alist-get 'sample_account_ids g) - (alist-get 'accounts json)) - for status = (mastodon-notifications--alist-by-value - (alist-get 'status_id g) 'id - (alist-get 'statuses json)) - do (mastodon-notifications--format-note g status accounts) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point))))) + (let ((uname (mastodon-tl--byline-username toot account)) + (handle (concat + "(" + (mastodon-tl--byline-handle toot nil account) + ")"))) + (if compact + ;; FIXME: this doesn't work to make a link from a username: + (propertize handle 'display uname) + (concat uname handle))) + "\n"))) ;; FIXME: only if not last handle + (if (< accts total) + (let ((diff (- total accts))) + ;; FIXME: help echo all remaining accounts? + (format "\nand %s other%s" diff (if (= 1 diff) "" "s"))))))) + +(defun mastodon-notifications--render (json) + "Display grouped notifications in JSON." + ;; (setq masto-grouped-notifs json) + (let ((groups (alist-get 'notification_groups json))) + (cl-loop + for g in groups + for start-pos = (point) + for accounts = (mastodon-notifications--group-accounts + (alist-get 'sample_account_ids g) + (alist-get 'accounts json)) + for status = (mastodon-notifications--alist-by-value + (alist-get 'status_id g) 'id + (alist-get 'statuses json)) + do (mastodon-notifications--format-note g status accounts) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." (if (seq-empty-p json) (user-error "Looks like you have no (more) notifications for now") - (let ((groups (alist-get 'notification_groups json))) - ;; (mapc (lambda (x) - (mastodon-notifications--by-type groups json) - ;; grouped) - (goto-char (point-min))))) + (mastodon-notifications--render json) + (goto-char (point-min)))) (defun mastodon-notifications--get-mentions () "Display mention notifications in buffer." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3ebfa4e..efc16ac 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -598,11 +598,10 @@ Do so if type of status at poins is not follow_request/follow." (string= type "follow")) ; no counts for these (message "%s" echo))))) -;; FIXME: now that this can also be used for non byline rendering, let's remove -;; the toot arg, and deal with attachments higher up (on real author -;; byline only) -;; removing toot arg makes it easier to render notifs that have no status -;; (foll_reqs) +;; FIXME: now that this can also be used for non byline rendering, let's +;; remove the toot arg, and deal with attachments higher up (on real +;; author byline only) removing toot arg makes it easier to render notifs +;; that have no status (foll_reqs) (defun mastodon-tl--byline-username (toot &optional account) "Format a byline username from account in TOOT." (let-alist (or account (alist-get 'account toot)) @@ -634,12 +633,12 @@ DOMAIN is optionally added to the handle." (url-generic-parse-url .url))))) 'face 'mastodon-handle-face 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle + 'mastodon-tab-stop 'user-handle 'account account - 'shr-url .url - 'keymap mastodon-tl--link-keymap + 'shr-url .url + 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .acct) - 'help-echo (concat "Browse user profile of @" .acct)))) + 'help-echo (concat "Browse user profile of @" .acct)))) (defun mastodon-tl--byline-uname-+-handle (data &optional domain account) "" -- cgit v1.2.3 From 7800c16bf9cf28cc60fc8c8bd2dbe858fe6f290f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 12:57:28 +0200 Subject: notifs: action symbol for action byline str --- lisp/mastodon-notifications.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index aa38302..c969c8e 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -62,6 +62,7 @@ (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-media--get-avatar-rendering "mastodon-media") (autoload 'mastodon-tl--image-trans-check "mastodon-tl") +(autoload 'mastodon-tl--symbol "mastodon-tl") (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -123,7 +124,16 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat "\n " (propertize message 'face 'highlight) + (concat "\n " + (mastodon-tl--symbol + (cond ((string= message "Favourited") + 'favourite) + ((string= message "Boosted") + 'boost) + ((string= message "Edited") + 'edited))) + " " + (propertize message 'face 'highlight) " " (cdr (assoc message mastodon-notifications--response-alist)) "\n")) -- cgit v1.2.3 From f114f3c19066e5bd7211389e6730b23a17c35e09 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:39:30 +0200 Subject: notifs: fix foll_reqs --- lisp/mastodon-notifications.el | 154 ++++++++++++++++++++++------------------- lisp/mastodon-tl.el | 19 ++--- 2 files changed, 92 insertions(+), 81 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c969c8e..599b4aa 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -232,77 +232,80 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (let-alist group ;; .sample_account_ids .status_id .notifications_count ;; .most_recent_notifiation_id - (let* (;(type .type) - (type-sym (intern .type)) + (let* ((type-sym (intern .type)) (profile-note - (when (eq type-sym 'follow_request) + (when (member type-sym '(follow follow_request)) (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) - ;; (follower (car .sample_account_ids)) - (follower-name (mastodon-tl--field 'username (car accounts))) - (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (follower (when (member type-sym + '(reblog favourite follow follow_request)) + (car accounts))) + (follower-name (mastodon-tl--field 'username follower)) + (filtered (mastodon-tl--field 'filtered status)) (filters (when filtered (mastodon-tl--current-filters filtered)))) (unless (and filtered (assoc "hide" filters)) - (if (member type-sym '(follow follow_request)) - ;; FIXME: handle follow requests, polls - (insert "TODO: follow-req\n") - (mastodon-notifications--insert-note - ;; toot - (if (member type-sym '(follow follow_request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; status - status - ;; (cons '(reblog (id . nil)) status) ;;note)) - ;; reblogs/faves use 'note' to process their own json not the - ;; toot's. this ensures following etc. work on such notifs - status) ;; FIXME: fix following on these notifs - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler status (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - #'mastodon-tl--byline-author - ;; action-byline - (unless (member type-sym '(mention)) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) - ;; action authors - (cond ((member type-sym '(mention)) - "") ;; mentions are normal statuses - ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts accounts status group)) + (mastodon-notifications--insert-note + ;; toot + ;; FIXME: fix following on grouped notifs + ;; FIXME: block boost/fave on boost/fave notifs? + (if (member type-sym + ;; reblogs/faves use 'note' to process their own + ;; json not the toot's. this ensures following etc. + ;; work on such notifs + '(reblog favourite follow follow_request)) + ;; FIXME: breaks item stats! + follower + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + ;; (cons '(reblog (id . nil)) status) ;;note)) + status) + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler status (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) ((eq type-sym 'follow_request) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) - .status_id - ;; base toot - (when (member type-sym '(favourite reblog)) - status) - folded group accounts))))))) ;; insert status still needs our group data + (concat + (propertize + (format "You have a follow request from... %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + #'mastodon-tl--byline-author + ;; action-byline + (unless (member type-sym '(follow follow_request mention)) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + ;; action authors + (cond + ((member type-sym '(follow_request mention)) + "") ;; mentions are normal statuses + ((member type-sym '(favourite reblog update)) + (mastodon-notifications--byline-accounts accounts status group)) + ((eq type-sym 'follow_request) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + .status_id + ;; base toot + (when (member type-sym '(favourite reblog)) + status) + folded group accounts)))))) ;; FIXME: this is copied from `mastodon-tl--insert-status' ;; we could probably cull a lot of the code so its just for notifs @@ -314,16 +317,19 @@ BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author portion of the byline that takes one variable. By default it is `mastodon-tl--byline-author'. -ACTION-BYLINE is also an optional function for adding an action, -such as boosting favouriting and following to the byline. It also -takes a single function. By default it is -`mastodon-tl--byline-boosted'. +ACTION-BYLINE is a string, obtained by calling +`mastodon-notifications--byline-concat'. +ACTION-AUTHORS is a string of those who have responded to the +current item, obtained by calling +`mastodon-notifications--byline-accounts' ID is that of the status if it is a notification, which is attached as a `item-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. -UNFOLDED is a boolean meaning whether to unfold or fold item if foldable. -NO-BYLINE means just insert toot body, used for folding." +UNFOLDED is a boolean meaning whether to unfold or fold item if +foldable. +GROUP is the notification group data. +ACCOUNTS is the notification accounts data." (let* ((type (alist-get 'type (or group toot))) (toot-foldable (and mastodon-tl--fold-toots-at-length @@ -339,7 +345,9 @@ NO-BYLINE means just insert toot body, used for folding." ;; byline: "\n" (mastodon-tl--byline toot author-byline nil nil - base-toot group)) + base-toot group + (if (member type '("follow" "follow_request")) + toot))) ;; account data! 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -365,8 +373,10 @@ NO-BYLINE means just insert toot body, used for folding." (defun mastodon-notifications--byline-accounts (accounts toot group &optional avatar compact) "Propertize author byline ACCOUNTS for TOOT, the item responded to. -With arg AVATAR, include the account's avatar image. -When DOMAIN, force inclusion of user's domain in their handle." +GROUP is the group notification data. +When AVATAR, include the account's avatar image. +When DOMAIN, force inclusion of user's domain in their handle. +When COMPACT, just display username, not also handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat @@ -385,7 +395,7 @@ When DOMAIN, force inclusion of user's domain in their handle." (mastodon-media--get-avatar-rendering .avatar)) (let ((uname (mastodon-tl--byline-username toot account)) (handle (concat - "(" + " (" (mastodon-tl--byline-handle toot nil account) ")"))) (if compact diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index efc16ac..f6460e1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -645,7 +645,7 @@ DOMAIN is optionally added to the handle." (concat (mastodon-tl--byline-username data account) " (" (mastodon-tl--byline-handle data domain account) ")")) -(defun mastodon-tl--byline-author (toot &optional avatar domain base) +(defun mastodon-tl--byline-author (toot &optional avatar domain base account) "Propertize author of TOOT. If TOOT contains a reblog, return author of reblogged item. With arg AVATAR, include the account's avatar image. @@ -666,8 +666,8 @@ If BASE is nil, we are a boosted byline, so show less info." (alist-get 'avatar (alist-get 'account data)))) (if (not base) - (mastodon-tl--byline-handle data domain) - (mastodon-tl--byline-uname-+-handle data domain))))) + (mastodon-tl--byline-handle data domain account) + (mastodon-tl--byline-uname-+-handle data domain account))))) (defun mastodon-tl--format-byline-help-echo (toot) "Format a help-echo for byline of TOOT. @@ -760,7 +760,7 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (image-transforms-p))) (defun mastodon-tl--byline (toot author-byline &optional detailed-p - domain base-toot group) + domain base-toot group account) "Generate byline for TOOT. AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. @@ -789,7 +789,8 @@ BASE-TOOT is JSON for the base toot, if any." (type (alist-get 'type toot)) (base-toot-maybe (or base-toot ;; show edits for notifs (mastodon-tl--toot-or-base toot))) ;; for boosts - (account (alist-get 'account base-toot-maybe)) + (account (or account + (alist-get 'account base-toot-maybe))) (avatar-url (alist-get 'avatar account)) (edited-time (alist-get 'edited_at base-toot-maybe)) (edited-parsed (when edited-time (date-to-time edited-time)))) @@ -828,7 +829,7 @@ BASE-TOOT is JSON for the base toot, if any." (propertize (concat " " (mastodon-tl--symbol 'private)) 'help-echo visibility))) ;; (base) author byline: - (funcall author-byline toot nil domain :base) + (funcall author-byline toot nil domain :base account) " " ;; timestamp: (let ((ts (format-time-string @@ -852,10 +853,10 @@ BASE-TOOT is JSON for the base toot, if any." 'face 'mastodon-display-name-face 'follow-link t 'mouse-face 'highlight - 'mastodon-tab-stop 'shr-url - 'shr-url app-url + 'mastodon-tab-stop 'shr-url + 'shr-url app-url 'help-echo app-url - 'keymap mastodon-tl--shr-map-replacement))))) + 'keymap mastodon-tl--shr-map-replacement))))) ;; edited: (when edited-time (concat -- cgit v1.2.3 From d573d80f023813ce4c429dc73da6714b0a29af8c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:53:06 +0200 Subject: notifs: string-trim action authors --- lisp/mastodon-notifications.el | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 599b4aa..fc82edd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -380,29 +380,30 @@ When COMPACT, just display username, not also handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat - (cl-loop - for account in accounts - repeat accts - concat - (let-alist account - (concat - ;; avatar insertion moved up to `mastodon-tl--byline' by - ;; default to be outside 'byline propt. - (when (and avatar ; used by `mastodon-profile--format-user' - mastodon-tl--show-avatars - mastodon-tl--display-media-p - (mastodon-tl--image-trans-check)) - (mastodon-media--get-avatar-rendering .avatar)) - (let ((uname (mastodon-tl--byline-username toot account)) - (handle (concat - " (" - (mastodon-tl--byline-handle toot nil account) - ")"))) - (if compact - ;; FIXME: this doesn't work to make a link from a username: - (propertize handle 'display uname) - (concat uname handle))) - "\n"))) ;; FIXME: only if not last handle + (string-trim ;; remove trailing newline + (cl-loop + for account in accounts + repeat accts + concat + (let-alist account + (concat + ;; avatar insertion moved up to `mastodon-tl--byline' by + ;; default to be outside 'byline propt. + (when (and avatar ; used by `mastodon-profile--format-user' + mastodon-tl--show-avatars + mastodon-tl--display-media-p + (mastodon-tl--image-trans-check)) + (mastodon-media--get-avatar-rendering .avatar)) + (let ((uname (mastodon-tl--byline-username toot account)) + (handle (concat + " (" + (mastodon-tl--byline-handle toot nil account) + ")"))) + (if compact + ;; FIXME: this doesn't work to make a link from a username: + (propertize handle 'display uname) + (concat uname handle))) + "\n")))) (if (< accts total) (let ((diff (- total accts))) ;; FIXME: help echo all remaining accounts? -- cgit v1.2.3 From f53d252a27fc451bd41c8fb6fe2049695b9bedc0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:53:26 +0200 Subject: notifs: revert add fave/boost to foll_req condition --- lisp/mastodon-notifications.el | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index fc82edd..bbc77a8 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -240,7 +240,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) (follower (when (member type-sym - '(reblog favourite follow follow_request)) + '(follow follow_request)) (car accounts))) (follower-name (mastodon-tl--field 'username follower)) (filtered (mastodon-tl--field 'filtered status)) @@ -249,18 +249,14 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (unless (and filtered (assoc "hide" filters)) (mastodon-notifications--insert-note ;; toot - ;; FIXME: fix following on grouped notifs + ;; FIXME: fix following etc. on action authors ;; FIXME: block boost/fave on boost/fave notifs? (if (member type-sym ;; reblogs/faves use 'note' to process their own ;; json not the toot's. this ensures following etc. ;; work on such notifs - '(reblog favourite follow follow_request)) - ;; FIXME: breaks item stats! + '(follow follow_request)) follower - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; (cons '(reblog (id . nil)) status) ;;note)) status) ;; body (let ((body (if-let ((match (assoc "warn" filters))) -- cgit v1.2.3 From 934024173c05678610ac26ba86730e93f9475ea7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:58:49 +0200 Subject: notifs: byline funcall dostrings --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f6460e1..6c90b58 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -766,7 +766,7 @@ AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. ACTION-BYLINE is a function for adding an action, such as boosting, favouriting and following to the byline. It also takes a single function. -By default it is `mastodon-tl--byline-boosted'. +By default it is `mastodon-tl--byline-author' DETAILED-P means display more detailed info. For now this just means displaying toot client. When DOMAIN, force inclusion of user's domain in their handle. @@ -1625,7 +1625,7 @@ portion of the byline that takes one variable. By default it is ACTION-BYLINE is also an optional function for adding an action, such as boosting favouriting and following to the byline. It also takes a single function. By default it is -`mastodon-tl--byline-boosted'. +`mastodon-tl--byline-boost'. ID is that of the status if it is a notification, which is attached as a `item-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the -- cgit v1.2.3 From 4b58d618e7f21a4e716f4f491f0bb6348a129a61 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 14:03:11 +0200 Subject: bylines: move attachments from byline author to --byline --- lisp/mastodon-tl.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6c90b58..3dd4736 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -610,7 +610,7 @@ Do so if type of status at poins is not follow_request/follow." .username) 'face 'mastodon-display-name-face ;; enable playing of videos when point is on byline: - 'attachments (mastodon-tl--get-attachments-for-byline toot) + ;; 'attachments (mastodon-tl--get-attachments-for-byline toot) 'keymap mastodon-tl--byline-link-keymap ;; echo faves count when point on post author name: ;; which is where --goto-next-toot puts point. @@ -633,12 +633,12 @@ DOMAIN is optionally added to the handle." (url-generic-parse-url .url))))) 'face 'mastodon-handle-face 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle + 'mastodon-tab-stop 'user-handle 'account account - 'shr-url .url - 'keymap mastodon-tl--link-keymap + 'shr-url .url + 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .acct) - 'help-echo (concat "Browse user profile of @" .acct)))) + 'help-echo (concat "Browse user profile of @" .acct)))) (defun mastodon-tl--byline-uname-+-handle (data &optional domain account) "" @@ -853,10 +853,10 @@ BASE-TOOT is JSON for the base toot, if any." 'face 'mastodon-display-name-face 'follow-link t 'mouse-face 'highlight - 'mastodon-tab-stop 'shr-url - 'shr-url app-url + 'mastodon-tab-stop 'shr-url + 'shr-url app-url 'help-echo app-url - 'keymap mastodon-tl--shr-map-replacement))))) + 'keymap mastodon-tl--shr-map-replacement))))) ;; edited: (when edited-time (concat @@ -881,6 +881,8 @@ BASE-TOOT is JSON for the base toot, if any." 'favourited-p faved 'boosted-p boosted 'bookmarked-p bookmarked + ;; enable playing of videos when point is on byline: + 'attachments (mastodon-tl--get-attachments-for-byline toot) 'edited edited-time 'edit-history (when edited-time (mastodon-toot--get-toot-edits -- cgit v1.2.3 From 5a0ab77d0faad9a32361907c2b610d458844ffad Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 18:26:21 +0200 Subject: bylines: format boost authors as clickable handles but display uname --- lisp/mastodon-tl.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3dd4736..fa48414 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -626,12 +626,13 @@ Do so if type of status at poins is not follow_request/follow." "Format a byline handle from account in TOOT. DOMAIN is optionally added to the handle." (let-alist (or account (alist-get 'account toot)) - (propertize (concat "@" .acct - (when domain - (concat "@" - (url-host - (url-generic-parse-url .url))))) - 'face 'mastodon-handle-face + (propertize (or string + (concat "@" .acct + (when domain + (concat "@" + (url-host + (url-generic-parse-url .url)))))) + 'face (or face 'mastodon-handle-face) 'mouse-face 'highlight 'mastodon-tab-stop 'user-handle 'account account @@ -654,7 +655,11 @@ BASE means to use data from the base item (reblog slot) if possible. If BASE is nil, we are a boosted byline, so show less info." (let* ((data (if base (mastodon-tl--toot-or-base toot) - toot))) + toot)) + (account (or account (alist-get 'account data))) + (uname (if (not (string-empty-p (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account)))) (concat ;; avatar insertion moved up to `mastodon-tl--byline' by default to ;; be outside 'byline propt. @@ -666,7 +671,10 @@ If BASE is nil, we are a boosted byline, so show less info." (alist-get 'avatar (alist-get 'account data)))) (if (not base) - (mastodon-tl--byline-handle data domain account) + (mastodon-tl--byline-handle + data domain account + ;; display uname not handle (for boosts): + uname 'mastodon-display-name-face) (mastodon-tl--byline-uname-+-handle data domain account))))) (defun mastodon-tl--format-byline-help-echo (toot) -- cgit v1.2.3 From bf01cb7caae67dae36382e0489bc53d56c2172d7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 18:27:12 +0200 Subject: bylines: fix visibility icon position --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fa48414..42ed5c5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -829,6 +829,8 @@ BASE-TOOT is JSON for the base toot, if any." (concat ;; NB: action-byline (boost) is now added in insert-status, so no ;; longer part of the byline. + ;; (base) author byline: + (funcall author-byline toot nil domain :base account) ;; visibility: (cond ((string= visibility "direct") (propertize (concat " " (mastodon-tl--symbol 'direct)) @@ -836,8 +838,6 @@ BASE-TOOT is JSON for the base toot, if any." ((string= visibility "private") (propertize (concat " " (mastodon-tl--symbol 'private)) 'help-echo visibility))) - ;; (base) author byline: - (funcall author-byline toot nil domain :base account) " " ;; timestamp: (let ((ts (format-time-string -- cgit v1.2.3 From d74004b02d412bd3fff6ec37393c4e21873296a7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 18:27:43 +0200 Subject: flycheck -tl.el --- lisp/mastodon-tl.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 42ed5c5..74c79c3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -92,6 +92,7 @@ (autoload 'mastodon-toot--with-toot-item "mastodon-toot") (autoload 'mastodon-media--image-or-cached "mastodon-media") (autoload 'mastodon-toot--base-toot-or-item-json "mastodon-toot") +(autoload 'mastodon-search--load-link-posts "mastodon-search") (defvar mastodon-toot--visibility) (defvar mastodon-toot-mode) @@ -578,8 +579,7 @@ With a double PREFIX arg, limit results to your own instance." (defun mastodon-tl--link-timeline (url) "Load a link timeline, displaying posts containing URL." - (let ((endpoint (mastodon-http--api "timelines/link")) - (params `(("url" . ,url)))) + (let ((params `(("url" . ,url)))) (mastodon-tl--init "links" "timelines/link" 'mastodon-tl--timeline nil params))) @@ -603,7 +603,8 @@ Do so if type of status at poins is not follow_request/follow." ;; author byline only) removing toot arg makes it easier to render notifs ;; that have no status (foll_reqs) (defun mastodon-tl--byline-username (toot &optional account) - "Format a byline username from account in TOOT." + "Format a byline username from account in TOOT. +ACCOUNT is optionally acccount data to use." (let-alist (or account (alist-get 'account toot)) (propertize (if (not (string-empty-p .display_name)) .display_name @@ -622,9 +623,14 @@ Do so if type of status at poins is not follow_request/follow." (string-suffix-p "-following*" (buffer-name))) (mastodon-tl--format-byline-help-echo toot))))) -(defun mastodon-tl--byline-handle (toot &optional domain account) +(defun mastodon-tl--byline-handle (toot &optional domain account string face) "Format a byline handle from account in TOOT. -DOMAIN is optionally added to the handle." +DOMAIN is optionally added to the handle. +ACCOUNT is optionally acccount data to use. +STRING is optionally the string to propertize. +FACE is optionally the face to use. +The last two args allow for display a username as a clickable +handle." (let-alist (or account (alist-get 'account toot)) (propertize (or string (concat "@" .acct @@ -642,7 +648,10 @@ DOMAIN is optionally added to the handle." 'help-echo (concat "Browse user profile of @" .acct)))) (defun mastodon-tl--byline-uname-+-handle (data &optional domain account) - "" + "Concatenate a byline username and handle. +DATA is the (toot) data to use. +DOMAIN is optionally a domain for the handle. +ACCOUNT is optionally acccount data to use." (concat (mastodon-tl--byline-username data account) " (" (mastodon-tl--byline-handle data domain account) ")")) @@ -652,7 +661,8 @@ If TOOT contains a reblog, return author of reblogged item. With arg AVATAR, include the account's avatar image. When DOMAIN, force inclusion of user's domain in their handle. BASE means to use data from the base item (reblog slot) if possible. -If BASE is nil, we are a boosted byline, so show less info." +If BASE is nil, we are a boosted byline, so show less info. +ACCOUNT is optionally acccount data to use." (let* ((data (if base (mastodon-tl--toot-or-base toot) toot)) -- cgit v1.2.3 From 0ed127907f34dd8dbc1aad9d131e0fda1ce4d35d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 18:33:59 +0200 Subject: bylines/notifs: use new uname/handle combo in reaction notifs --- lisp/mastodon-notifications.el | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bbc77a8..8517a84 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -390,15 +390,12 @@ When COMPACT, just display username, not also handle." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering .avatar)) - (let ((uname (mastodon-tl--byline-username toot account)) - (handle (concat - " (" - (mastodon-tl--byline-handle toot nil account) - ")"))) - (if compact - ;; FIXME: this doesn't work to make a link from a username: - (propertize handle 'display uname) - (concat uname handle))) + (let ((uname + (if (not (string-empty-p (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account)))) + (mastodon-tl--byline-handle toot nil account + uname 'mastodon-display-name-face)) "\n")))) (if (< accts total) (let ((diff (- total accts))) -- cgit v1.2.3 From 3e7f1eccd386c3c041a482b9250ed0ef5f768354 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 13:09:19 +0200 Subject: notifs: top byline: action symbol, action author, action str --- lisp/mastodon-notifications.el | 48 +++++++++++++++++++++++------------------- lisp/mastodon-tl.el | 2 ++ 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 8517a84..eef68a2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -124,16 +124,8 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat "\n " - (mastodon-tl--symbol - (cond ((string= message "Favourited") - 'favourite) - ((string= message "Boosted") - 'boost) - ((string= message "Edited") - 'edited))) - " " - (propertize message 'face 'highlight) + (concat " " + (propertize message 'face 'mastodon-boosted-face) " " (cdr (assoc message mastodon-notifications--response-alist)) "\n")) @@ -281,22 +273,31 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ":\n" (mastodon-notifications--comment-note-text body))))) ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) + (propertize + (mastodon-notifications--comment-note-text body) + ;; indent faves/boosts (maybe remove): + 'line-prefix " " + 'wrap-prefix " ")) (t body))) ;; author-byline #'mastodon-tl--byline-author ;; action-byline (unless (member type-sym '(follow follow_request mention)) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) + (downcase + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors (cond ((member type-sym '(follow_request mention)) "") ;; mentions are normal statuses ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts accounts status group)) + (mastodon-notifications--byline-accounts + accounts status group)) ((eq type-sym 'follow_request) (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + ;; action symbol: + (when (member type-sym '(favourite reblog update)) + (mastodon-tl--symbol type-sym)) .status_id ;; base toot (when (member type-sym '(favourite reblog)) @@ -306,7 +307,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; FIXME: this is copied from `mastodon-tl--insert-status' ;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note - (toot body author-byline action-byline action-authors + (toot body author-byline action-byline action-authors action-symbol &optional id base-toot unfolded group accounts) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -331,15 +332,17 @@ ACCOUNTS is the notification accounts data." (and mastodon-tl--fold-toots-at-length (length> body mastodon-tl--fold-toots-at-length)))) (insert - (propertize ;; body + byline: + (propertize ;; top byline, body + byline: (concat - (concat action-authors - action-byline) - (propertize ;; body only: + (propertize ;; top byline + (concat action-symbol " " action-authors + action-byline) + 'byline-top t) + (propertize ;; body only body 'toot-body t) ;; includes newlines etc. for folding - ;; byline: "\n" + ;; actual byline: (mastodon-tl--byline toot author-byline nil nil base-toot group (if (member type '("follow" "follow_request")) @@ -396,11 +399,12 @@ When COMPACT, just display username, not also handle." (alist-get 'username account)))) (mastodon-tl--byline-handle toot nil account uname 'mastodon-display-name-face)) - "\n")))) + ", "))) + nil ", ") (if (< accts total) (let ((diff (- total accts))) ;; FIXME: help echo all remaining accounts? - (format "\nand %s other%s" diff (if (= 1 diff) "" "s"))))))) + (format " and %s other%s" diff (if (= 1 diff) "" "s"))))))) (defun mastodon-notifications--render (json) "Display grouped notifications in JSON." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 74c79c3..c5ada75 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -155,6 +155,7 @@ nil." (defcustom mastodon-tl--symbols '((reply . ("💬" . "R")) (boost . ("🔁" . "B")) + (reblog . ("🔁" . "B")) ;; server compat (favourite . ("⭐" . "F")) (bookmark . ("🔖" . "K")) (media . ("📹" . "[media]")) @@ -163,6 +164,7 @@ nil." (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) (edited . ("✍" . "[edited]")) + (update . ("✍" . "[edited]")) ;; server compat (replied . ("⬇" . "↓")) (reply-bar . ("┃" . "|"))) "A set of symbols (and fallback strings) to be used in timeline. -- cgit v1.2.3 From 8eab2d38ebcde6946b16aeba7c6c0c480141ecdf Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 13:17:25 +0200 Subject: notifs: comment faved/boosted toot body line-prefix (breaks cursor highlight) --- lisp/mastodon-notifications.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index eef68a2..a61492a 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -275,9 +275,13 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ((member type-sym '(favourite reblog)) (propertize (mastodon-notifications--comment-note-text body) - ;; indent faves/boosts (maybe remove): - 'line-prefix " " - 'wrap-prefix " ")) + ;; indent faves/boosts (maybe remove, as it makes + ;; cursor highlight ugly) + ;; but it's nice to be able to differentiate top + ;; byline a little from body of item acted on + ;; 'line-prefix "" + ;; 'wrap-prefix "" + )) (t body))) ;; author-byline #'mastodon-tl--byline-author -- cgit v1.2.3 From 5c1a8d5a3b0a6a772f712e6ad21f0889a4081325 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:09:04 +0200 Subject: grouped notifs: fix foll req process: use notif-type prop not item-json --- lisp/mastodon-notifications.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a61492a..262ed57 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -139,7 +139,9 @@ follow-requests view." (let* ((item-json (mastodon-tl--property 'item-json)) (f-reqs-view-p (string= "follow_requests" (plist-get mastodon-tl--buffer-spec 'endpoint))) - (f-req-p (or (string= "follow_request" (alist-get 'type item-json)) ;notifs + (f-req-p (or (string= "follow_request" + (mastodon-tl--property 'notification-type + :no-move)) f-reqs-view-p))) (if (not f-req-p) (user-error "No follow request at point?") -- cgit v1.2.3 From 95875366372b6acf571254cc70f58caa80dda19b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:12:01 +0200 Subject: notifs: no stats for foll-reqs / tl--byline: get type from group --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c5ada75..7d41971 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -806,7 +806,9 @@ BASE-TOOT is JSON for the base toot, if any." (boosted (eq t (mastodon-tl--field 'reblogged toot))) (bookmarked (eq t (mastodon-tl--field 'bookmarked toot))) (visibility (mastodon-tl--field 'visibility toot)) - (type (alist-get 'type toot)) + (type (if group + (alist-get 'type group) + (alist-get 'type toot))) (base-toot-maybe (or base-toot ;; show edits for notifs (mastodon-tl--toot-or-base toot))) ;; for boosts (account (or account -- cgit v1.2.3 From 94a7083c282b0d65984ef6dffa891e3ea397386e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:17:28 +0200 Subject: flycheck --- lisp/mastodon-notifications.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 262ed57..f8f093b 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -324,7 +324,8 @@ ACTION-BYLINE is a string, obtained by calling `mastodon-notifications--byline-concat'. ACTION-AUTHORS is a string of those who have responded to the current item, obtained by calling -`mastodon-notifications--byline-accounts' +`mastodon-notifications--byline-accounts'. +ACTION-SYMBOL is a symbol indicating a favourite, boost, or edit. ID is that of the status if it is a notification, which is attached as a `item-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the @@ -376,12 +377,11 @@ ACCOUNTS is the notification accounts data." ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. (defun mastodon-notifications--byline-accounts - (accounts toot group &optional avatar compact) + (accounts toot group &optional avatar) "Propertize author byline ACCOUNTS for TOOT, the item responded to. GROUP is the group notification data. When AVATAR, include the account's avatar image. -When DOMAIN, force inclusion of user's domain in their handle. -When COMPACT, just display username, not also handle." +When DOMAIN, force inclusion of user's domain in their handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat -- cgit v1.2.3 From 3338be8e330c9e904c3bd6d1e603506346a88557 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:30:19 +0200 Subject: notifs: tl--more-json-async: v2 api for notifs --- lisp/mastodon-tl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7d41971..6005a54 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2824,7 +2824,8 @@ the current view." (args (append args params)) (url (mastodon-http--api endpoint - (when (string-suffix-p "search" endpoint) + (when (or (string= endpoint "notifications") + (string-suffix-p "search" endpoint)) "v2")))) (apply #'mastodon-http--get-json-async url args callback cbargs))) -- cgit v1.2.3 From 3c3ef2e98ff81e94446c6e749759f0422f2aa140 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 15:06:13 +0200 Subject: notifs: improve insert-note text props. fixes pagination (hack) --- lisp/mastodon-notifications.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index f8f093b..14f2be5 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -354,19 +354,23 @@ ACCOUNTS is the notification accounts data." base-toot group (if (member type '("follow" "follow_request")) toot))) ;; account data! - 'item-type 'toot - 'item-id (or id ; notification's own id - (alist-get 'id toot)) ; toot id - 'base-item-id (mastodon-tl--item-id - ;; if status is a notif, get id from base-toot - ;; (-tl--item-id toot) will not work here: - (or base-toot - toot)) ; else normal toot with reblog check - 'item-json toot - 'base-toot base-toot - 'cursor-face 'mastodon-cursor-highlight-face + 'item-type 'notification + 'item-id (or + ;; grouped notifications pagination max_id: + ;; NB: their min id used for our max id param + (alist-get 'page_min_id group) + (alist-get 'id toot)) ; toot id + 'base-item-id (mastodon-tl--item-id + ;; if status is a notif, get id from base-toot + ;; (-tl--item-id toot) will not work here: + (or base-toot + toot)) ; else normal toot with reblog check + 'item-json toot + 'base-toot base-toot + 'cursor-face 'mastodon-cursor-highlight-face 'toot-foldable toot-foldable - 'toot-folded (and toot-foldable (not unfolded)) + 'toot-folded (and toot-foldable (not unfolded)) + ;; grouped notifs data: 'notification-type type 'notification-group group 'notification-accounts accounts) -- cgit v1.2.3 From 532f608fe52f1dd326df4995dcef69fb5c431c1e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 15:15:02 +0200 Subject: notifs: item-type = toot (for nav, item actions) --- lisp/mastodon-notifications.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 14f2be5..c2d1962 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -354,7 +354,7 @@ ACCOUNTS is the notification accounts data." base-toot group (if (member type '("follow" "follow_request")) toot))) ;; account data! - 'item-type 'notification + 'item-type 'toot ;; for nav, actions, etc. 'item-id (or ;; grouped notifications pagination max_id: ;; NB: their min id used for our max id param -- cgit v1.2.3 From c784cb81ab693d0979425b1cd223df106f9802fc Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 19:28:08 +0200 Subject: notifs: fix pagination using grouped min/max ids --- lisp/mastodon-notifications.el | 12 ++++++------ lisp/mastodon-tl.el | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c2d1962..debc760 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -355,11 +355,8 @@ ACCOUNTS is the notification accounts data." (if (member type '("follow" "follow_request")) toot))) ;; account data! 'item-type 'toot ;; for nav, actions, etc. - 'item-id (or - ;; grouped notifications pagination max_id: - ;; NB: their min id used for our max id param - (alist-get 'page_min_id group) - (alist-get 'id toot)) ; toot id + 'item-id (or (alist-get 'page_max_id group) ;; newest notif + (alist-get 'id toot)) ; toot id 'base-item-id (mastodon-tl--item-id ;; if status is a notif, get id from base-toot ;; (-tl--item-id toot) will not work here: @@ -373,7 +370,10 @@ ACCOUNTS is the notification accounts data." ;; grouped notifs data: 'notification-type type 'notification-group group - 'notification-accounts accounts) + 'notification-accounts accounts + ;; for pagination: + 'notifications-min-id (alist-get 'page_min_id group) + 'notifications-max-id (alist-get 'page_max_id group)) "\n"))) ;; FIXME: REFACTOR with -tl--byline?: diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6005a54..99663ac 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2216,16 +2216,28 @@ BACKWARD means move backward (up) the timeline." (get-text-property (point) prop))))) (defun mastodon-tl--newest-id () - "Return item-id from the top of the buffer." + "Return item-id from the top of the buffer. +If we are in a notifications view, return `notifications-max-id'." (save-excursion (goto-char (point-min)) - (mastodon-tl--property 'item-id))) + (mastodon-tl--property + (if (eq (mastodon-tl--get-buffer-type) + (member (mastodon-tl--get-buffer-type) + '(mentions notifications))) + 'notifications-max-id + 'item-id)))) (defun mastodon-tl--oldest-id () - "Return item-id from the bottom of the buffer." + "Return item-id from the bottom of the buffer. +If we are in a notifications view, return `notifications-min-id'." (save-excursion (goto-char (point-max)) - (mastodon-tl--property 'item-id nil :backward))) + (mastodon-tl--property + (if (member (mastodon-tl--get-buffer-type) + '(mentions notifications)) + 'notifications-min-id + 'item-id) + nil :backward))) (defun mastodon-tl--as-string (numeric) "Convert NUMERIC to string." -- cgit v1.2.3 From 22b81fabbe7272163d88b5234e948c76963f4de3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 19:28:31 +0200 Subject: tiny clean up of tl--update --- lisp/mastodon-tl.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 99663ac..28fbb64 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3184,12 +3184,13 @@ This location is defined by a non-nil value of (interactive) ;; FIXME: actually these buffers should just reload by calling their own ;; load function (actually g is mostly mapped as such): - (if (or (mastodon-tl--buffer-type-eq 'trending-statuses) - (mastodon-tl--buffer-type-eq 'trending-tags) - (mastodon-tl--buffer-type-eq 'follow-suggestions) - (mastodon-tl--buffer-type-eq 'lists) - (mastodon-tl--buffer-type-eq 'filters) - (mastodon-tl--buffer-type-eq 'scheduled-statuses) + (if (or (member (mastodon-tl--get-buffer-type) + '(trending-statuses + trending-tags + follow-suggestions + lists + filters + scheduled-statuses)) (mastodon-tl--search-buffer-p)) (user-error "Update not available in this view") ;; FIXME: handle update for search and trending buffers @@ -3197,7 +3198,7 @@ This location is defined by a non-nil value of (update-function (mastodon-tl--update-function))) ;; update a thread, without calling `mastodon-tl--updated-json': (if (mastodon-tl--buffer-type-eq 'thread) - ;; load whole thread whole thread + ;; load whole thread: (let ((thread-id (mastodon-tl--thread-parent-id))) (funcall update-function thread-id) (message "Loaded full thread.")) @@ -3211,8 +3212,9 @@ This location is defined by a non-nil value of (mastodon-tl--set-after-update-marker) (goto-char (or mastodon-tl--update-point (point-min))) (funcall update-function json) - (when mastodon-tl--after-update-marker - (goto-char mastodon-tl--after-update-marker))))))))) + (if mastodon-tl--after-update-marker + (goto-char mastodon-tl--after-update-marker) + (mastodon-tl--goto-next-item))))))))) ;;; LOADING TIMELINES -- cgit v1.2.3 From 34979a5e64c8d07d028e7a8a59d4f3f156fb869c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:09:52 +0200 Subject: notifs: make action authors work for all notif types --- lisp/mastodon-notifications.el | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index debc760..59b90fd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -293,19 +293,15 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors - (cond - ((member type-sym '(follow_request mention)) - "") ;; mentions are normal statuses - ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts - accounts status group)) - ((eq type-sym 'follow_request) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + (cond ((member type-sym '(follow_request mention)) + "") ;; mentions are normal statuses + (t (mastodon-notifications--byline-accounts + accounts status group))) ;; action symbol: (when (member type-sym '(favourite reblog update)) (mastodon-tl--symbol type-sym)) .status_id - ;; base toot + ;; base toot (no need for update/poll/?) (when (member type-sym '(favourite reblog)) status) folded group accounts)))))) -- cgit v1.2.3 From 4653bdadfcd9a5487e8d1b01c8186a0458578f9f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:11:16 +0200 Subject: notifs: mastodon-notifications--types --- lisp/mastodon-notifications.el | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 59b90fd..9ec3252 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -91,16 +91,10 @@ make them unweildy." (defvar mastodon-tl--fold-toots-at-length) (defvar mastodon-tl--show-avatars) -(defvar mastodon-notifications--types-alist - '(("follow" . mastodon-notifications--follow) - ("favourite" . mastodon-notifications--favourite) - ("reblog" . mastodon-notifications--reblog) - ("mention" . mastodon-notifications--mention) - ("poll" . mastodon-notifications--poll) - ("follow_request" . mastodon-notifications--follow-request) - ("status" . mastodon-notifications--status) - ("update" . mastodon-notifications--edit)) - "Alist of notification types and their corresponding function.") +(defvar mastodon-notifications--types + '("favourite" "reblog" "mention" "poll" + "follow_request" "follow" "status" "update") + "A list of notification types according to their name on the server.") (defvar mastodon-notifications--response-alist '(("Followed" . "you") @@ -293,7 +287,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors - (cond ((member type-sym '(follow_request mention)) + (cond ((member type-sym '(follow follow_request mention)) "") ;; mentions are normal statuses (t (mastodon-notifications--byline-accounts accounts status group))) @@ -467,8 +461,7 @@ Status notifications are created when you call (defun mastodon-notifications--filter-types-list (type) "Return a list of notification types with TYPE removed." - (let ((types (mapcar #'car mastodon-notifications--types-alist))) - (remove type types))) + (remove type mastodon-notifications--types)) (defun mastodon-notifications--clear-all () "Clear all notifications." -- cgit v1.2.3 From 61e85a022c573193afa97d11798ed0553f2364d4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:45:06 +0200 Subject: add some more symbols, for notifs actions --- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-tl.el | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 9ec3252..339857c 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -292,7 +292,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (t (mastodon-notifications--byline-accounts accounts status group))) ;; action symbol: - (when (member type-sym '(favourite reblog update)) + (unless (eq type-sym 'mention) (mastodon-tl--symbol type-sym)) .status_id ;; base toot (no need for update/poll/?) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 28fbb64..f4051a3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -153,20 +153,24 @@ nil." :type 'boolean) (defcustom mastodon-tl--symbols - '((reply . ("💬" . "R")) - (boost . ("🔁" . "B")) - (reblog . ("🔁" . "B")) ;; server compat - (favourite . ("⭐" . "F")) - (bookmark . ("🔖" . "K")) - (media . ("📹" . "[media]")) - (verified . ("" . "V")) - (locked . ("🔒" . "[locked]")) - (private . ("🔒" . "[followers]")) - (direct . ("✉" . "[direct]")) - (edited . ("✍" . "[edited]")) - (update . ("✍" . "[edited]")) ;; server compat - (replied . ("⬇" . "↓")) - (reply-bar . ("┃" . "|"))) + '((reply . ("💬" . "R")) + (boost . ("🔁" . "B")) + (reblog . ("🔁" . "B")) ;; server compat + (favourite . ("⭐" . "F")) + (bookmark . ("🔖" . "K")) + (media . ("📹" . "[media]")) + (verified . ("" . "V")) + (locked . ("🔒" . "[locked]")) + (private . ("🔒" . "[followers]")) + (direct . ("✉" . "[direct]")) + (edited . ("✍" . "[edited]")) + (update . ("✍" . "[edited]")) ;; server compat + (status . ("✍" . "[posted]")) + (replied . ("⬇" . "↓")) + (reply-bar . ("┃" . "|")) + (poll . ("📊" . "")) + (follow . ("👤" . "+")) + (follow_request . ("👤" . "+"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." -- cgit v1.2.3 From e8787743b5ba661927b00bef37fe4cdf08429a97 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:47:24 +0200 Subject: notifs: clean up format-note. adjust some notif type conditionals --- lisp/mastodon-notifications.el | 65 ++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 40 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 339857c..7d85200 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -218,17 +218,14 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (let ((folded nil)) ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' (let-alist group - ;; .sample_account_ids .status_id .notifications_count - ;; .most_recent_notifiation_id (let* ((type-sym (intern .type)) (profile-note - (when (member type-sym '(follow follow_request)) + (when (member type-sym '(follow_request)) (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) - (follower (when (member type-sym - '(follow follow_request)) + (follower (when (member type-sym '(follow follow_request)) (car accounts))) (follower-name (mastodon-tl--field 'username follower)) (filtered (mastodon-tl--field 'filtered status)) @@ -238,47 +235,35 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--insert-note ;; toot ;; FIXME: fix following etc. on action authors - ;; FIXME: block boost/fave on boost/fave notifs? - (if (member type-sym - ;; reblogs/faves use 'note' to process their own - ;; json not the toot's. this ensures following etc. - ;; work on such notifs - '(follow follow_request)) + (if (member type-sym '(follow follow_request)) follower status) ;; body (let ((body (if-let ((match (assoc "warn" filters))) (mastodon-tl--spoiler status (cadr match)) (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (propertize - (mastodon-notifications--comment-note-text body) - ;; indent faves/boosts (maybe remove, as it makes - ;; cursor highlight ugly) - ;; but it's nice to be able to differentiate top - ;; byline a little from body of item acted on - ;; 'line-prefix "" - ;; 'wrap-prefix "" - )) - (t body))) + (cond ((mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status)) + ((eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note)) + (t (mastodon-tl--content status))))))) + (cond + ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow_request) + (concat + (propertize (format "You have a follow request from %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (propertize + (mastodon-notifications--comment-note-text body))) + (t body))) ;; author-byline #'mastodon-tl--byline-author ;; action-byline -- cgit v1.2.3 From be46982de5a59bfa0da674953079c72d71153395 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:06:41 +0200 Subject: notifs : remove stale id arg --- lisp/mastodon-notifications.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 7d85200..6b63c3e 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -279,7 +279,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; action symbol: (unless (eq type-sym 'mention) (mastodon-tl--symbol type-sym)) - .status_id ;; base toot (no need for update/poll/?) (when (member type-sym '(favourite reblog)) status) @@ -289,7 +288,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note (toot body author-byline action-byline action-authors action-symbol - &optional id base-toot unfolded group accounts) + &optional base-toot unfolded group accounts) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author -- cgit v1.2.3 From c9370483b3beacc164438cd158f7e8b2965fbc42 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:06:49 +0200 Subject: notifs: byline authors: help-echo remaining byline authors --- lisp/mastodon-notifications.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6b63c3e..b5a0ff4 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -387,8 +387,12 @@ When DOMAIN, force inclusion of user's domain in their handle." nil ", ") (if (< accts total) (let ((diff (- total accts))) - ;; FIXME: help echo all remaining accounts? - (format " and %s other%s" diff (if (= 1 diff) "" "s"))))))) + (propertize ;; help-echo remaining notifs authors: + (format " and %s other%s" diff (if (= 1 diff) "" "s")) + 'help-echo (mapconcat (lambda (a) + (alist-get 'username a)) + (cddr accounts) ;; not first two + " "))))))) (defun mastodon-notifications--render (json) "Display grouped notifications in JSON." -- cgit v1.2.3 From 6da29b195192d65e1567e593ad761107e1dbfe1f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:09:46 +0200 Subject: notifs: remove comment --- lisp/mastodon-notifications.el | 2 -- 1 file changed, 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b5a0ff4..b54b012 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -284,8 +284,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." status) folded group accounts)))))) -;; FIXME: this is copied from `mastodon-tl--insert-status' -;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note (toot body author-byline action-byline action-authors action-symbol &optional base-toot unfolded group accounts) -- cgit v1.2.3 From 91058026d2d98b62072f372211b899a0c31433df Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 22:07:04 +0200 Subject: notifs: handle actions fixed via user-handles-get --- lisp/mastodon-tl.el | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f4051a3..b0658e2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2551,23 +2551,29 @@ LANGS is the accumulated array param alist if we re-run recursively." (get-text-property (point) 'profile-json)) (list (alist-get 'acct (mastodon-profile--profile-json)))) + ;; (grouped) notifications: + ((member (mastodon-tl--get-buffer-type) '(mentions notifications)) + (append ;; those acting on item: + (cl-remove-duplicates + (cl-loop for a in (mastodon-tl--property 'notification-accounts :no-move) + collect (alist-get 'acct a))) + ;; mentions in item: + (mastodon-profile--extract-users-handles + (mastodon-profile--item-json)))) (t (mastodon-profile--extract-users-handles (mastodon-profile--item-json)))))) - ;; return immediately if only 1 handle: - (if (eq 1 (length user-handles)) - (car user-handles) - (completing-read (cond ((or ; TODO: make this "enable/disable notifications" - (string= action "disable") - (string= action "enable")) - (format "%s notifications when user posts: " action)) - ((string-suffix-p "boosts" action) - (format "%s by user: " action)) - (t - (format "Handle of user to %s: " action))) - user-handles - nil ; predicate - 'confirm))))) + (completing-read (cond ((or ; TODO: make this "enable/disable notifications" + (string= action "disable") + (string= action "enable")) + (format "%s notifications when user posts: " action)) + ((string-suffix-p "boosts" action) + (format "%s by user: " action)) + (t + (format "Handle of user to %s: " action))) + user-handles + nil ; predicate + 'confirm)))) (defun mastodon-tl--get-blocks-or-mutes-list (action) "Fetch the list of accounts for ACTION from the server. -- cgit v1.2.3 From d728369ca44cf2ca76935079e0cd5e10521464eb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 22:07:25 +0200 Subject: remove mastodon-active-user from extract-users-handles --- lisp/mastodon-profile.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index ce7fddd..900e9c0 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -861,13 +861,15 @@ These include the author, author of reblogged entries and any user mentioned." status)) ; status is a user listing (mentions (mastodon-tl--field-status 'mentions status)) (reblog (mastodon-tl--field-status 'reblog status))) - (seq-filter #'stringp - (seq-uniq - (seq-concatenate - 'list - (list (alist-get 'acct this-account)) - (mastodon-profile--extract-users-handles reblog) - (mastodon-tl--map-alist 'acct mentions))))))) + (seq-remove + (lambda (x) (string= x mastodon-active-user)) + (seq-filter #'stringp + (seq-uniq + (seq-concatenate + 'list + (list (alist-get 'acct this-account)) + (mastodon-profile--extract-users-handles reblog) + (mastodon-tl--map-alist 'acct mentions)))))))) (defun mastodon-profile--lookup-account-in-status (handle status) "Return account for HANDLE using hints in STATUS if possible." -- cgit v1.2.3 From cb9be01c7e57a38b58ab79ecce1f80b868701e20 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 08:22:36 +0200 Subject: notifs: fix do-user-action and get-user-handles for grouped notifs notifs: user action and response: if nothing in notifs data, fallback --- lisp/mastodon-tl.el | 110 +++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 49 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b0658e2..cdfdf5f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2535,45 +2535,44 @@ LANGS is the accumulated array param alist if we re-run recursively." "Get the list of user-handles for ACTION from the current toot." (mastodon-tl--do-if-item (let ((user-handles - (cond ((or ; follow suggests / search / foll requests compat: - (mastodon-tl--buffer-type-eq 'follow-suggestions) - (mastodon-tl--buffer-type-eq 'search) - (mastodon-tl--buffer-type-eq 'follow-requests) - ;; profile follows/followers but not statuses: - (mastodon-tl--buffer-type-eq 'profile-followers) - (mastodon-tl--buffer-type-eq 'profile-following)) - ;; fetch 'item-json: - (list (alist-get 'acct - (mastodon-tl--property 'item-json :no-move)))) - ;; profile view, point in profile details, poss no toots - ;; needed for e.g. gup.pe groups which show no toots publically: - ((and (mastodon-tl--profile-buffer-p) - (get-text-property (point) 'profile-json)) - (list (alist-get 'acct - (mastodon-profile--profile-json)))) - ;; (grouped) notifications: - ((member (mastodon-tl--get-buffer-type) '(mentions notifications)) - (append ;; those acting on item: - (cl-remove-duplicates - (cl-loop for a in (mastodon-tl--property 'notification-accounts :no-move) - collect (alist-get 'acct a))) - ;; mentions in item: - (mastodon-profile--extract-users-handles - (mastodon-profile--item-json)))) - (t - (mastodon-profile--extract-users-handles - (mastodon-profile--item-json)))))) - (completing-read (cond ((or ; TODO: make this "enable/disable notifications" - (string= action "disable") - (string= action "enable")) - (format "%s notifications when user posts: " action)) - ((string-suffix-p "boosts" action) - (format "%s by user: " action)) - (t - (format "Handle of user to %s: " action))) - user-handles - nil ; predicate - 'confirm)))) + (cond + ((or ; follow suggests / search / foll requests compat: + (member (mastodon-tl--get-buffer-type) + '( follow-suggestions search follow-requests + ;; profile follows/followers but not statuses: + profile-followers profile-following))) + ;; fetch 'item-json: + (list (alist-get 'acct + (mastodon-tl--property 'item-json :no-move)))) + ;; profile view, point in profile details, poss no toots + ;; needed for e.g. gup.pe groups which show no toots publically: + ((and (mastodon-tl--profile-buffer-p) + (get-text-property (point) 'profile-json)) + (list (alist-get 'acct + (mastodon-profile--profile-json)))) + ;; (grouped) notifications: + ((member (mastodon-tl--get-buffer-type) '(mentions notifications)) + (append ;; those acting on item: + (cl-remove-duplicates + (cl-loop for a in (mastodon-tl--property + 'notification-accounts :no-move) + collect (alist-get 'acct a))) + ;; mentions in item: + (mastodon-profile--extract-users-handles + (mastodon-profile--item-json)))) + (t + (mastodon-profile--extract-users-handles + (mastodon-profile--item-json)))))) + (completing-read + (cond ((or ; TODO: make this "enable/disable notifications" + (string= action "disable") + (string= action "enable")) + (format "%s notifications when user posts: " action)) + ((string-suffix-p "boosts" action) + (format "%s by user: " action)) + (t (format "Handle of user to %s: " action))) + user-handles nil ; predicate + 'confirm)))) (defun mastodon-tl--get-blocks-or-mutes-list (action) "Fetch the list of accounts for ACTION from the server. @@ -2599,16 +2598,29 @@ NOTIFY is only non-nil when called by `mastodon-tl--follow-user'. LANGS is an array parameters alist of languages to filer user's posts by. REBLOGS is a boolean string like NOTIFY, enabling or disabling display of the user's boosts in your timeline." - (let* ((account (if negp - ;; unmuting/unblocking, handle from mute/block list - (mastodon-profile--search-account-by-handle user-handle) - (mastodon-profile--lookup-account-in-status - user-handle - (if (mastodon-tl--profile-buffer-p) - ;; profile view, use 'profile-json as status: - (mastodon-profile--profile-json) - ;; muting/blocking, select from handles in current status - (mastodon-profile--item-json))))) + (let* ((account + (cond + (negp ;; unmuting/unblocking, use mute/block list + (mastodon-profile--search-account-by-handle user-handle)) + ;; (grouped) notifications: + ((member (mastodon-tl--get-buffer-type) + '(mentions notifications)) + (let ((accounts (mastodon-tl--property 'notification-accounts))) + (or (cl-some (lambda (x) + (when (string= user-handle (alist-get 'acct x)) + x)) + accounts) + (mastodon-profile--lookup-account-in-status + user-handle + (mastodon-profile--item-json))))) + (t + (mastodon-profile--lookup-account-in-status + user-handle + (if (mastodon-tl--profile-buffer-p) + ;; profile view, use 'profile-json as status: + (mastodon-profile--profile-json) + ;; muting/blocking, select from handles in current status + (mastodon-profile--item-json)))))) (user-id (alist-get 'id account)) (name (if (string-empty-p (alist-get 'display_name account)) (alist-get 'username account) -- cgit v1.2.3 From f4fb3251d3dcec60f088e6a822319ba8b4556921 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 08:23:34 +0200 Subject: do use action response: change cond clause not/or to make a neither --- lisp/mastodon-tl.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index cdfdf5f..77eb320 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2674,8 +2674,7 @@ ARGS is an alist of any parameters to send with the request." ((assoc "languages[]" args #'string=) (message "User %s filtered by language(s): %s" name (mapconcat #'cdr args " "))) - ((and (eq notify nil) - (eq reblogs nil)) + ((not (or notify reblogs)) (if (and (string= action "follow") (eq t (alist-get 'requested json))) (message "Follow requested for user %s (@%s)!" name user-handle) -- cgit v1.2.3 From 390c1d0c2dec6f247830cd507d8d1e8ca4db3479 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 09:13:07 +0200 Subject: bump version, copyright --- lisp/mastodon-discover.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 2 +- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-profile.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon-views.el | 2 +- lisp/mastodon.el | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index c34d85f..9278432 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -1,7 +1,7 @@ ;;; mastodon-discover.el --- Use Mastodon.el with discover.el -*- lexical-binding: t -*- ;; Copyright (C) 2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index c0402f0..42b599d 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -1,7 +1,7 @@ ;;; mastodon-http.el --- HTTP request/response functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 43c8ba4..adc6d64 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -1,7 +1,7 @@ ;;; mastodon-inspect.el --- Client for Mastodon -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 2ec498e..fff5d23 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -1,7 +1,7 @@ ;;; mastodon-media.el --- Functions for inlining Mastodon media -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b54b012..c2257b2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -1,7 +1,7 @@ ;;; mastodon-notifications.el --- Notification functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 900e9c0..8db1d69 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -1,7 +1,7 @@ ;;; mastodon-profile.el --- Functions for inspecting Mastodon profiles -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 77eb320..92bf0a6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1,7 +1,7 @@ ;;; mastodon-tl.el --- Timeline functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 386b720..b5322b3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1,7 +1,7 @@ ;;; mastodon-toot.el --- Minor mode for sending Mastodon toots -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index ac62b1f..3112c20 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -1,6 +1,6 @@ ;;; mastodon-views.el --- Minor views functions for mastodon.el -*- lexical-binding: t -*- -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Marty Hiatt ;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 80b6d8c..e754b28 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -6,7 +6,7 @@ ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -;; Version: 1.0.27 +;; Version: 1.1.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.0") ;; (persist "0.4") (tp "0.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el -- cgit v1.2.3 From 854b7027bc390807876595d2a014e9e61abad591 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 11:38:35 +0200 Subject: images in threads: load images for single-toot and thread toot --- lisp/mastodon-tl.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 92bf0a6..b0f5981 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2281,6 +2281,9 @@ ID is that of the toot to view." #'mastodon-tl--update-toot) (mastodon-tl--toot toot :detailed-p) (goto-char (point-min)) + (when mastodon-tl--display-media-p + (mastodon-media--inline-images (point-min) + (point-max))) (mastodon-tl--goto-next-item :no-refresh))))) (defun mastodon-tl--update-toot (json) @@ -2339,6 +2342,11 @@ view all branches of a thread." (move-marker marker (point)) ;; print re-fetched toot: (mastodon-tl--toot toot :detailed-p :thread) + ;; inline images only for the toot + ;; (`mastodon-tl--timeline' handles the rest): + (when mastodon-tl--display-media-p + (mastodon-media--inline-images marker ;start-pos + (point))) (mastodon-tl--timeline (alist-get 'descendants context) :thread) ;; put point at the toot: -- cgit v1.2.3 From ce4c59c4328b7050bd9e0844980ce9c8f91a7f82 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 15:32:53 +0200 Subject: add boost symbol in boost author byline --- lisp/mastodon-tl.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b0f5981..50d623a 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -687,10 +687,15 @@ ACCOUNT is optionally acccount data to use." (alist-get 'avatar (alist-get 'account data)))) (if (not base) - (mastodon-tl--byline-handle - data domain account - ;; display uname not handle (for boosts): - uname 'mastodon-display-name-face) + ;; boost symbol: + (concat (mastodon-tl--symbol 'boost) + " " + ;; username as button: + (mastodon-tl--byline-handle + data domain account + ;; display uname not handle (for boosts): + uname 'mastodon-display-name-face)) + ;; normal combo author byline: (mastodon-tl--byline-uname-+-handle data domain account))))) (defun mastodon-tl--format-byline-help-echo (toot) -- cgit v1.2.3 From 6975a22a1c3b403b5aa86bb7a375220b6b0f9fea Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 12:10:04 +0200 Subject: bylines: try out booster byline as top byline (like notifs) --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 50d623a..7d333e4 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1686,6 +1686,7 @@ NO-BYLINE means just insert toot body, used for folding." (propertize ;; body only: (concat "\n" + (funcall action-byline toot) ;; relpy symbol: (when (and after-reply-status-p thread) (concat (mastodon-tl--symbol 'replied) @@ -1705,9 +1706,8 @@ NO-BYLINE means just insert toot body, used for folding." "\n" (if no-byline "" - (concat (funcall action-byline toot) - (mastodon-tl--byline toot author-byline detailed-p - domain base-toot group)))) + (mastodon-tl--byline toot author-byline detailed-p + domain base-toot group))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id -- cgit v1.2.3 From deaedf0d8d8f516909afa1d2bafda654896f958e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 12:23:39 +0200 Subject: notifs: remove stray space at beginning of mentions --- lisp/mastodon-notifications.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c2257b2..f163863 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -314,8 +314,10 @@ ACCOUNTS is the notification accounts data." (propertize ;; top byline, body + byline: (concat (propertize ;; top byline - (concat action-symbol " " action-authors - action-byline) + (if (equal type "mention") + "" + (concat action-symbol " " action-authors + action-byline)) 'byline-top t) (propertize ;; body only body -- cgit v1.2.3 From 595ad8b8620a63b7ef5a7569bc6cb44675904051 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 12:30:22 +0200 Subject: remove stray " " from byline-booster --- lisp/mastodon-tl.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7d333e4..95632cd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -749,8 +749,7 @@ The result is added as an attachments property to author-byline." Only return something if TOOT contains a reblog." (let ((reblog (alist-get 'reblog toot))) (if reblog - (concat - " " (mastodon-tl--byline-author toot)) + (mastodon-tl--byline-author toot) ""))) (defun mastodon-tl--byline-booster-str (toot) -- cgit v1.2.3 From cfe4703513dc574a58baf1fd7883082563bdbcc5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 21:55:39 +0200 Subject: notifs: remove stale notifs code from tl--insert-status --- lisp/mastodon-notifications.el | 1 - lisp/mastodon-tl.el | 24 +++++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index f163863..cb36616 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -46,7 +46,6 @@ (autoload 'mastodon-tl--find-property-range "mastodon-tl") (autoload 'mastodon-tl--has-spoiler "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl") -(autoload 'mastodon-tl--insert-status "mastodon-tl") (autoload 'mastodon-tl--property "mastodon-tl") (autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") (autoload 'mastodon-tl--spoiler "mastodon-tl") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 95632cd..5d0fafc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -798,7 +798,9 @@ By default it is `mastodon-tl--byline-author' DETAILED-P means display more detailed info. For now this just means displaying toot client. When DOMAIN, force inclusion of user's domain in their handle. -BASE-TOOT is JSON for the base toot, if any." +BASE-TOOT is JSON for the base toot, if any. +GROUP is the notification group if any. +ACCOUNT is the notification account if any." (let* ((created-time (if group (mastodon-tl--field 'latest_page_notification_at group) @@ -814,9 +816,7 @@ BASE-TOOT is JSON for the base toot, if any." (boosted (eq t (mastodon-tl--field 'reblogged toot))) (bookmarked (eq t (mastodon-tl--field 'bookmarked toot))) (visibility (mastodon-tl--field 'visibility toot)) - (type (if group - (alist-get 'type group) - (alist-get 'type toot))) + (type (alist-get 'type (or group toot))) (base-toot-maybe (or base-toot ;; show edits for notifs (mastodon-tl--toot-or-base toot))) ;; for boosts (account (or account @@ -1648,7 +1648,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id base-toot - detailed-p thread domain unfolded no-byline group accounts) + detailed-p thread domain unfolded no-byline) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author @@ -1668,14 +1668,11 @@ 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." - (let* ((reply-to-id - (if group - (alist-get 'status_id group) - (alist-get 'in_reply_to_id toot))) + (let* ((reply-to-id (alist-get 'in_reply_to_id toot)) (after-reply-status-p (when (and thread reply-to-id) (mastodon-tl--after-reply-status reply-to-id))) - (type (alist-get 'type (or group toot))) + ;; (type (alist-get 'type toot)) (toot-foldable (and mastodon-tl--fold-toots-at-length (length> body mastodon-tl--fold-toots-at-length)))) @@ -1706,7 +1703,7 @@ NO-BYLINE means just insert toot body, used for folding." (if no-byline "" (mastodon-tl--byline toot author-byline detailed-p - domain base-toot group))) + domain base-toot))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -1719,10 +1716,7 @@ NO-BYLINE means just insert toot body, used for folding." 'base-toot base-toot 'cursor-face 'mastodon-cursor-highlight-face 'toot-foldable toot-foldable - 'toot-folded (and toot-foldable (not unfolded)) - 'notification-type type - 'notification-group group - 'notification-accounts accounts) + 'toot-folded (and toot-foldable (not unfolded))) (if no-byline "" "\n")))) (defun mastodon-tl--is-reply (toot) -- cgit v1.2.3 From 31f77807011aee93957322b4134fb10b6f815a72 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 22:01:21 +0200 Subject: bump min emacs to 28.1 --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e754b28..37da99c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -7,7 +7,7 @@ ;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.1.0 -;; Package-Requires: ((emacs "27.1") (request "0.3.0") +;; Package-Requires: ((emacs "28.1") (request "0.3.0") ;; (persist "0.4") (tp "0.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el -- cgit v1.2.3 From a47313e2fb1509028f022ac24ce311057023f4ca Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 22:14:44 +0200 Subject: flycheck toot --- lisp/mastodon-toot.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index b5322b3..cc75fae 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -181,7 +181,7 @@ width fonts")) (defvar mastodon-toot-visibility-settings-list '("public" "unlisted" "private") "A list of the available default toot visibility settings. -Like `mastodon-toot-visibility-list' but without 'direct.") +Like `mastodon-toot-visibility-list' but without direct.") (defvar-local mastodon-toot--visibility nil "A string indicating the visibility of the toot being composed. @@ -541,7 +541,8 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement." (defun mastodon-toot--list-boosters-or-favers (&optional favourite accounts) "List the favouriters or boosters of toot at point. -With FAVOURITE, list favouriters, else list boosters." +With FAVOURITE, list favouriters, else list boosters. +ACCOUNTS is notfications accounts if any." (mastodon-toot--with-toot-item (let* ((endpoint (unless accounts (if favourite "favourited_by" "reblogged_by"))) -- cgit v1.2.3 From 9aeb84f4fd781f931e2e78573cbd85edd2a22db7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 22:20:44 +0200 Subject: flychecks --- lisp/mastodon-http.el | 3 ++- lisp/mastodon-media.el | 1 + lisp/mastodon-profile.el | 1 + lisp/mastodon-search.el | 9 +++++---- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 42b599d..5035cb4 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -302,7 +302,8 @@ Optionally specify the PARAMS to send." (defun mastodon-http--patch (url &optional params json) "Make synchronous PATCH request to URL. -Optionally specify the PARAMS to send." +Optionally specify the PARAMS to send. +JSON means send params as JSON data." (mastodon-http--authorized-request "PATCH" ;; NB: unlike POST, PATCHing only works if we use query params! ;; so here, unless JSON arg, we use query params and do not set diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index fff5d23..ccd258c 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -38,6 +38,7 @@ (require 'image-mode) (autoload 'mastodon-tl--propertize-img-str-or-url "mastodon-tl") +(autoload 'mastodon-tl--image-trans-check "mastodon-tl") (defvar url-show-status) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8db1d69..c6a0276 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -84,6 +84,7 @@ (autoload 'mastodon-search--query "mastodon-search") (autoload 'mastodon-tl--field-status "mastodon-tl") +(defvar mastodon-active-user) (defvar mastodon-tl--horiz-bar) (defvar mastodon-tl--update-point) (defvar mastodon-toot--max-toot-chars) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 90519ed..262f75c 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -28,8 +28,7 @@ ;;; Code: (require 'json) -(eval-when-compile - (require 'mastodon-tl)) +(require 'mastodon-tl) (autoload 'mastodon-auth--access-token "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") @@ -44,6 +43,7 @@ (autoload 'mastodon-tl--timeline "mastodon-tl") (autoload 'mastodon-tl--toot "mastodon-tl") (autoload 'mastodon-tl--buffer-property "mastodon-tl") +(autoload 'mastodon-http--api-v2 "mastodon-http") (defvar mastodon-toot--completion-style-for-mentions) (defvar mastodon-instance-url) @@ -165,7 +165,8 @@ Optionally add string TYPE after HEADING." (defun mastodon-search--format-heading (str &optional type no-newline) "Format STR as a heading. -Optionally add string TYPE after HEADING." +Optionally add string TYPE after HEADING. +NO-NEWLINE means don't add add a newline at end." (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " (upcase str) " " @@ -189,7 +190,7 @@ is used for pagination." ;; TODO: handle no results (interactive "sSearch mastodon for: ") (let* ((url (mastodon-http--api-v2 "search")) - (following (when (or following (eq current-prefix-arg '(4))) + (following (when (or following (equal current-prefix-arg '(4))) "true")) (type (or type (if (eq current-prefix-arg '(4)) -- cgit v1.2.3 From bfb2b4b2276622830b7a5ed1066c64ef6d5693e8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 10:11:40 +0200 Subject: refactor display-or-uname --- lisp/mastodon-notifications.el | 5 +---- lisp/mastodon-search.el | 4 +--- lisp/mastodon-tl.el | 34 ++++++++++++++++------------------ 3 files changed, 18 insertions(+), 25 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index cb36616..0177ba7 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -376,10 +376,7 @@ When DOMAIN, force inclusion of user's domain in their handle." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering .avatar)) - (let ((uname - (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)))) + (let ((uname (mastodon-tl--display-or-uname account))) (mastodon-tl--byline-handle toot nil account uname 'mastodon-display-name-face)) ", "))) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 262f75c..cead17e 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -331,9 +331,7 @@ If NOTE is non-nil, include user's profile note. This is also (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." - (list (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)) + (list (mastodon-tl--display-or-uname account) (alist-get 'acct account) (alist-get 'url account) (alist-get 'note account))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5d0fafc..437a5e3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -661,6 +661,12 @@ ACCOUNT is optionally acccount data to use." (concat (mastodon-tl--byline-username data account) " (" (mastodon-tl--byline-handle data domain account) ")")) +(defun mastodon-tl--display-or-uname (account) + "Return display name or username from ACCOUNT data." + (if (not (string-empty-p (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account))) + (defun mastodon-tl--byline-author (toot &optional avatar domain base account) "Propertize author of TOOT. If TOOT contains a reblog, return author of reblogged item. @@ -673,9 +679,7 @@ ACCOUNT is optionally acccount data to use." (mastodon-tl--toot-or-base toot) toot)) (account (or account (alist-get 'account data))) - (uname (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)))) + (uname (mastodon-tl--display-or-uname account))) (concat ;; avatar insertion moved up to `mastodon-tl--byline' by default to ;; be outside 'byline propt. @@ -684,8 +688,7 @@ ACCOUNT is optionally acccount data to use." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering - (alist-get 'avatar - (alist-get 'account data)))) + (map-nested-elt data '(account avatar)))) (if (not base) ;; boost symbol: (concat (mastodon-tl--symbol 'boost) @@ -873,10 +876,9 @@ ACCOUNT is the notification account if any." 'help-echo ts)) ;; detailed: (when detailed-p - (let* ((app (alist-get 'application toot)) - (app-name (alist-get 'name app)) - (app-url (alist-get 'website app))) - (when app + (let* ((app-name (map-nested-elt toot '(application name))) + (app-url (map-nested-elt toot '(application website)))) + (when app-name (concat (propertize " via " 'face 'default) (propertize app-name @@ -973,9 +975,8 @@ links in the text. If TOOT is nil no parsing occurs." (get-text-property (car region) 'shr-url)) (when (proper-list-p toot) ;; not on profile fields cons cells ;; render card author maybe: - (let* ((card (alist-get 'card toot)) - (card-url (alist-get 'url card)) - (authors (alist-get 'authors card)) + (let* ((card-url (map-nested-elt toot '(card url))) + (authors (map-nested-elt toot '(card authors))) (url (buffer-substring (car region) (cdr region))) (url-no-query (car (split-string url "?")))) (when (and (string= url-no-query card-url) @@ -1121,7 +1122,7 @@ the toot)." (url-generic-parse-url instance-url))) (parsed (url-generic-parse-url url)) (path (url-filename parsed)) - (split (string-split path "/"))) + (split (split-string path "/"))) (when (and (string= instance-host (url-host parsed)) (string-prefix-p "/tag" path)) ;; "/tag/" or "/tags/" (nth 2 split)))) @@ -2395,8 +2396,7 @@ If UNMUTE, unmute it." (defun mastodon-tl--map-account-id-from-toot (statuses) "Return a list of the account IDs of the author of each toot in STATUSES." (mapcar (lambda (status) - (alist-get 'id - (alist-get 'account status))) + (map-nested-elt status '(account id))) statuses)) (defun mastodon-tl--user-in-thread-p (id) @@ -2628,9 +2628,7 @@ display of the user's boosts in your timeline." ;; muting/blocking, select from handles in current status (mastodon-profile--item-json)))))) (user-id (alist-get 'id account)) - (name (if (string-empty-p (alist-get 'display_name account)) - (alist-get 'username account) - (alist-get 'display_name account))) + (name (mastodon-tl--display-or-uname account)) (args (cond (notify `(("notify" . ,notify))) (langs langs) (reblogs `(("reblogs" . ,reblogs))) -- cgit v1.2.3 From c7305179fcca04ebdf090c93dabd2c82bad5b6ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 10:36:49 +0200 Subject: remove stale fixme --- lisp/mastodon-notifications.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index cb36616..a7f358b 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -233,7 +233,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (unless (and filtered (assoc "hide" filters)) (mastodon-notifications--insert-note ;; toot - ;; FIXME: fix following etc. on action authors (if (member type-sym '(follow follow_request)) follower status) -- cgit v1.2.3 From e87f997e121e0486c7c55551a9d1f8c11a815173 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 10:55:40 +0200 Subject: change order of toot-visibility-list for sane cycling --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index cc75fae..95fccc3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -175,7 +175,7 @@ width fonts")) "A flag indicating whether the toot should be marked as NSFW.") (defvar mastodon-toot-visibility-list - '(direct private unlisted public) + '(public unlisted private direct) "A list of the available toot visibility settings.") (defvar mastodon-toot-visibility-settings-list -- cgit v1.2.3 From ef6762986de6f4c85405dbc01ae19854cd2687fd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 13:39:06 +0200 Subject: change email address --- README.org | 2 +- lisp/mastodon-async.el | 2 +- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-discover.el | 4 ++-- lisp/mastodon-http.el | 4 ++-- lisp/mastodon-inspect.el | 4 ++-- lisp/mastodon-iso.el | 2 +- lisp/mastodon-media.el | 4 ++-- lisp/mastodon-notifications.el | 4 ++-- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-search.el | 4 ++-- lisp/mastodon-tl.el | 4 ++-- lisp/mastodon-toot.el | 4 ++-- lisp/mastodon-transient.el | 2 +- lisp/mastodon-views.el | 4 ++-- lisp/mastodon.el | 4 ++-- mastodon.texi | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) (limited to 'lisp') diff --git a/README.org b/README.org index cf6aed5..1898366 100644 --- a/README.org +++ b/README.org @@ -487,7 +487,7 @@ If you prefer emailing patches to the process described below, feel free to send If you'd like to support continued development of =mastodon.el=, I accept donations via paypal: [[https://paypal.me/martianh][paypal.me/martianh]]. If you would prefer a different -payment method, please write to me at and I can +payment method, please write to me at and I can provide IBAN or other bank account details. I don't have a tech worker's income, so even a small tip would help out. diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 317be93..b059407 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Alex J. Griffith ;; Author: Alex J. Griffith -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 3796b7e..01639fb 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 6e55829..c0db3d6 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 9278432..993cc27 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 5035cb4..1093de1 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index adc6d64..4981943 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-iso.el b/lisp/mastodon-iso.el index 8ea5635..6199cbe 100644 --- a/lisp/mastodon-iso.el +++ b/lisp/mastodon-iso.el @@ -1,7 +1,7 @@ ;;; mastodon-iso.el --- ISO language code lists for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2022 Marty Hiatt -;; Author: Marty Hiatt +;; Author: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index ccd258c..8601410 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 8d2c928..b16b5a6 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c6a0276..40f834c 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index cead17e..25db7d8 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,8 +1,8 @@ ;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Marty Hiatt -;; Author: Marty Hiatt -;; Maintainer: Marty Hiatt +;; Author: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 437a5e3..1a4df7f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 95fccc3..fc5825a 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index fe70eac..526dfa4 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2024 martian hiatus -;; Author: martian hiatus +;; Author: martian hiatus ;; Keywords: convenience ;; This program is free software; you can redistribute it and/or modify diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 3112c20..8d356fb 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -1,8 +1,8 @@ ;;; mastodon-views.el --- Minor views functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2020-2024 Marty Hiatt -;; Author: Marty Hiatt -;; Maintainer: Marty Hiatt +;; Author: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 37da99c..cb5731a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -4,8 +4,8 @@ ;; Copyright (C) 2020-2022 Marty Hiatt ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Version: 1.1.0 ;; Package-Requires: ((emacs "28.1") (request "0.3.0") ;; (persist "0.4") (tp "0.1")) diff --git a/mastodon.texi b/mastodon.texi index dafa92d..d1c9268 100644 --- a/mastodon.texi +++ b/mastodon.texi @@ -818,7 +818,7 @@ There's no need for a blank line after the first docstring line (one is added au If you'd like to support continued development of @samp{mastodon.el}, I accept donations via paypal: @uref{https://paypal.me/martianh, paypal.me/martianh}. If you would prefer a different -payment method, please write to me at and I can +payment method, please write to me at and I can provide IBAN or other bank account details. I don't have a tech worker's income, so even a small tip would help out. -- cgit v1.2.3