From d90c104299636f2525f8b77001b4374e5b0df72a Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 28 Feb 2022 15:21:40 +0100 Subject: add copy-toot-text function --- lisp/mastodon-toot.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 48e7d96..1d80e55 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -271,6 +271,13 @@ Makes a POST request to the server." (kill-new url) (message "Toot URL copied to the clipboard."))) +(defun mastodon-toot--copy-toot-text () + "Copy text of toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json))) + (kill-new (mastodon-tl--content toot)) + (message "Toot content copied to the clipboard."))) + (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." (and (not (alist-get 'reblog toot)) -- cgit v1.2.3 From b1318ba12165d59cc1b7ce21d3b77099a3ff78d3 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 10 Mar 2022 13:14:11 +0100 Subject: translate toot with lingva.el this could easily be made into a macro supporting any emacs translation pkg --- lisp/mastodon-toot.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1d80e55..9c09441 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -70,6 +70,11 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") +; for mastodon-toot--translate-toot-text +(autoload 'mastodon-tl--content "mastodon-tl") +(when (require 'lingva nil :no-error) + (declare-function lingva-translate "lingva")) + (defgroup mastodon-toot nil "Tooting in Mastodon." :prefix "mastodon-toot-" @@ -278,6 +283,18 @@ Makes a POST request to the server." (kill-new (mastodon-tl--content toot)) (message "Toot content copied to the clipboard."))) +(when (require 'lingva nil :no-error) + (defun mastodon-toot--translate-toot-text () + "Translate text of toot at point. +Uses `lingva.el'." + (interactive) + (if mastodon-tl--buffer-spec + (let* ((toot (mastodon-tl--property 'toot-json))) + (if toot + (lingva-translate nil (mastodon-tl--content toot)) + (message "No toot to translate?"))) + (message "No mastodon buffer?")))) + (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." (and (not (alist-get 'reblog toot)) -- cgit v1.2.3 From 56995a8c693cca194e3272d17fec092c3585a3f4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Mar 2022 09:26:19 +0100 Subject: favourite not favorite --- lisp/mastodon-notifications.el | 4 ++-- lisp/mastodon-tl.el | 4 ++-- lisp/mastodon-toot.el | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 719a77b..041918d 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -146,7 +146,7 @@ Can be called in notifications view or in follow-requests view." (defun mastodon-notifications--favourite (note) "Format for a `favourite' NOTE." - (mastodon-notifications--format-note note 'favorite)) + (mastodon-notifications--format-note note 'favourite)) (defun mastodon-notifications--reblog (note) "Format for a `boost' NOTE." @@ -202,7 +202,7 @@ Status notifications are given when (mastodon-notifications--byline-concat (cond ((equal type 'boost) "Boosted") - ((equal type 'favorite) + ((equal type 'favourite) "Favourited") ((equal type 'follow-request) "Requested to follow") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6cd3ff0..e517397 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -376,7 +376,7 @@ Used on initializing a timeline or thread." ")"))) (defun mastodon-tl--format-faves-count (toot) - "Format a favorites, boosts, replies count for a TOOT. + "Format a favourites, boosts, replies count for a TOOT. Used as a help-echo when point is at the start of a byline, i.e. where `mastodon-tl--goto-next-toot' leaves point. Also displays a toot's media types and optionally the binding to play moving @@ -558,7 +558,7 @@ By default it is `mastodon-tl--byline-boosted'" 'byline t)))) (defun mastodon-tl--format-faved-or-boosted-byline (letter) - "Format the byline marker for a boosted or favorited status. + "Format the byline marker for a boosted or favourited status. LETTER is a string, either F or B." (format "(%s) " (propertize letter 'face 'mastodon-boost-fave-face))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9c09441..76d7d41 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -264,7 +264,7 @@ Makes a POST request to the server." (mastodon-toot--action-success "F" byline-region remove)) (message (format "%s #%s" action id)))) - (message "Nothing to favorite here?!?")))) + (message "Nothing to favourite here?!?")))) (defun mastodon-toot--copy-toot-url () "Copy URL of toot at point." -- cgit v1.2.3 From db2d0aed887c072e1a100ee54205091e1f2d981c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 18 Mar 2022 10:05:56 +0100 Subject: remove require test for --translate-toot-text we already have the same test for declaring lingva-translate fun, so this shouldn't be needed and seems to prevent our fun from loading. --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 76d7d41..780e726 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -283,7 +283,7 @@ Makes a POST request to the server." (kill-new (mastodon-tl--content toot)) (message "Toot content copied to the clipboard."))) -(when (require 'lingva nil :no-error) +;; (when (require 'lingva nil :no-error) (defun mastodon-toot--translate-toot-text () "Translate text of toot at point. Uses `lingva.el'." @@ -293,7 +293,7 @@ Uses `lingva.el'." (if toot (lingva-translate nil (mastodon-tl--content toot)) (message "No toot to translate?"))) - (message "No mastodon buffer?")))) + (message "No mastodon buffer?"))) (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." -- cgit v1.2.3 From c7b475160d2e7712e339e15adf168529f71b52c6 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 19 Mar 2022 16:07:44 +0100 Subject: attach parent JSON to fave/boost notifs to fix replies because we switched to using boost/fave JSON rather than parent, as 'toot-json, replies to these toots were broken (mentions, etc.) so now we attach both bits of data and selectively pull from each. --- lisp/mastodon-notifications.el | 9 ++++++--- lisp/mastodon-tl.el | 5 +++-- lisp/mastodon-toot.el | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 041918d..6b253ec 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -214,9 +214,12 @@ Status notifications are given when "Posted") ((equal type 'poll) "Posted a poll")))) - id))) + id + (when (or (equal type 'favourite) + (equal type 'boost)) + status)))) -(defun mastodon-notifications--insert-status (toot body author-byline action-byline id) +(defun mastodon-notifications--insert-status (toot body author-byline action-byline id &optional parent-toot) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -232,7 +235,7 @@ takes a single function. By default it is ID is the notification's own id, which is attached as a property." (when toot ; handle rare blank notif server bug - (mastodon-tl--insert-status toot body author-byline action-byline id))) + (mastodon-tl--insert-status toot body author-byline action-byline id parent-toot))) (defun mastodon-notifications--by-type (note) "Filters NOTE for those listed in `mastodon-notifications--types-alist'." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4833a3f..40cbcae 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -852,7 +852,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--get-poll toot)) (mastodon-tl--media toot)))) -(defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id) +(defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id parent-toot) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -876,7 +876,8 @@ a notification." 'toot-id (or id ; for notifications (alist-get 'id toot)) 'base-toot-id (mastodon-tl--toot-id toot) - 'toot-json toot) + 'toot-json toot + 'parent-toot parent-toot) "\n") (when mastodon-tl--display-media-p (mastodon-media--inline-images start-pos (point))))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 780e726..07ab400 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -617,11 +617,12 @@ candidate ARG. IGNORED remains a mystery." "Reply to toot at `point'." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) + (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id toot))) (account (mastodon-tl--field 'account toot)) (user (alist-get 'acct account)) - (mentions (mastodon-toot--mentions toot)) - (boosted (mastodon-tl--field 'reblog toot)) + (mentions (mastodon-toot--mentions (or parent toot))) + (boosted (mastodon-tl--field 'reblog (or parent toot))) (booster (when boosted (alist-get 'acct (alist-get 'account toot))))) @@ -637,7 +638,7 @@ candidate ARG. IGNORED remains a mystery." mentions)) (concat (mastodon-toot--process-local user) mentions))) - id toot))) + id (or parent toot)))) (defun mastodon-toot--toggle-warning () "Toggle `mastodon-toot--content-warning'." -- cgit v1.2.3 From 6d4528ca05d946892e13cbc4657d0c379445b13d Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 25 Mar 2022 17:39:19 +0100 Subject: call lingva-translate with optional variable-pitch arg --- lisp/mastodon-toot.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 07ab400..52b061c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -289,9 +289,12 @@ Makes a POST request to the server." Uses `lingva.el'." (interactive) (if mastodon-tl--buffer-spec - (let* ((toot (mastodon-tl--property 'toot-json))) + (let ((toot (mastodon-tl--property 'toot-json))) (if toot - (lingva-translate nil (mastodon-tl--content toot)) + (lingva-translate nil + (mastodon-tl--content toot) + (when mastodon-tl--enable-proportional-fonts + t)) (message "No toot to translate?"))) (message "No mastodon buffer?"))) -- cgit v1.2.3 From 1cc9cc621c9ab31419f965d5958ff24b1bc8f987 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 29 Mar 2022 21:34:23 +0200 Subject: toot--reply: improve mentions in replies - make sure we get ID from parent if its a fave/boost - avoid duplicates if user or booster already in mentions list --- lisp/mastodon-toot.el | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 52b061c..79f3d74 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -621,7 +621,8 @@ candidate ARG. IGNORED remains a mystery." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling - (id (mastodon-tl--as-string (mastodon-tl--field 'id toot))) + (id (mastodon-tl--as-string + (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) (user (alist-get 'acct account)) (mentions (mastodon-toot--mentions (or parent toot))) @@ -634,14 +635,27 @@ candidate ARG. IGNORED remains a mystery." (if (and (not (equal user booster)) (not (string-match booster mentions))) + ;; different booster, user and mentions: (concat (mastodon-toot--process-local user) ;; "@" booster " " - (mastodon-toot--process-local booster) mentions) + (mastodon-toot--process-local booster) + mentions) + ;; booster is either user or in mentions: + (if (not string-match user mentions) + ;; user not already in mentions: + (concat (mastodon-toot--process-local user) + mentions) + ;; user already in mentions: + mentions)) + ;; no booster: + (if (not (string-match user mentions)) + ;; user not in mentions: (concat (mastodon-toot--process-local user) - mentions)) - (concat (mastodon-toot--process-local user) - mentions))) - id (or parent toot)))) + mentions) + ;; user in mentions already: + mentions))) + id + (or parent toot)))) (defun mastodon-toot--toggle-warning () "Toggle `mastodon-toot--content-warning'." -- cgit v1.2.3 From 0794d93ab897a2cb8c917bb6884007b13e04a1d3 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:05 +0200 Subject: toot: indents and flycheck --- lisp/mastodon-toot.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 79f3d74..1f3440c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -48,6 +48,7 @@ (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) +(defvar mastodon-tl--enable-proportional-fonts) (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--delete "mastodon-http") @@ -70,7 +71,7 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") -; for mastodon-toot--translate-toot-text +;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") (when (require 'lingva nil :no-error) (declare-function lingva-translate "lingva")) @@ -176,9 +177,9 @@ Valid values are \"direct\", \"private\" (followers-only), (alist-get 'statuses (alist-get 'configuration json-response)))))) - (setq mastodon-toot--max-toot-chars max-chars) - (with-current-buffer "*new toot*" - (mastodon-toot--update-status-fields)))) + (setq mastodon-toot--max-toot-chars max-chars) + (with-current-buffer "*new toot*" + (mastodon-toot--update-status-fields)))) (defun mastodon-toot--action-success (marker byline-region remove) "Insert/remove the text MARKER with 'success face in byline. @@ -202,7 +203,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (propertize marker 'face 'success))))) ;; leave point after the marker: (unless remove - (mastodon-tl--goto-next-toot)))) + (mastodon-tl--goto-next-toot)))) (defun mastodon-toot--action (action callback) "Take ACTION on toot at point, then execute CALLBACK. @@ -296,7 +297,7 @@ Uses `lingva.el'." (when mastodon-tl--enable-proportional-fonts t)) (message "No toot to translate?"))) - (message "No mastodon buffer?"))) + (message "No mastodon buffer?")))) (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, e.g. for deleting it." @@ -350,7 +351,7 @@ NO-REDRAFT means delete toot only." (if no-redraft (progn (when mastodon-tl--buffer-spec - (mastodon-tl--reload-timeline-or-profile)) + (mastodon-tl--reload-timeline-or-profile)) (message "Toot deleted!")) (mastodon-toot--redraft response reply-id @@ -519,9 +520,9 @@ If media items have been attached and uploaded with (symbol-name t))) ("spoiler_text" . ,spoiler))) (args-media (when mastodon-toot--media-attachments - (mapcar (lambda (id) - (cons "media_ids[]" id)) - mastodon-toot--media-attachment-ids))) + (mapcar (lambda (id) + (cons "media_ids[]" id)) + mastodon-toot--media-attachment-ids))) (args (append args-media args-no-media))) (cond ((and mastodon-toot--media-attachments ;; make sure we have media args -- cgit v1.2.3 From 2fbf4694672e8dfa53767e6e2402490fa871d824 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:32 +0200 Subject: toot: missing parens in --reply booster checks --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1f3440c..6521b16 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -642,13 +642,13 @@ candidate ARG. IGNORED remains a mystery." (mastodon-toot--process-local booster) mentions) ;; booster is either user or in mentions: - (if (not string-match user mentions) + (if (not (string-match user mentions)) ;; user not already in mentions: (concat (mastodon-toot--process-local user) mentions) ;; user already in mentions: mentions)) - ;; no booster: + ;; ELSE no booster: (if (not (string-match user mentions)) ;; user not in mentions: (concat (mastodon-toot--process-local user) -- cgit v1.2.3 From adccdcd22a527720efaa38f57f3077d70687bdfe Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 5 Apr 2022 17:10:51 +0200 Subject: toot: message if translate-toot called without lingva.el --- lisp/mastodon-toot.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 6521b16..f8d0642 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -285,10 +285,12 @@ Makes a POST request to the server." (message "Toot content copied to the clipboard."))) ;; (when (require 'lingva nil :no-error) - (defun mastodon-toot--translate-toot-text () - "Translate text of toot at point. +(defun mastodon-toot--translate-toot-text () + "Translate text of toot at point. Uses `lingva.el'." - (interactive) + (interactive) + (if (not (require 'lingva nil :no-error)) + (message "Looks like you need to install lingva.el first.") (if mastodon-tl--buffer-spec (let ((toot (mastodon-tl--property 'toot-json))) (if toot -- cgit v1.2.3