From 1dca682bc22945a2e92aaea96ce8f87f9271b8a8 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 6 May 2021 19:31:11 +0200 Subject: delete toot keybinding --- lisp/mastodon.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 07535ec..8b2673c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -106,7 +106,9 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "t") #'mastodon-toot) ;; override special mode binding (define-key map (kbd "g") #'undefined) + (define-key map (kbd "D") #'mastodon-tl--delete-toot) map) + "Keymap for `mastodon-mode'.") (defcustom mastodon-mode-hook nil -- cgit v1.2.3 From 9575c3436e3b1ef1a9159d24a2c2a0f8afb27829 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 7 May 2021 10:35:11 +0200 Subject: cherry pick ieure's cosmetic changes --- lisp/mastodon-tl.el | 10 +++++----- lisp/mastodon.el | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ae21041..43be5fb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -266,7 +266,7 @@ Optionally start from POS." (let ((reblog (cdr (assoc 'reblog toot)))) (when reblog (concat - " " + "\n " (propertize "Boosted" 'face 'mastodon-boosted-face) " " (mastodon-tl--byline-author reblog))))) @@ -355,11 +355,11 @@ it is `mastodon-tl--byline-boosted'" (faved (equal 't (mastodon-tl--field 'favourited toot))) (boosted (equal 't (mastodon-tl--field 'reblogged toot)))) (concat - (propertize "\n | " 'face 'default) + ;; (propertize "\n | " 'face 'default) (propertize (concat (when boosted (format "(%s) " - (propertize "B" 'face 'mastodon-boost-fave-face))) + (propertize "B" 'face 'mastodon-boost-face))) (when faved (format "(%s) " (propertize "F" 'face 'mastodon-boost-fave-face))) @@ -592,13 +592,13 @@ message is a link which unhides/hides the main body." 'default)) (message (concat "\n" " ---------------\n" - " " (mastodon-tl--make-link "Content Warning" + " " (mastodon-tl--make-link + (concat "CW: " string) ;"Content Warning" 'content-warning) "\n" " ---------------\n")) (cw (mastodon-tl--set-face message 'mastodon-cw-face))) (concat - string cw (propertize (mastodon-tl--content toot) 'invisible t diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 8b2673c..99b23f7 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -126,7 +126,7 @@ Use. e.g. \"%c\" for your locale's date and time format." "Face used for user display names.") (defface mastodon-boosted-face - '((t :inherit highlight :weight bold)) + '((t :inherit success :weight bold)) "Face to indicate that a toot is boosted.") (defface mastodon-boost-fave-face -- cgit v1.2.3 From f511b7ca340918901d1eb9d0a6e97029ad92c443 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 7 May 2021 13:43:12 +0200 Subject: follow user binding --- lisp/mastodon.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 99b23f7..a6609ac 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -107,6 +107,7 @@ Use. e.g. \"%c\" for your locale's date and time format." ;; override special mode binding (define-key map (kbd "g") #'undefined) (define-key map (kbd "D") #'mastodon-tl--delete-toot) + (define-key map (kbd "W") #'mastodon-tl--follow-user) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 77941ed350b83ab36459e0bb1346699e1db992c2 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 8 May 2021 12:03:43 +0200 Subject: unfollow user fun --- lisp/mastodon-tl.el | 27 ++++++++++++++++++++++++++- lisp/mastodon.el | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 14623e6..10284d2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -45,6 +45,7 @@ ;; try an autoload for new follow fun (autoload 'mastodon-profile--toot-json "mastodon-profile.el") (autoload 'mastodon-profile--account-field "mastodon-profile.el") +(autoload 'mastodon-profile--extract-users-handles "mastodon-profile.el") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; need to declare it since Emacs24 didn't have this @@ -799,7 +800,7 @@ webapp" (message "Toot deleted! There may be a delay before it disappears from your profile.")))))) (defun mastodon-tl--follow-user (user-handle) - "Query user for user id from current status and follow that user." + "Query for user id from current status and follow that user." (interactive (list (let ((user-handles (mastodon-profile--extract-users-handles @@ -820,6 +821,30 @@ webapp" (message "User %s (@%s) followed!" name user-handle)))) (message "Cannot find a user with handle %S" user-handle)))) +(defun mastodon-tl--unfollow-user (user-handle) + "Query for user id from current status and unfollow that user." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "User handle: " + user-handles + nil ; predicate + 'confirm)))) + (let* ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json))) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/unfollow" user-id)))) + (if account + (when (y-or-n-p (format "Unfollow user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) unfollowed!" name user-handle)))) + (message "Cannot find a user with handle %S" user-handle))))) + + (defun mastodon-tl--more () "Append older toots to timeline." (interactive) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a6609ac..22c7c1c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -108,6 +108,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "g") #'undefined) (define-key map (kbd "D") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) + (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 6d944039bef1288745ae5535f6a407bb7cef1a51 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 8 May 2021 14:07:34 +0200 Subject: mute/unmute, block/unblock funs and bindings --- lisp/mastodon-tl.el | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++-- lisp/mastodon.el | 4 +++ 2 files changed, 103 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 10284d2..30982a2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -841,9 +841,106 @@ webapp" (let ((response (mastodon-http--post url nil nil))) (mastodon-http--triage response (lambda () - (message "User %s (@%s) unfollowed!" name user-handle)))) - (message "Cannot find a user with handle %S" user-handle))))) + (message "User %s (@%s) unfollowed!" name user-handle))))) + (message "Cannot find a user with handle %S" user-handle)))) + +(defun mastodon-tl--mute-user (user-handle) + "Query for user id from current status and mute that user." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "User handle: " + user-handles + nil ; predicate + 'confirm)))) + (let* ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json))) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/mute" user-id)))) + (if account + (when (y-or-n-p (format "Mute user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) muted!" name user-handle))))) + (message "Cannot find a user with handle %S" user-handle)))) + +(defun mastodon-tl--unmute-user (user-handle) + "Query for USER-HANDLE from list of muted users and unmute that user." + (interactive + (list + (let* ((mutes-url (mastodon-http--api (format "mutes"))) + (mutes-json (mastodon-http--get-json mutes-url)) + (muted-accts (mapcar (lambda (muted) + (cdr (assoc 'acct muted))) + mutes-json))) + (completing-read "Unmute user: " + muted-accts + nil ; predicate + t)))) + (let* ((account (mastodon-profile--search-account-by-handle + user-handle)) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/unmute" user-id)))) + (if account + (when (y-or-n-p (format "Unmute user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) unmuted!" name user-handle))))) + (message "Cannot find a user with handle %S" user-handle)))) +(defun mastodon-tl--block-user (user-handle) + "Query for USER-HANDLE from current status and block that user." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "User handle: " + user-handles + nil ; predicate + 'confirm)))) + (let* ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json))) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/block" user-id)))) + (if account + (when (y-or-n-p (format "Block user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) blocked!" name user-handle))))) + (message "Cannot find a user with handle %S" user-handle)))) + +(defun mastodon-tl--unblock-user (user-handle) + "Query for user from list of blocked users and unblock that user." + (interactive + (list + (let* ((blocks-url (mastodon-http--api (format "blocks"))) + (blocks-json (mastodon-http--get-json blocks-url)) + (blocked-accts (mapcar (lambda (blocked) + (cdr (assoc 'acct blocked))) + blocks-json))) + (completing-read "Unblock user: " + blocked-accts + nil ; predicate + t)))) + (let* ((account (mastodon-profile--search-account-by-handle + user-handle)) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/unblock" user-id)))) + (if account + (when (y-or-n-p (format "Unblock user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) unblocked!" name user-handle))))) + (message "Cannot find a user with handle %S" user-handle)))) (defun mastodon-tl--more () "Append older toots to timeline." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 22c7c1c..929ae8c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -109,6 +109,10 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "D") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) + (define-key map (kbd "B") #'mastodon-tl--block-user) + (define-key map (kbd "C-S-B") #'mastodon-tl--unblock-user) + (define-key map (kbd "M") #'mastodon-tl--mute-user) + (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From c69bf45a170a28934d18b762960845e773922514 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 8 May 2021 21:20:33 +0200 Subject: async view profile, async view thread, better prompts - view profile (using make-profile-buffer-for). - user confirm to delete toot. - better follow/mute/block/profile prompts --- lisp/mastodon-profile.el | 13 +++++++++---- lisp/mastodon-tl.el | 35 ++++++++++++++++++++--------------- lisp/mastodon.el | 3 ++- 3 files changed, 31 insertions(+), 20 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index aed33a7..2c6b798 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -102,12 +102,17 @@ following the current profile." (defun mastodon-profile--make-profile-buffer-for (account endpoint-type update-function) (let* ((id (mastodon-profile--account-field account 'id)) - (acct (mastodon-profile--account-field account 'acct)) (url (mastodon-http--api (format "accounts/%s/%s" - id endpoint-type))) + id endpoint-type)))) + (mastodon-http--get-json-async url + 'mastodon-profile--make-profile-buffer-for* + account endpoint-type update-function))) + +(defun mastodon-profile--make-profile-buffer-for* (json account endpoint-type update-function) + (let* ((acct (mastodon-profile--account-field account 'acct)) (buffer (concat "*mastodon-" acct "-" endpoint-type "*")) (note (mastodon-profile--account-field account 'note)) - (json (mastodon-http--get-json url)) + (id (mastodon-profile--account-field account 'id)) (fol_count (mastodon-tl--as-string (mastodon-profile--account-field account 'followers_count))) (folling_count (mastodon-tl--as-string (mastodon-profile--account-field account 'following_count))) (toots_count (mastodon-tl--as-string (mastodon-profile--account-field account 'statuses_count)))) @@ -175,7 +180,7 @@ following the current profile." (list (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) - (completing-read "User handle: " + (completing-read "View profile of user: " user-handles nil ; predicate 'confirm)))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a1c6495..b44b160 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -771,14 +771,18 @@ webapp" (if reblog (cdr (assoc 'id reblog)) id))) (defun mastodon-tl--thread () - "Open thread buffer for toot under `point'." + "Open thread buffer for toot under `point' asynchronously." (interactive) (let* ((id (mastodon-tl--as-string (mastodon-tl--toot-id (mastodon-tl--property 'toot-json)))) - (url (mastodon-http--api (format "statuses/%s/context" id))) - (buffer (format "*mastodon-thread-%s*" id)) (toot (mastodon-tl--property 'toot-json)) - (context (mastodon-http--get-json url))) + (buffer (format "*mastodon-thread-%s*" id)) + (url (mastodon-http--api (format "statuses/%s/context" id)))) + (mastodon-http--get-json-async url + 'mastodon-tl--thread* id toot buffer))) + +(defun mastodon-tl--thread* (context id toot buffer) + (interactive) (when (member (cdr (assoc 'type toot)) '("reblog" "favourite")) (setq toot (cdr (assoc 'status toot)))) (if (> (+ (length (cdr (assoc 'ancestors context))) @@ -797,7 +801,7 @@ webapp" (cdr (assoc 'ancestors context)) `(,toot) (cdr (assoc 'descendants context)))))) - (message "No Thread!")))) + (message "No Thread!")));) (defun mastodon-tl--delete-toot () "Delete user's toot at point synchronously." @@ -805,10 +809,11 @@ webapp" (let* ((id (mastodon-tl--as-string (mastodon-tl--toot-id (mastodon-tl--property 'toot-json)))) (url (mastodon-http--api (format "statuses/%s" id)))) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response - (lambda () - (message "Toot deleted! There may be a delay before it disappears from your profile.")))))) + (when (y-or-n-p (format "Delete this toot? ")) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (message "Toot deleted! There may be a delay before it disappears from your profile."))))))) (defun mastodon-tl--follow-user (user-handle) "Query for user id from current status and follow that user." @@ -816,7 +821,7 @@ webapp" (list (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) - (completing-read "User handle: " + (completing-read "Handle of user to follow: " user-handles nil ; predicate 'confirm)))) @@ -838,7 +843,7 @@ webapp" (list (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) - (completing-read "User handle: " + (completing-read "Handle of user to unfollow: " user-handles nil ; predicate 'confirm)))) @@ -861,7 +866,7 @@ webapp" (list (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) - (completing-read "User handle: " + (completing-read "Handle of user to mute: " user-handles nil ; predicate 'confirm)))) @@ -887,7 +892,7 @@ webapp" (muted-accts (mapcar (lambda (muted) (cdr (assoc 'acct muted))) mutes-json))) - (completing-read "Unmute user: " + (completing-read "Handle of user to unmute: " muted-accts nil ; predicate t)))) @@ -910,7 +915,7 @@ webapp" (list (let ((user-handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json)))) - (completing-read "User handle: " + (completing-read "Handle of user to block: " user-handles nil ; predicate 'confirm)))) @@ -936,7 +941,7 @@ webapp" (blocked-accts (mapcar (lambda (blocked) (cdr (assoc 'acct blocked))) blocks-json))) - (completing-read "Unblock user: " + (completing-read "Handle of user to unblock: " blocked-accts nil ; predicate t)))) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 929ae8c..7cd673b 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -106,7 +106,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "t") #'mastodon-toot) ;; override special mode binding (define-key map (kbd "g") #'undefined) - (define-key map (kbd "D") #'mastodon-tl--delete-toot) + ;; mousebot additions + (define-key map (kbd "d") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) (define-key map (kbd "B") #'mastodon-tl--block-user) -- cgit v1.2.3 From 4fcdb8c4b919b3a708684d1b373208dc67367664 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 10 May 2021 16:24:51 +0200 Subject: add my profile function --- lisp/mastodon-profile.el | 5 +++++ lisp/mastodon-tl.el | 2 +- lisp/mastodon.el | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 2c6b798..254f042 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -190,6 +190,11 @@ following the current profile." (mastodon-profile--make-author-buffer account) (message "Cannot find a user with handle %S" user-handle)))) +(defun mastodon-profile--my-profile () + "Show the profile of the currently signed in user." + (interactive) + (mastodon-profile--show-user (mastodon-auth--get-account-name))) + (defun mastodon-profile--account-field (account field) "Return FIELD from the ACCOUNT. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b44b160..1b3837d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -750,7 +750,7 @@ Move forward (down) the timeline unless BACKWARD is non-nil." (goto-char (point-max)) (mastodon-tl--property 'toot-id t))) -(defun mastodon-tl--as-string(numeric) +(defun mastodon-tl--as-string (numeric) "Convert NUMERIC to string." (cond ((numberp numeric) (number-to-string numeric)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 7cd673b..e338793 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -114,6 +114,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-B") #'mastodon-tl--unblock-user) (define-key map (kbd "M") #'mastodon-tl--mute-user) (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) + (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 1ffe400fd4e01400fee143bf9cf6a5c22be17b3f Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 11 May 2021 10:00:08 +0200 Subject: add basic search functions --- lisp/mastodon-search.el | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ lisp/mastodon-tl.el | 5 +- lisp/mastodon.el | 2 + 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 lisp/mastodon-search.el (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el new file mode 100644 index 0000000..4cb4477 --- /dev/null +++ b/lisp/mastodon-search.el @@ -0,0 +1,145 @@ +;;; mastodon-search.el --- serach functions for mastodon.el -*- lexical-binding: t -*- + +;; search functions: + +;; autoloads? + +;; mastodon-tl--as-string +;; mastodon-tl--set-face +;; mastodon-tl--render-text +;; mastodon-tl--toot +;; mastodon-http--get-json + +;; mastodon-instance-url + +;; code + +(defun mastodon-search--search-query (query) + "Prompt for a search QUERY and return accounts, statuses, and hashtags." + (interactive "sSearch mastodon for: ") + (let* ((url (format "%s/api/v2/search" mastodon-instance-url)) + (buffer (format "*mastodon-search-%s*" query)) + (response (mastodon-http--get-search-json url query)) + (accts (cdr (assoc 'accounts response))) + (tags (cdr (assoc 'hashtags response))) + (statuses (cdr (assoc 'statuses response))) + (user-ids (mapcar #'mastodon-search--get-user-info + accts)) ; returns a list of three-item lists + (tags-list (mapcar #'mastodon-search--get-hashtag-info + tags)) + (status-list (mapcar #'mastodon-search--get-status-info + statuses)) + (status-ids-list (mapcar 'mastodon-search--get-id-from-status + statuses)) + (toots-list-json (mapcar #'mastodon-search--fetch-full-status-from-id + status-ids-list))) + (with-current-buffer (get-buffer-create buffer) + (switch-to-buffer buffer) + (erase-buffer) + (mastodon-mode) + (setq-local inhibit-read-only t) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " USERS" "\n" + " ------------\n") + 'success)) + (mapcar (lambda (el) + (dolist (item el) + (insert (mastodon-tl--render-text item nil) "")) + (insert "----\n\n")) + ;; (insert (mastodon-tl--render-text (car el) nil) + ;; " : " + ;; (mastodon-tl--render-text (car (cdr el)) nil) + ;; " : " + ;; (mastodon-tl--render-text (car (cdr (cdr el))) nil) + ;; "\n")) + user-ids) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " HASHTAGS" "\n" + " ------------\n") + 'success)) + (mapcar (lambda (el) + (dolist (item el) + (insert (mastodon-tl--render-text item nil) "")) + (insert "----\n\n")) + ;; (seq-do 'insert el)) + ;; (insert (mastodon-tl--render-text (car el) nil) + ;; " : " + ;; (mastodon-tl--render-text (car (cdr el)) nil) + ;; "\n")) + tags-list) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " STATUSES" "\n" + " ------------\n") + 'success)) + (mapcar 'mastodon-tl--toot toots-list-json) + (goto-char (point-min)) + ))) + +(defun mastodon-search--get-user-info (account) + "Get user handle, display name and account URL from ACCOUNT." + (list (cdr (assoc 'display_name account)) + (cdr (assoc 'acct account)) + (cdr (assoc 'url account)))) + +(defun mastodon-search--get-hashtag-info (tag) + "Get hashtag name and URL from TAG." + (list (cdr (assoc 'name tag)) + (cdr (assoc 'url tag)))) + +(defun mastodon-search--get-status-info (status) + "Get ID, timestamp, content, and spoiler from STATUS." + (list (cdr (assoc 'id status)) + (cdr (assoc 'created_at status)) + (cdr (assoc 'spoiler_text status)) + (cdr (assoc 'content status)))) + +(defun mastodon-search--get-id-from-status (status) + "Fetch the id from a STATUS returned by a search call to the server. + +We use this to fetch the complete status from the server." + (cdr (assoc 'id status))) + +(defun mastodon-search--fetch-full-status-from-id (id) + "Fetch the full status with id ID from the server. + +This allows us to access the full account etc. details and to render them properly." + (let* ((url (concat mastodon-instance-url "/api/v1/statuses/" (mastodon-tl--as-string id))) + (json (mastodon-http--get-json url))) + json)) + +;; http functions for search: + +(defun mastodon-http--process-json-search () + (goto-char (point-min)) + (re-search-forward "^$" nil 'move) + (let ((json-string + (decode-coding-string + (buffer-substring-no-properties (point) (point-max)) + 'utf-8))) + (kill-buffer) + (json-read-from-string json-string))) + +(defun mastodon-http--get-search-json (url query) + "Make GET request to URL. Return JSON response" + (let ((buffer (mastodon-http--get-search url query))) + (with-current-buffer buffer + (mastodon-http--process-json-search)))) + +(defun mastodon-http--get-search (base-url query) + "Make GET request to URL. + +Pass response buffer to CALLBACK function." + (let ((url-request-method "GET") + (url (concat base-url "?q=" (url-hexify-string query))) + (url-request-extra-headers + `(("Authorization" . ,(concat "Bearer " + (mastodon-auth--access-token)))))) + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + +(provide 'mastodon-search) +;; mastodon-search.el ends here diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1b3837d..9090339 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -42,10 +42,11 @@ (autoload 'mastodon-profile--account-from-id "mastodon.el-profile.el") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile.el") (autoload 'mastodon-profile--search-account-by-handle "mastodon.el-profile.el") -;; try an autoload for new follow fun +;; mousebot adds (autoload 'mastodon-profile--toot-json "mastodon-profile.el") (autoload 'mastodon-profile--account-field "mastodon-profile.el") (autoload 'mastodon-profile--extract-users-handles "mastodon-profile.el") + (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; need to declare it since Emacs24 didn't have this @@ -656,7 +657,7 @@ it is `mastodon-tl--byline-boosted'" (when mastodon-tl--display-media-p (mastodon-media--inline-images start-pos (point))))) -(defun mastodon-tl--toot(toot) +(defun mastodon-tl--toot (toot) "Formats TOOT and insertes it into the buffer." (mastodon-tl--insert-status toot diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e338793..512b345 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -53,6 +53,7 @@ (autoload 'mastodon-toot--toggle-boost "mastodon-toot") (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") +(autoload 'mastodon-search--search-query "mastodon-search") (defgroup mastodon nil "Interface with Mastodon." @@ -115,6 +116,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "M") #'mastodon-tl--mute-user) (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) + (define-key map (kbd "S") #'mastodon-search--search-query) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From e53bf8fe17bdf3d750f07075cb9d59ca7f5e97ee Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 13 May 2021 20:25:41 +0200 Subject: copy url of toot at point --- lisp/mastodon-tl.el | 3 +-- lisp/mastodon.el | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 81c2d4b..de64e1b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -812,8 +812,7 @@ webapp" "Copy URL of toot at point." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - (boosted (mastodon-tl--field 'reblog toot)) - (url (if boosted + (url (if (mastodon-tl--field 'reblog toot) (cdr (assoc 'url (cdr (assoc 'reblog toot)))) (cdr (assoc 'url toot))))) (kill-new url) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 512b345..accbed8 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -54,6 +54,7 @@ (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") (autoload 'mastodon-search--search-query "mastodon-search") +(autoload 'mastodon-tl--copy-toot-url "mastodon-tl") (defgroup mastodon nil "Interface with Mastodon." @@ -117,6 +118,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) + (define-key map (kbd "C") #'mastodon-tl--copy-toot-url) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 5ea4b715d022e5a4ccff47d4874ee171aa7af522 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 14 May 2021 12:00:25 +0200 Subject: display "follows you" and "followed by you" on user profiles --- lisp/mastodon-http.el | 4 +--- lisp/mastodon-profile.el | 45 ++++++++++++++++++++++++++++++++++++++------- lisp/mastodon.el | 3 ++- 3 files changed, 41 insertions(+), 11 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f26d808..3fe47c9 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -106,9 +106,7 @@ Pass response buffer to CALLBACK function." (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) (defun mastodon-http--delete (url) - "Make DELETE request to URL. - -Pass response buffer to CALLBACK function." + "Make DELETE request to URL." (let ((url-request-method "DELETE") (url-request-extra-headers `(("Authorization" . ,(concat "Bearer " diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index bd325c1..e0e209d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -100,6 +100,15 @@ following the current profile." #'mastodon-profile--add-author-bylines) (error "Not in a mastodon profile"))) +(defun mastodon-profile--relationships-get (id) + "Fetch info about logged in user's relationship to user with id ID." + (interactive) + (let* ((their-id id) + (url (mastodon-http--api (format + "accounts/relationships?id[]=%s" + their-id)))) + (mastodon-http--get-json url))) + (defun mastodon-profile--make-profile-buffer-for (account endpoint-type update-function) (let* ((id (mastodon-profile--account-field account 'id)) (url (mastodon-http--api (format "accounts/%s/%s" @@ -113,9 +122,20 @@ following the current profile." (buffer (concat "*mastodon-" acct "-" endpoint-type "*")) (note (mastodon-profile--account-field account 'note)) (id (mastodon-profile--account-field account 'id)) - (fol_count (mastodon-tl--as-string (mastodon-profile--account-field account 'followers_count))) - (folling_count (mastodon-tl--as-string (mastodon-profile--account-field account 'following_count))) - (toots_count (mastodon-tl--as-string (mastodon-profile--account-field account 'statuses_count)))) + (followers-count (mastodon-tl--as-string + (mastodon-profile--account-field + account 'followers_count))) + (following-count (mastodon-tl--as-string + (mastodon-profile--account-field + account 'following_count))) + (toots-count (mastodon-tl--as-string + (mastodon-profile--account-field + account 'statuses_count))) + (followed-by-you (cdr (assoc 'following + (aref (mastodon-profile--relationships-get id) 0)))) + (follows-you (cdr (assoc 'followed_by + (aref (mastodon-profile--relationships-get id) 0)))) + (followsp (or (equal follows-you 't) (equal followed-by-you 't)))) (with-output-to-temp-buffer buffer (switch-to-buffer buffer) (mastodon-mode) @@ -147,11 +167,20 @@ following the current profile." (mastodon-tl--render-text note nil) (mastodon-tl--set-face (concat " ------------\n" - " TOOTS: " toots_count " | " - "FOLLOWERS: " fol_count " | " - "FOLLOWING: " folling_count "\n" + " TOOTS: " toots-count " | " + "FOLLOWERS: " followers-count " | " + "FOLLOWING: " following-count "\n" " ------------\n\n") 'success) + (if followsp + (mastodon-tl--set-face + (concat (if (equal follows-you 't) + "FOLLOWS YOU | ") + (if (equal followed-by-you 't) + "FOLLOWED BY YOU | ") + "\n\n") + 'success) + "") ; if no followsp we still need str-or-char-p for insert (mastodon-tl--set-face (concat " ------------\n" endpoint-name "\n" @@ -163,7 +192,9 @@ following the current profile." (mastodon-tl--goto-next-toot))) (defun mastodon-profile--get-toot-author () - "Opens authors profile of toot under point." + "Open profile of author of toot under point. + +If toot is a boost, opens the profile of the booster." (interactive) (mastodon-profile--make-author-buffer (cdr (assoc 'account (mastodon-profile--toot-json))))) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index accbed8..6862e52 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -153,7 +153,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." (interactive) - (mastodon-tl--get-home-timeline)) + (mastodon-tl--get-home-timeline) + (message "Loading Mastodon account %s on %s..." (mastodon-auth--get-account-name) mastodon-instance-url)) ;;;###autoload (defun mastodon-toot (&optional user reply-to-id) -- cgit v1.2.3 From a52f25ce26cd6a9fe8d88d893eb8500ad1292677 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sun, 16 May 2021 15:26:35 +0200 Subject: add new functions to discover menu, and autoloads. --- lisp/mastodon-discover.el | 30 ++++++++++++++++++++++-------- lisp/mastodon-tl.el | 1 + lisp/mastodon.el | 9 +++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index a99ddc2..862eb8f 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -44,25 +44,39 @@ (description "Mastodon feed viewer") (actions ("Toots" - ("A" "Author" mastodon-profile--get-toot-author) + ("A" "View profile of author" mastodon-profile--get-toot-author) ("b" "Boost" mastodon-toot--boost) - ("c" "Toggle content" mastodon-tl--toggle-spoiler-text-in-toot) ("f" "Favourite" mastodon-toot--favourite) + ("c" "Toggle hidden text" mastodon-tl--toggle-spoiler-text-in-toot) ("n" "Next" mastodon-tl--goto-next-toot) ("p" "Prev" mastodon-tl--goto-prev-toot) - ("t" "Toot" mastodon-toot) + ("t" "New toot" mastodon-toot) ("r" "Reply" mastodon-toot--reply) - ("u" "Update" mastodon-tl--update) - ("P" "Users" mastodon-profile--show-user) - ("T" "Thread" mastodon-tl--thread)) + ("C" "Copy toot URL" mastodon-tl--copy-toot-url) + ("d" "Delete (your) toot" mastodon-tl--delete-toot) + ("P" "View user profile" mastodon-profile--show-user) + ("T" "View thread" mastodon-tl--thread)) ("Timelines" ("#" "Tag" mastodon-tl--get-tag-timeline) ("F" "Federated" mastodon-tl--get-federated-timeline) ("H" "Home" mastodon-tl--get-home-timeline) ("L" "Local" mastodon-tl--get-local-timeline) - ("N" "Notifications" mastodon-notifications--get)) + ("N" "Notifications" mastodon-notifications--get) + ("u" "Update timeline" mastodon-tl--update) + ("S" "Search" mastodon-search--search-query) + ("C-S-P" "Jump to my profile" mastodon-profile--my-profile)) + ("Users" + ("W" "Follow" mastodon-tl--follow-user) + ("C-S-W" "Unfollow" mastodon-tl--unfollow-user) + ("M" "Mute" mastodon-tl--mute-user) + ("C-S-M" "Unmute" mastodon-tl--unmute-user) + ("B" "Block" mastodon-tl--block-user) + ("C-S-B" "Unblock" mastodon-tl--unblock-user)) + ("Profile view" + ("o" "Show following" mastodon-profile--open-following) + ("O" "Show followers" mastodon-profile--open-followers)) ("Quit" - ("q" "Quit mastodon buffer. Leave window open." kill-this-buffer) + ("q" "Quit mastodon and bury buffer." kill-this-buffer) ("Q" "Quit mastodon buffer and kill window." kill-buffer-and-window))))))) (provide 'mastodon-discover) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 435938e..2c9c080 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -46,6 +46,7 @@ (autoload 'mastodon-profile--toot-json "mastodon-profile.el") (autoload 'mastodon-profile--account-field "mastodon-profile.el") (autoload 'mastodon-profile--extract-users-handles "mastodon-profile.el") +(autoload 'mastodon-profile--my-profile "mastodon-profile.el") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6862e52..878ddbf 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -53,8 +53,17 @@ (autoload 'mastodon-toot--toggle-boost "mastodon-toot") (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") +(autoload 'mastodon-tl--block-user "mastodon-tl") +(autoload 'mastodon-tl--unblock-user "mastodon-tl") +(autoload 'mastodon-tl--mute-user "mastodon-tl") +(autoload 'mastodon-tl--unmute-user "mastodon-tl") +(autoload 'mastodon-tl--delete-toot "mastodon-tl") +(autoload 'mastodon-tl--follow-user "mastodon-tl") +(autoload 'mastodon-tl--unfollow-user "mastodon-tl") +(autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") (autoload 'mastodon-tl--copy-toot-url "mastodon-tl") +(autoload 'mastodon-auth--get-account-name "mastodon-auth") (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From 7b23d4d03aee72e54484034bc91bd51e909ead32 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 24 May 2021 11:04:47 +0200 Subject: pin/unpin toot funs, delete toot now tests if toot is own. --- lisp/mastodon-tl.el | 59 +++++++++++++++++++++++++++++++++++++++++++++-------- lisp/mastodon.el | 2 ++ 2 files changed, 53 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index adb834a..85f5641 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -794,7 +794,6 @@ webapp" 'mastodon-tl--thread* id toot buffer))) (defun mastodon-tl--thread* (context id toot buffer) - ;; (interactive) (when (member (cdr (assoc 'type toot)) '("reblog" "favourite")) (setq toot (cdr (assoc 'status toot)))) (if (> (+ (length (cdr (assoc 'ancestors context))) @@ -825,17 +824,61 @@ webapp" (kill-new url) (message "Toot URL copied to the clipboard."))) +;; TODO redraw buffer on success? (defun mastodon-tl--delete-toot () "Delete user's toot at point synchronously." (interactive) - (let* ((id (mastodon-tl--as-string (mastodon-tl--toot-id - (mastodon-tl--property 'toot-json)))) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) (url (mastodon-http--api (format "statuses/%s" id)))) - (when (y-or-n-p (format "Delete this toot? ")) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response - (lambda () - (message "Toot deleted! There may be a delay before it disappears from your profile."))))))) + (if (or (cdr (assoc 'reblog toot)) + (not (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (message "You can only delete your own toots.") + (if (y-or-n-p (format "Delete this toot? ")) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (message "Toot deleted!")))))))) + +;; TODO: rewrite pin/unpin as toggle functions +(defun mastodon-tl--pin-toot () + "Pin user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s/pin" id))) + (pinnable-p (and + (not (cdr (assoc 'reblog toot))) + (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (pinned-p (equal (cdr (assoc 'pinned toot)) t))) + (if (not pinnable-p) + (message "You can only pin your own toots.") + (if pinned-p + (message "Looks like toot is already pinned.") + (if (y-or-n-p (format "Pin this toot to your profile? ")) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "Toot pinned!"))))))))) + +(defun mastodon-tl--unpin-toot () + "Unpin user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s/unpin" id))) + (pinned-p (equal (cdr (assoc 'pinned toot)) t))) + (if (not pinned-p) + (message "No pinned toot to unpin here.") + (if (y-or-n-p (format "Unpin this toot? ")) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "Toot unpinned!")))))))) (defun mastodon-tl--follow-user (user-handle) "Query for USER-HANDLE from current status and follow that user." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 878ddbf..2d51120 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -128,6 +128,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) (define-key map (kbd "C") #'mastodon-tl--copy-toot-url) + (define-key map (kbd "i") #'mastodon-tl--pin-toot) + (define-key map (kbd "I") #'mastodon-tl--unpin-toot) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From d8121e7447bf30767cd91523e12429a7a934a2c9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 25 May 2021 11:22:26 +0200 Subject: pin/unpin now toggle fun, and moved copy/delete to mastodon-toot. --- lisp/mastodon-discover.el | 5 ++-- lisp/mastodon-tl.el | 66 ----------------------------------------------- lisp/mastodon-toot.el | 51 ++++++++++++++++++++++++++++++++++++ lisp/mastodon.el | 12 ++++----- 4 files changed, 60 insertions(+), 74 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 9e1cbad..55623f7 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -54,8 +54,9 @@ ("S-TAB" "Prev link item" mastodon-tl--previous-tab-item) ("t" "New toot" mastodon-toot) ("r" "Reply" mastodon-toot--reply) - ("C" "Copy toot URL" mastodon-tl--copy-toot-url) - ("d" "Delete (your) toot" mastodon-tl--delete-toot) + ("C" "Copy toot URL" mastodon-toot--copy-toot-url) + ("d" "Delete (your) toot" mastodon-toot--delete-toot) + ("i" "Pin/Unpin (your) toot" mastodon-toot--pin-toot-toggle) ("P" "View user profile" mastodon-profile--show-user) ("T" "View thread" mastodon-tl--thread)) ("Timelines" diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 85f5641..5bc07e0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -814,72 +814,6 @@ webapp" (cdr (assoc 'descendants context)))))) (message "No Thread!")));) -(defun mastodon-tl--copy-toot-url () - "Copy URL of toot at point." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (url (if (mastodon-tl--field 'reblog toot) - (cdr (assoc 'url (cdr (assoc 'reblog toot)))) - (cdr (assoc 'url toot))))) - (kill-new url) - (message "Toot URL copied to the clipboard."))) - -;; TODO redraw buffer on success? -(defun mastodon-tl--delete-toot () - "Delete user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s" id)))) - (if (or (cdr (assoc 'reblog toot)) - (not (equal (cdr (assoc 'acct - (cdr (assoc 'account toot)))) - (mastodon-auth--user-acct)))) - (message "You can only delete your own toots.") - (if (y-or-n-p (format "Delete this toot? ")) - (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response - (lambda () - (message "Toot deleted!")))))))) - -;; TODO: rewrite pin/unpin as toggle functions -(defun mastodon-tl--pin-toot () - "Pin user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/pin" id))) - (pinnable-p (and - (not (cdr (assoc 'reblog toot))) - (equal (cdr (assoc 'acct - (cdr (assoc 'account toot)))) - (mastodon-auth--user-acct)))) - (pinned-p (equal (cdr (assoc 'pinned toot)) t))) - (if (not pinnable-p) - (message "You can only pin your own toots.") - (if pinned-p - (message "Looks like toot is already pinned.") - (if (y-or-n-p (format "Pin this toot to your profile? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot pinned!"))))))))) - -(defun mastodon-tl--unpin-toot () - "Unpin user's toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/unpin" id))) - (pinned-p (equal (cdr (assoc 'pinned toot)) t))) - (if (not pinned-p) - (message "No pinned toot to unpin here.") - (if (y-or-n-p (format "Unpin this toot? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot unpinned!")))))))) - (defun mastodon-tl--follow-user (user-handle) "Query for USER-HANDLE from current status and follow that user." (interactive diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a11bfa0..6f82ded 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -35,6 +35,7 @@ (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") (autoload 'mastodon-http--triage "mastodon-http") +(autoload 'mastodon-http--delete "mastodon-http") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-tl--clean-tabs-and-nl "mastodon-tl") (autoload 'mastodon-tl--field "mastodon-tl") @@ -182,6 +183,56 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (message (format "%s #%s" action id)))) (message "Nothing to favorite here?!?")))) +(defun mastodon-toot--pin-toot-toggle () + "Pin or unpin user's toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s/pin" id))) + (pinnable-p (and + (not (cdr (assoc 'reblog toot))) + (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (pinned-p (equal (cdr (assoc 'pinned toot)) t)) + (action (if pinned-p "unpin" "pin")) + (msg (if pinned-p "unpinned" "pinned")) + (msg-y-or-n (if pinned-p "Unpin" "Pin"))) + (if (not pinnable-p) + (message "You can only pin your own toots.") + (if (y-or-n-p (format "%s this toot? " msg-y-or-n)) + (mastodon-toot--action action + (lambda () + (message "Toot %s!" msg))))))) + +(defun mastodon-toot--copy-toot-url () + "Copy URL of toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (url (if (mastodon-tl--field 'reblog toot) + (cdr (assoc 'url (cdr (assoc 'reblog toot)))) + (cdr (assoc 'url toot))))) + (kill-new url) + (message "Toot URL copied to the clipboard."))) + +;; TODO redraw buffer on success? +(defun mastodon-toot--delete-toot () + "Delete user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s" id)))) + (if (or (cdr (assoc 'reblog toot)) + (not (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (message "You can only delete your own toots.") + (if (y-or-n-p (format "Delete this toot? ")) + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (message "Toot deleted!")))))))) + (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." (kill-buffer-and-window)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2d51120..f6635c0 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -57,12 +57,13 @@ (autoload 'mastodon-tl--unblock-user "mastodon-tl") (autoload 'mastodon-tl--mute-user "mastodon-tl") (autoload 'mastodon-tl--unmute-user "mastodon-tl") -(autoload 'mastodon-tl--delete-toot "mastodon-tl") (autoload 'mastodon-tl--follow-user "mastodon-tl") (autoload 'mastodon-tl--unfollow-user "mastodon-tl") (autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") -(autoload 'mastodon-tl--copy-toot-url "mastodon-tl") +(autoload 'mastodon-toot--delete-toot "mastodon-toot") +(autoload 'mastodon-toot--copy-toot-url "mastodon-toot") +(autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") (defgroup mastodon nil @@ -118,7 +119,6 @@ Use. e.g. \"%c\" for your locale's date and time format." ;; override special mode binding (define-key map (kbd "g") #'undefined) ;; mousebot additions - (define-key map (kbd "d") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) (define-key map (kbd "B") #'mastodon-tl--block-user) @@ -127,9 +127,9 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) - (define-key map (kbd "C") #'mastodon-tl--copy-toot-url) - (define-key map (kbd "i") #'mastodon-tl--pin-toot) - (define-key map (kbd "I") #'mastodon-tl--unpin-toot) + (define-key map (kbd "d") #'mastodon-toot--delete-toot) + (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) + (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From cc1570df86c7a4f43684fd7caf14cf298301c655 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 27 May 2021 12:43:21 +0200 Subject: add request and seq as dependencies, flycheck cleanups, and move http search funs into http.el --- Cask | 2 ++ lisp/mastodon-http.el | 43 +++++++++++++++++++++++++++++++++++++++---- lisp/mastodon-profile.el | 3 ++- lisp/mastodon-search.el | 34 ++-------------------------------- lisp/mastodon.el | 3 ++- 5 files changed, 47 insertions(+), 38 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/Cask b/Cask index 599efa2..ebb7669 100644 --- a/Cask +++ b/Cask @@ -4,6 +4,8 @@ (package-file "lisp/mastodon.el") (files "lisp/*.el") +(depends-on "seq") + (development (depends-on "ert-runner") (depends-on "el-mock") diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 8a7499f..3b31668 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -33,7 +33,12 @@ (require 'request) ; for attachments upload (defvar mastodon-instance-url) +(defvar mastodon-toot--media-attachment-ids) +(defvar mastodon-toot--media-attachment-filenames) + (autoload 'mastodon-auth--access-token "mastodon-auth") +(autoload 'mastodon-toot--update-status-fields "mastodon-toot") + (defvar mastodon-http--api-version "v1") @@ -132,6 +137,37 @@ Pass response buffer to CALLBACK function." (kill-buffer) (json-read-from-string json-string))) +;; http functions for search: +(defun mastodon-http--process-json-search () + "Process JSON returned by a search query to the server." + (goto-char (point-min)) + (re-search-forward "^$" nil 'move) + (let ((json-string + (decode-coding-string + (buffer-substring-no-properties (point) (point-max)) + 'utf-8))) + (kill-buffer) + (json-read-from-string json-string))) + +(defun mastodon-http--get-search-json (url query) + "Make GET request to URL, searching for QUERY and return JSON response." + (let ((buffer (mastodon-http--get-search url query))) + (with-current-buffer buffer + (mastodon-http--process-json-search)))) + +(defun mastodon-http--get-search (base-url query) + "Make GET request to BASE-URL, searching for QUERY. + +Pass response buffer to CALLBACK function." + (let ((url-request-method "GET") + (url (concat base-url "?q=" (url-hexify-string query))) + (url-request-extra-headers + `(("Authorization" . ,(concat "Bearer " + (mastodon-auth--access-token)))))) + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + ;; Asynchronous functions (defun mastodon-http--get-async (url &optional callback &rest cbargs) @@ -173,7 +209,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." ;; TODO: test for curl first? (defun mastodon-http--post-media-attachment (url filename caption) - "Make a POST request to upload file FILENAME with CAPTION to the server's media URL. + "Make POST request to upload FILENAME with CAPTION to the server's media URL. The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' is set to the id(s) of the item uploaded, `mastodon-toot--media-attachments' is set to t, and `mastodon-toot--update-status-fields' is run." (let* ((file (file-name-nondirectory filename)) @@ -204,8 +240,7 @@ The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' (mastodon-toot--update-status-fields))))) :error (cl-function (lambda (&key error-thrown &allow-other-keys) - (message "Got error: %s" error-thrown))) - ))) + (message "Got error: %s" error-thrown)))))) (pcase (request-response-status-code response) (200 (request-response-data response)) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 9d4793c..e007343 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.7.2 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -49,6 +49,7 @@ (autoload 'mastodon-tl--timeline "mastodon-tl.el") (autoload 'mastodon-tl--as-string "mastodon-tl.el") (autoload 'mastodon-tl--toot-id "mastodon-tl") +(autoload 'mastodon-tl--toot "mastodon-tl") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 408b887..90158a1 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,4 +1,4 @@ -;;; mastodon-search.el --- search functions for mastodon.el -*- lexical-binding: t -*- +;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen , martyhiatt @@ -37,6 +37,7 @@ (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-auth--access-token "mastodon-auth") +(autoload 'mastodon-http--get-search-json "mastodon-http") (defvar mastodon-instance-url) (defvar mastodon-tl--link-keymap) @@ -143,36 +144,5 @@ This allows us to access the full account etc. details and to render them proper (json (mastodon-http--get-json url))) json)) -;; http functions for search: -(defun mastodon-http--process-json-search () - "Process JSON returned by a search query to the server." - (goto-char (point-min)) - (re-search-forward "^$" nil 'move) - (let ((json-string - (decode-coding-string - (buffer-substring-no-properties (point) (point-max)) - 'utf-8))) - (kill-buffer) - (json-read-from-string json-string))) - -(defun mastodon-http--get-search-json (url query) - "Make GET request to URL, searching for QUERY and return JSON response." - (let ((buffer (mastodon-http--get-search url query))) - (with-current-buffer buffer - (mastodon-http--process-json-search)))) - -(defun mastodon-http--get-search (base-url query) - "Make GET request to BASE-URL, searching for QUERY. - -Pass response buffer to CALLBACK function." - (let ((url-request-method "GET") - (url (concat base-url "?q=" (url-hexify-string query))) - (url-request-extra-headers - `(("Authorization" . ,(concat "Bearer " - (mastodon-auth--access-token)))))) - (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) - (url-retrieve-synchronously url) - (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) - (provide 'mastodon-search) ;;; mastodon-search.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f6635c0..37876f6 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (request "0.2.0") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -32,6 +32,7 @@ ;;; Code: (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") +(declare-function request "request") (autoload 'special-mode "simple") (autoload 'mastodon-tl--get-federated-timeline "mastodon-tl") (autoload 'mastodon-tl--get-home-timeline "mastodon-tl") -- cgit v1.2.3 From 1ff6d8ef35f83ada24fafd3656dde0a1da57922a Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 31 May 2021 09:58:01 +0200 Subject: bump masto version, bump emacs version to 25.1, dependency in readme --- README.org | 3 +++ lisp/mastodon-auth--test.el | 4 ++-- lisp/mastodon-auth.el | 4 ++-- lisp/mastodon-client.el | 4 ++-- lisp/mastodon-discover.el | 4 ++-- lisp/mastodon-http.el | 4 ++-- lisp/mastodon-inspect.el | 4 ++-- 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.el | 4 ++-- 14 files changed, 29 insertions(+), 26 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index 214d3d0..d06c93a 100644 --- a/README.org +++ b/README.org @@ -25,6 +25,9 @@ This updated version is not on MELPA, to use it you need to clone and require it I did this for my own use and to learn more Elisp. If the code is terrible, feel free to improve or replace it. +** dependency: +This version depends on the library =request= (for uploading attachments). You can install it from melpa. + ** bugs As it stands the client still has some bugs. In particular, when composing a toot, you may have to hit =C-g= before sending your toot. You may also see a related error when you try to add a media attachment. You should be able to run the command again and it should work. See the issues on the original repo. diff --git a/lisp/mastodon-auth--test.el b/lisp/mastodon-auth--test.el index 8082536..b8705f5 100644 --- a/lisp/mastodon-auth--test.el +++ b/lisp/mastodon-auth--test.el @@ -3,9 +3,9 @@ ;; Copyright (C) 2020 Ian Eure ;; Author: Ian Eure -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index cfe89b5..3c61848 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index da70dea..90f1375 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 1f063b3..2387feb 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -2,8 +2,8 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Version: 0.9.1 +;; Package-Requires: ((emacs "25.1")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 462b5c6..e85429f 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -2,8 +2,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4") (request "0.2.0")) +;; Version: 0.9.1 +;; Package-Requires: ((emacs "25.1") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 44b9344..c5a8d5d 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -2,8 +2,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Version: 0.9.1 +;; Package-Requires: ((emacs "25.1")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index da99007..6c17ae0 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index d6fa78f..d40815a 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.7.2 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 17b480d..bf1a3a9 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -2,8 +2,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.7.2 -;; Package-Requires: ((emacs "24.4") (seq "1.8")) +;; Version: 0.9.1 +;; Package-Requires: ((emacs "25.1") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 90158a1..5e8253f 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen , martyhiatt -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7b0afeb..ecaeff4 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8328bb9..a0f886c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 +;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "25.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 37876f6..b703b30 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -2,8 +2,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4") (request "0.2.0") (seq "1.8")) +;; Version: 0.9.1 +;; Package-Requires: ((emacs "25.1") (request "0.2.0") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3 From 35d7133bfc5060e76dfe91526da399ddb8559600 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 31 May 2021 11:51:23 +0200 Subject: foll reqs/faves bindings global, autoloads and declarations, readme --- README.org | 62 +++++++++++++++++++++++++++++++++--------------- lisp/mastodon-auth.el | 1 + lisp/mastodon-media.el | 7 +++--- lisp/mastodon-profile.el | 10 ++++---- lisp/mastodon-tl.el | 16 ++++++------- lisp/mastodon.el | 2 ++ 6 files changed, 64 insertions(+), 34 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index d06c93a..af2c46c 100644 --- a/README.org +++ b/README.org @@ -4,33 +4,57 @@ This is a fork of of the great but seemingly dormant https://github.com/jdenen/m It adds the following features: -| | display profile metadata fields | -| =i= | (un)pin toots, display pinned toots on profiles, | -| | display relationship (follows you/followed by you) on profiles | -| | links and tags in profiles are tab stops like in posts | -| =S= | search (posts, users, tags) (improved!) | -| =C-c C-a= (=C-c C-n=) | media uploads (including sensitive/nsfw flag) | -| =RET= | images are links to the full-sized image, can be zoomed | -| | mention booster in replies by default | -| =W=, =M=, =B= | (un)follow, (un)mute, (un)block users | -| =R=, =a=, =r= | view/accept/reject follow requests | -| =v= | view your favorited toots | -| =S-M-P= | jump to your profile | -| =C= | copy toot url | -| =d= | delete your toot | +| Profiles: | | +| | display profile metadata fields | +| | display relationship (follows you/followed by you) on profiles | +| | display toots/follows/followers counts on profiles | +| | links and tags in profiles are tab stops like in posts | +| =R=, =a=, =r= | view/accept/reject follow requests | +| =v= | view your favorited toots | +| =i= | (un)pin toots, display pinned toots on profiles | +| =S-C-P= | jump to your profile | +| Timelines: | | +| =W=, =M=, =B= | (un)follow, (un)mute, (un)block users | +| | images are links to the full image, can be zoomed/rotated/saved (see their keymap) | +| =C= | copy url of toot at point | +| =d= | delete your toot at point | +| | display polls (very basic for now) | +| Toots: | | +| =C-c C-a= (=C-c C-n=) | media uploads (and sensitive/nsfw flag) | +| | mention booster in replies by default | +| Search: | | +| =S= | search (posts, users, tags) (improved! but still pretty basic!) | It also makes some small cosmetic changes to make timelines easier to read, and makes some functions asynchronous, based on https://github.com/ieure/mastodon.el. This updated version is not on MELPA, to use it you need to clone and require it as per the installation instructions below. -I did this for my own use and to learn more Elisp. If the code is terrible, feel free to improve or replace it. +The minimum Emacs version is now 25.1. But if you are running an older version it shouldn't be very hard to get it working. -** dependency: -This version depends on the library =request= (for uploading attachments). You can install it from melpa. +I did this for my own use and to learn more Elisp. If the code is terrible, feel free to improve or replace it. It surely still contains errors, I'm only weeding them out as I find them. -** bugs +** NB: dependency: -As it stands the client still has some bugs. In particular, when composing a toot, you may have to hit =C-g= before sending your toot. You may also see a related error when you try to add a media attachment. You should be able to run the command again and it should work. See the issues on the original repo. +This version depends on the library =request= (for uploading attachments). You can install it from MELPA, or https://github.com/tkf/emacs-request. + +** NB: bugs + +As it stands the client still has some bugs. In particular, when composing a toot, hit =C-g= before sending your toot. If you don't, your draft may disappear. You may also see a related error when you try to add a media attachment. You should be able to run the command again and it should work. See the issues on the original repo. + +Some people have also had niggling troubles with initial auth and set-up, but I couldn't reproduce. + +** roadmap-ish + +I might add a few more features if the ones I added turn out to work ok. Possible additions/amendments: + +- voting on polls +- better display of polls +- mention all thread participants in replies +- handle newlines in toots better, for poetry, etc. +- improve async. +- perhaps integrate live timeline updates from https://github.com/alexjgriffith/mastodon-future.el, and add live updates for notifcations and home timeline. + +It looks like 2-factor auth was never completed in the original repo. It's not a priority for me, auth ain't my thing. If you want to hack on it, its on the develop branch in the original repo. ** Original README diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 3c61848..4bd1cce 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -32,6 +32,7 @@ (require 'plstore) (require 'auth-source) (require 'json) +(eval-when-compile (require 'subr-x)) ; for if-let (autoload 'mastodon-client "mastodon-client") (autoload 'mastodon-http--api "mastodon-http") diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 6c17ae0..381d994 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -34,6 +34,8 @@ ;;; Code: (defvar url-show-status) +(defvar mastodon-tl--shr-image-map-replacement) + (defgroup mastodon-media nil "Inline Mastadon media." :prefix "mastodon-media-" @@ -125,7 +127,7 @@ CAQgEIBAAAIBFiNOFMaY6V1tnFhkDQIQCEAgAIEABAKAQAACAQgEIBCAQAACAQgEIBCAQABIXO4e c1y+zhoEIBCAQAAQCEAgAIEABAIQCEAgAIEABAIQCEAgAAgEIBCAQAACAQgEIBCAQAACAQgEAIEA BAIQCEAgAIEABAIsJVH58WqHw8FIgjUIQCAACAQgEIBAAAIBCAQgEIBAAAIBCAQgEAAEAhAIQCBA fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=") - "The PNG data for a generic 200x200 'broken image' view") + "The PNG data for a generic 200x200 'broken image' view.") (defun mastodon-media--process-image-response (status-plist marker image-options region-length) @@ -134,8 +136,7 @@ fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=") STATUS-PLIST is the usual plist of status events as per `url-retrieve'. IMAGE-OPTIONS are the precomputed options to apply to the image. MARKER is the marker to where the response should be visible. -REGION-LENGTH is the length of the region that should be replaced with the image. -" +REGION-LENGTH is the length of the region that should be replaced with the image." (when (marker-buffer marker) ; only if the buffer hasn't been kill in the meantime (let ((url-buffer (current-buffer)) (is-error-response-p (eq :error (car status-plist)))) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index bf1a3a9..84664c0 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -36,6 +36,8 @@ (autoload 'mastodon-http--api "mastodon-http.el") (autoload 'mastodon-http--get-json "mastodon-http.el") +(autoload 'mastodon-http--post "mastodon-http.el") +(autoload 'mastodon-http--triage "mastodon-http.el") (autoload 'mastodon-auth--get-account-name "mastodon-auth.el") (autoload 'mastodon-http--get-json-async "mastodon-http.el") (autoload 'mastodon-media--get-media-link-rendering "mastodon-media.el") @@ -50,6 +52,7 @@ (autoload 'mastodon-tl--as-string "mastodon-tl.el") (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-tl--toot "mastodon-tl") +(autoload 'mastodon-tl--init "mastodon-tl.el") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -70,11 +73,9 @@ extra keybindings." ;; The key bindings :keymap '(((kbd "O") . mastodon-profile--open-followers) ((kbd "o") . mastodon-profile--open-following) - ((kbd "v") . mastodon-profile--view-favourites) - ((kbd "R") . mastodon-profile--view-follow-requests) ((kbd "a") . mastodon-profile--follow-request-accept) ((kbd "r") . mastodon-profile--follow-request-reject)) -:group 'mastodon) + :group 'mastodon) (defun mastodon-profile--toot-json () "Get the next toot-json." @@ -214,7 +215,7 @@ Returns a list of lists." (mastodon-http--get-json url))) (defun mastodon-profile--insert-statuses-pinned (pinned-statuses) - "Insert each of the PINNED_STATUSES for a given account." + "Insert each of the PINNED-STATUSES for a given account." (mapc (lambda (pinned-status) (insert (mastodon-tl--set-face " :pinned: " 'success)) @@ -222,6 +223,7 @@ Returns a list of lists." pinned-statuses)) (defun mastodon-profile--make-profile-buffer-for (account endpoint-type update-function) + "Display profile of ACCOUNT, using ENDPOINT-TYPE and UPDATE-FUNCTION." (let* ((id (mastodon-profile--account-field account 'id)) (url (mastodon-http--api (format "accounts/%s/%s" id endpoint-type))) (acct (mastodon-profile--account-field account 'acct)) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ecaeff4..d90a759 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -39,14 +39,14 @@ (autoload 'mastodon-media--get-media-link-rendering "mastodon-media") (autoload 'mastodon-media--inline-images "mastodon-media") (autoload 'mastodon-mode "mastodon") -(autoload 'mastodon-profile--account-from-id "mastodon.el-profile.el") -(autoload 'mastodon-profile--make-author-buffer "mastodon-profile.el") -(autoload 'mastodon-profile--search-account-by-handle "mastodon.el-profile.el") +(autoload 'mastodon-profile--account-from-id "mastodon-profile") +(autoload 'mastodon-profile--make-author-buffer "mastodon-profile") +(autoload 'mastodon-profile--search-account-by-handle "mastodon-profile") ;; mousebot adds -(autoload 'mastodon-profile--toot-json "mastodon-profile.el") -(autoload 'mastodon-profile--account-field "mastodon-profile.el") -(autoload 'mastodon-profile--extract-users-handles "mastodon-profile.el") -(autoload 'mastodon-profile--my-profile "mastodon-profile.el") +(autoload 'mastodon-profile--toot-json "mastodon-profile") +(autoload 'mastodon-profile--account-field "mastodon-profile") +(autoload 'mastodon-profile--extract-users-handles "mastodon-profile") +(autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-toot--delete-toot "mastodon-toot") (autoload 'mastodon-http--post "mastodon-http") (autoload 'mastodon-http--triage "mastodon-http") @@ -55,7 +55,7 @@ (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) -(defvar shr-use-fonts) ;; need to declare it since Emacs24 didn't have this +(defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this (defgroup mastodon-tl nil "Timelines in Mastodon." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index b703b30..d3477cb 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -131,6 +131,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "d") #'mastodon-toot--delete-toot) (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) + (define-key map (kbd "v") #'mastodon-profile--view-favourites) + (define-key map (kbd "R") #'mastodon-profile--view-follow-requests) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From db26f1b4bc8a62e472ed7c7191a67ddbc2c65c69 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 1 Jun 2021 14:20:28 +0200 Subject: add basic live updates of home/local/federated timelines. the code, mastodon-async.el is taken from https://github.com/alexjgriffith/mastodon-future.el and only slightly modified to make the home stream work. --- README.org | 1 + lisp/mastodon-async.el | 332 +++++++++++++++++++++++++++++++++++++++++++++++++ lisp/mastodon.el | 6 + 3 files changed, 339 insertions(+) create mode 100644 lisp/mastodon-async.el (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index af2c46c..b51644b 100644 --- a/README.org +++ b/README.org @@ -47,6 +47,7 @@ Some people have also had niggling troubles with initial auth and set-up, but I I might add a few more features if the ones I added turn out to work ok. Possible additions/amendments: +- update profile note. - voting on polls - better display of polls - mention all thread participants in replies diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el new file mode 100644 index 0000000..ffd8ab6 --- /dev/null +++ b/lisp/mastodon-async.el @@ -0,0 +1,332 @@ +;;; mastodon-async.el --- Client for Mastodon -*- lexical-binding: t -*- + +;; Copyright (C) 2017 Johnson Denen +;; Author: Johnson Denen +;; Version: 0.7.1 +;; Package-Requires: ((emacs "25.1")) +;; Homepage: https://github.com/jdenen/mastodon.el + +;; This file is not part of GNU Emacs. + +;; This file is part of mastodon.el. + +;; mastodon.el is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; mastodon.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mastodon.el. If not, see . + +;;; Commentary: + +;; Rework sync code so it does not mess up the async-buffer + +;;; Code: + +(require 'json) + +(defgroup mastodon-async nil + "An async module for mastodon streams." + :prefix "mastodon-async-" + :group 'external) + +;;;###autoload +(define-minor-mode mastodon-async-mode + "Async Mastodon." + :lighter " MasA") + +(defvar mastodon-instance-url) + +(defvar mastodon-tl--enable-relative-timestamps) +(defvar mastodon-tl--display-media-p) +(defvar mastodon-tl--buffer-spec) + +(make-variable-buffer-local + (defvar mastodon-async--queue "" ;;"*mastodon-async-queue*" + "The intermediate queue buffer name.")) + +(make-variable-buffer-local + (defvar mastodon-async--buffer "" ;;"*mastodon-async-buffer*" + "User facing output buffer name.")) + +(make-variable-buffer-local + (defvar mastodon-async--http-buffer "" ;;"" + "Buffer variable bound to http output.")) + +(defun mastodon-async--display-http () + "Display the async HTTP input buffer." + (display-buffer mastodon-async--http-buffer)) + +(defun mastodon-async--display-buffer () + "Display the async user facing buffer." + (interactive) + (display-buffer mastodon-async--buffer)) + +(defun mastodon-async--display-queue () + "Display the async queue buffer." + (display-buffer mastodon-async--queue)) + +(defun mastodon-async--stop-http () + "Stop the http processs and close the async and http buffer." + (interactive) + (let ((inhibit-read-only t)) + (stop-process (get-buffer-process mastodon-async--http-buffer)) + (delete-process (get-buffer-process mastodon-async--http-buffer)) + (kill-buffer mastodon-async--http-buffer) + (setq mastodon-async--http-buffer "") + (kill-buffer mastodon-async--queue))) + +;; Need to handle the notification event +;; The output can be passed to notifications +;; need an alternate process-queue-string function +(defun mastodon-async--stream-notifications () + "Open a stream of Home." + (interactive) + (mastodon-async--mastodon + "user" + "home" + "notifications" + 'mastodon-async--process-queue-string)) + +;; this will stream both home AND notifications. +;; need to workout how to filter "user" stream +;; and split it +(defun mastodon-async--stream-home () + "Open a stream of Home." + (interactive) + (mastodon-async--mastodon + "user" + "home" + "home" + 'mastodon-async--process-queue-string)) + +(defun mastodon-async--stream-federated () + "Open a stream of Federated." + (interactive) + (mastodon-async--mastodon + "public" + "public" + "federated" + 'mastodon-async--process-queue-string)) + +(defun mastodon-async--stream-local () + "Open a stream of Local." + (interactive) + ;; Need to add another layer of filtering for this to work + ;; apparently it the local flag does not work + (mastodon-async--mastodon + "public" + "local" ;"public?local=true" + "local" + 'mastodon-async--process-queue-local-string)) + +(defun mastodon-async--mastodon (endpoint timeline name filter) + "Make sure that the previous async process has been closed. + +Then Start an async mastodon stream at ENDPOINT filtering toots +using FILTER. +Argument TIMELINE a specific target, such as federated or home. +Argument NAME the center portion of the buffer name for *mastodon-async-buffer and *mastodon-async-queueu." + (let ((buffer (mastodon-async--start-process + endpoint filter name))) + (with-current-buffer buffer + (mastodon-async--display-buffer) + (goto-char (point-max)) + (goto-char 1)))) + +(defun mastodon-async--get (url callback) + "An async get targeted at URL with a CALLBACK." + (let ((url-request-method "GET") + (url-request-extra-headers + `(("Authorization" . + ,(concat + "Bearer " + (mastodon-auth--access-token)))))) + (url-retrieve url callback))) + +(defun mastodon-async--set-http-buffer (buffer http-buffer) + "Initializes for BUFFER a local variable `mastodon-async--http-buffer'. + +HTTP-BUFFER is the initializing value. Use this funcion if HTTP-BUFFER +is not known when `mastodon-async--setup-buffer' is called." + (with-current-buffer (get-buffer-create buffer) + (setq mastodon-async--http-buffer http-buffer))) + +(defun mastodon-async--set-local-variables (buffer + http-buffer + buffer-name + queue-name) + (with-current-buffer (get-buffer-create buffer) + (let ((value mastodon-instance-url)) + (make-local-variable 'mastodon-instance-url) + (setq-local mastodon-instance-url value)) + (setq mastodon-async--http-buffer http-buffer) + (setq mastodon-async--buffer buffer-name) + (setq mastodon-async--queue queue-name))) + +(defun mastodon-async--setup-http (http-buffer name) + "Adds local variables to HTTP-BUFFER. + +NAME is used to generate the display buffer and the queue." + (let ((queue-name(concat " *mastodon-async-queue-" name "-" + mastodon-instance-url "*")) + (buffer-name(concat "*mastodon-async-display-" name "-" + mastodon-instance-url "*"))) + (mastodon-async--set-local-variables http-buffer http-buffer + buffer-name queue-name))) + +(defun mastodon-async--setup-queue (http-buffer name) + "Sets up the buffer for the async queue." + (let ((queue-name(concat " *mastodon-async-queue-" name "-" + mastodon-instance-url "*")) + (buffer-name(concat "*mastodon-async-display-" name "-" + mastodon-instance-url "*"))) + (mastodon-async--set-local-variables queue-name http-buffer + buffer-name queue-name) + queue-name)) + +(defun mastodon-async--setup-buffer (http-buffer name endpoint) + "Sets up the buffer timeline like `mastodon-tl--init'. + +HTTP-BUFFER the name of the http-buffer, if unknow set to +NAME is the given name of the stream, like local for public?local +ENPOINT is the specific endpoint for a stream and timeline" + (let ((queue-name (concat " *mastodon-async-queue-" name "-" + mastodon-instance-url "*")) + (buffer-name (concat "*mastodon-async-display-" name "-" + mastodon-instance-url "*")) + ;; if user stream, we need "timelines/home" not "timelines/user" + (endpoint (if (equal endpoint "user") "home" endpoint))) + (mastodon-async--set-local-variables buffer-name http-buffer + buffer-name queue-name) + ;; Similar to timeline init. + (with-current-buffer (get-buffer-create buffer-name) + (setq inhibit-read-only t) ; for home timeline? + (make-local-variable 'mastodon-tl--enable-relative-timestamps) + (make-local-variable 'mastodon-tl--display-media-p) + (message (mastodon-http--api (format "timelines/%s" endpoint))) + (mastodon-tl--timeline (mastodon-http--get-json + (mastodon-http--api + (format "timelines/%s" endpoint)))) + (mastodon-mode) + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer-name + endpoint ,(format "timelines/%s" endpoint) + update-function + ,'mastodon-tl--timeline)) + (setq-local mastodon-tl--enable-relative-timestamps nil) + (setq-local mastodon-tl--display-media-p t) + (current-buffer)))) + +(defun mastodon-async--start-process (endpoint filter &optional name) + "Start an async mastodon stream at ENDPOINT. +Filter the toots using FILTER." + (let* ((stream (concat "streaming/" endpoint)) + (async-queue (mastodon-async--setup-queue "" (or name stream))) + (async-buffer (mastodon-async--setup-buffer "" (or name stream) endpoint)) + (http-buffer (mastodon-async--get + (mastodon-http--api stream) + (lambda (status) (message "HTTP SOURCE CLOSED"))))) + (mastodon-async--setup-http http-buffer (or name stream)) + (mastodon-async--set-http-buffer async-buffer http-buffer) + (mastodon-async--set-http-buffer async-queue http-buffer) + (set-process-filter (get-buffer-process http-buffer) + (mastodon-async--http-hook filter)) + http-buffer)) + +(defun mastodon-async--http-hook (filter) + "Return a lambda with a custom FILTER for processing toots." + (let ((filter filter)) + (lambda (proc data) + (with-current-buffer (process-buffer proc) + (let* ((string + (mastodon-async--stream-filter + (mastodon-async--http-layer proc data))) + (queue-string (mastodon-async--cycle-queue string))) + (when queue-string + (mastodon-async--output-toot + (funcall filter queue-string)))))))) + +(defun mastodon-async--process-queue-string (string) + "Parse the output STRING of the queue buffer." + (let* ((split-strings (split-string string "\n" t)) + (event-type (replace-regexp-in-string + "^event: " "" + (car split-strings))) + (data (replace-regexp-in-string + "^data: " "" (cadr split-strings)))) + (when (equal "update" event-type) + ;; in some casses the data is not fully formed + ;; for now return nil if malformed using `ignore-errors' + (ignore-errors (json-read-from-string data))))) + +(defun mastodon-async--process-queue-local-string (string) + "Use STRING to limit the public endpoint to displaying local steams only." + (let ((json (mastodon-async--process-queue-string string))) + (when json + (when (mastodon-async--account-local-p json) + json)))) + +(defun mastodon-async--account-local-p (json) + "Test JSON to see if account is local." + (not (string-match-p + "@" + (cdr (assoc 'acct (cdr (assoc 'account json))))))) + +(defun mastodon-async--output-toot (toot) + "Process TOOT and prepend it to the async user facing buffer." + (if (not(bufferp (get-buffer mastodon-async--buffer))) + (mastodon-async--stop-http) + (when toot + (with-current-buffer mastodon-async--buffer + (let* ((inhibit-read-only t) + (old-max (point-max)) + (previous (point)) + (mastodon-tl--enable-relative-timestamps t) + (mastodon-tl--display-media-p t)) + (goto-char (point-min)) + (mastodon-tl--timeline (list toot)) + (if (equal previous 1) + (goto-char 1) + (goto-char (+ previous (- (point-max) old-max))))))))) + +(defun mastodon-async--cycle-queue (string) + "Append the most recent STRING from http buffer to queue buffer. + +Then determine if a full message has been recived. If so return it. +Full messages are seperated by two newlines" + (with-current-buffer mastodon-async--queue + (goto-char (max-char)) + (insert (decode-coding-string string 'utf-8)) + (goto-char 0) + (let((next(re-search-forward "\n\n" nil t))) + (when next + (let ((return-string (buffer-substring 1 next)) + (inhibit-read-only t)) + (delete-region 1 next) + return-string))))) + +(defun mastodon-async--http-layer (proc data) + "Passes PROC and DATA to ‘url-http-generic-filter’. + +It then processes its output." + (with-current-buffer (process-buffer proc) + (let ((start (max 1 ( - (point-max) 2)))) + (url-http-generic-filter proc data) + (when (> url-http-end-of-headers start) + (setq start url-http-end-of-headers)) + (let ((end (- (point-max) 2))) + (buffer-substring start end))))) + +(defun mastodon-async--stream-filter (string) + "Remove comments from STRING." + (replace-regexp-in-string "^:.*\n" "" string)) + +(provide 'mastodon-async) +;;; mastodon-async.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index d3477cb..6096c55 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -54,6 +54,7 @@ (autoload 'mastodon-toot--toggle-boost "mastodon-toot") (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") + (autoload 'mastodon-tl--block-user "mastodon-tl") (autoload 'mastodon-tl--unblock-user "mastodon-tl") (autoload 'mastodon-tl--mute-user "mastodon-tl") @@ -61,11 +62,16 @@ (autoload 'mastodon-tl--follow-user "mastodon-tl") (autoload 'mastodon-tl--unfollow-user "mastodon-tl") (autoload 'mastodon-profile--my-profile "mastodon-profile") +(autoload 'mastodon-profile--view-favourites "mastodon-profile") +(autoload 'mastodon-profile--view-follow-requests "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") (autoload 'mastodon-toot--delete-toot "mastodon-toot") (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") (autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") +(autoload 'mastodon-async--stream-federated "mastodon-async") +(autoload 'mastodon-async--stream-local "mastodon-async") +(autoload 'mastodon-async--stream-home "mastodon-async") (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From 9f532060927265717b7c71f5b77f6c650e72a34d Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 3 Jun 2021 10:02:57 +0200 Subject: enable async stream for user notifications. creates a notifications filter for the 'user' stream, then handles display of notifications, which have their own timeline funs. --- README.org | 13 +++++-- lisp/mastodon-async.el | 83 ++++++++++++++++++++++++++++-------------- lisp/mastodon-notifications.el | 6 +-- lisp/mastodon.el | 5 +++ 4 files changed, 73 insertions(+), 34 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index b51644b..6da0f4b 100644 --- a/README.org +++ b/README.org @@ -9,8 +9,8 @@ It adds the following features: | | display relationship (follows you/followed by you) on profiles | | | display toots/follows/followers counts on profiles | | | links and tags in profiles are tab stops like in posts | -| =R=, =a=, =r= | view/accept/reject follow requests | -| =v= | view your favorited toots | +| =R=, =a=, =r= | view/accept/reject follow requests | +| =v= | view your favorited toots | | =i= | (un)pin toots, display pinned toots on profiles | | =S-C-P= | jump to your profile | | Timelines: | | @@ -33,7 +33,13 @@ The minimum Emacs version is now 25.1. But if you are running an older version i I did this for my own use and to learn more Elisp. If the code is terrible, feel free to improve or replace it. It surely still contains errors, I'm only weeding them out as I find them. -** NB: dependency: +** live-updating timelines + +(code adapted from https://github.com/alexjgriffith/mastodon-future.el). + +Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream= + +** NB: dependency This version depends on the library =request= (for uploading attachments). You can install it from MELPA, or https://github.com/tkf/emacs-request. @@ -53,7 +59,6 @@ I might add a few more features if the ones I added turn out to work ok. Possibl - mention all thread participants in replies - handle newlines in toots better, for poetry, etc. - improve async. -- perhaps integrate live timeline updates from https://github.com/alexjgriffith/mastodon-future.el, and add live updates for notifcations and home timeline. It looks like 2-factor auth was never completed in the original repo. It's not a priority for me, auth ain't my thing. If you want to hack on it, its on the develop branch in the original repo. diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index ffd8ab6..1be88ae 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -31,6 +31,8 @@ (require 'json) +(autoload 'mastodon-notifications--timeline "mastodon-notifications") + (defgroup mastodon-async nil "An async module for mastodon streams." :prefix "mastodon-async-" @@ -86,19 +88,19 @@ ;; The output can be passed to notifications ;; need an alternate process-queue-string function (defun mastodon-async--stream-notifications () - "Open a stream of Home." + "Open a stream of user notifications." (interactive) (mastodon-async--mastodon "user" "home" "notifications" - 'mastodon-async--process-queue-string)) + 'mastodon-async--process-queue-string-notifications)) ;; this will stream both home AND notifications. ;; need to workout how to filter "user" stream ;; and split it (defun mastodon-async--stream-home () - "Open a stream of Home." + "Open a stream of the home timeline." (interactive) (mastodon-async--mastodon "user" @@ -132,7 +134,7 @@ Then Start an async mastodon stream at ENDPOINT filtering toots using FILTER. Argument TIMELINE a specific target, such as federated or home. -Argument NAME the center portion of the buffer name for *mastodon-async-buffer and *mastodon-async-queueu." +Argument NAME the center portion of the buffer name for *mastodon-async-buffer and *mastodon-async-queue." (let ((buffer (mastodon-async--start-process endpoint filter name))) (with-current-buffer buffer @@ -141,7 +143,7 @@ Argument NAME the center portion of the buffer name for *mastodon-async-buffer a (goto-char 1)))) (defun mastodon-async--get (url callback) - "An async get targeted at URL with a CALLBACK." + "An async GET request to URL with CALLBACK." (let ((url-request-method "GET") (url-request-extra-headers `(("Authorization" . @@ -174,16 +176,16 @@ is not known when `mastodon-async--setup-buffer' is called." "Adds local variables to HTTP-BUFFER. NAME is used to generate the display buffer and the queue." - (let ((queue-name(concat " *mastodon-async-queue-" name "-" + (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) - (buffer-name(concat "*mastodon-async-display-" name "-" + (buffer-name (concat "*mastodon-async-display-" name "-" mastodon-instance-url "*"))) (mastodon-async--set-local-variables http-buffer http-buffer buffer-name queue-name))) (defun mastodon-async--setup-queue (http-buffer name) "Sets up the buffer for the async queue." - (let ((queue-name(concat " *mastodon-async-queue-" name "-" + (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) (buffer-name(concat "*mastodon-async-display-" name "-" mastodon-instance-url "*"))) @@ -194,15 +196,18 @@ NAME is used to generate the display buffer and the queue." (defun mastodon-async--setup-buffer (http-buffer name endpoint) "Sets up the buffer timeline like `mastodon-tl--init'. -HTTP-BUFFER the name of the http-buffer, if unknow set to -NAME is the given name of the stream, like local for public?local -ENPOINT is the specific endpoint for a stream and timeline" +HTTP-BUFFER the name of the http-buffer, if unknown, set to... +NAME is the name of the stream for the buffer name. +ENPOINT is the endpoint for the stream and timeline." (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) (buffer-name (concat "*mastodon-async-display-" name "-" mastodon-instance-url "*")) - ;; if user stream, we need "timelines/home" not "timelines/user" - (endpoint (if (equal endpoint "user") "home" endpoint))) + ;; if user stream, we need "timelines/home" not "timelines/user" + ;; if notifs, we need "notifications" not "timelines/notifications" + (endpoint (if (equal name "notifications") "notifications" + (if (equal name "home") "timelines/home" + (format "timelines/%s" endpoint))))) (mastodon-async--set-local-variables buffer-name http-buffer buffer-name queue-name) ;; Similar to timeline init. @@ -210,16 +215,22 @@ ENPOINT is the specific endpoint for a stream and timeline" (setq inhibit-read-only t) ; for home timeline? (make-local-variable 'mastodon-tl--enable-relative-timestamps) (make-local-variable 'mastodon-tl--display-media-p) - (message (mastodon-http--api (format "timelines/%s" endpoint))) - (mastodon-tl--timeline (mastodon-http--get-json - (mastodon-http--api - (format "timelines/%s" endpoint)))) + (message (mastodon-http--api endpoint)) + (if (equal name "notifications") + (mastodon-notifications--timeline + (mastodon-http--get-json + (mastodon-http--api "notifications"))) + (mastodon-tl--timeline (mastodon-http--get-json + (mastodon-http--api endpoint)))) (mastodon-mode) (setq mastodon-tl--buffer-spec - `(buffer-name ,buffer-name - endpoint ,(format "timelines/%s" endpoint) - update-function - ,'mastodon-tl--timeline)) + `(buffer-name + ,buffer-name + endpoint ,endpoint + update-function + ,(if (equal name "notifications") + 'mastodon-notifications--timeline + 'mastodon-tl--timeline))) (setq-local mastodon-tl--enable-relative-timestamps nil) (setq-local mastodon-tl--display-media-p t) (current-buffer)))) @@ -254,7 +265,7 @@ Filter the toots using FILTER." (funcall filter queue-string)))))))) (defun mastodon-async--process-queue-string (string) - "Parse the output STRING of the queue buffer." + "Parse the output STRING of the queue buffer, returning only update events." (let* ((split-strings (split-string string "\n" t)) (event-type (replace-regexp-in-string "^event: " "" @@ -266,6 +277,20 @@ Filter the toots using FILTER." ;; for now return nil if malformed using `ignore-errors' (ignore-errors (json-read-from-string data))))) +(defun mastodon-async--process-queue-string-notifications (string) + "Parse the output STRING of the queue buffer, returning only notification events." + ;; NB notification events in screams include follow requests + (let* ((split-strings (split-string string "\n" t)) + (event-type (replace-regexp-in-string + "^event: " "" + (car split-strings))) + (data (replace-regexp-in-string + "^data: " "" (cadr split-strings)))) + (when (equal "notification" event-type) + ;; in some casses the data is not fully formed + ;; for now return nil if malformed using `ignore-errors' + (ignore-errors (json-read-from-string data))))) + (defun mastodon-async--process-queue-local-string (string) "Use STRING to limit the public endpoint to displaying local steams only." (let ((json (mastodon-async--process-queue-string string))) @@ -280,8 +305,8 @@ Filter the toots using FILTER." (cdr (assoc 'acct (cdr (assoc 'account json))))))) (defun mastodon-async--output-toot (toot) - "Process TOOT and prepend it to the async user facing buffer." - (if (not(bufferp (get-buffer mastodon-async--buffer))) + "Process TOOT and prepend it to the async user-facing buffer." + (if (not (bufferp (get-buffer mastodon-async--buffer))) (mastodon-async--stop-http) (when toot (with-current-buffer mastodon-async--buffer @@ -290,8 +315,12 @@ Filter the toots using FILTER." (previous (point)) (mastodon-tl--enable-relative-timestamps t) (mastodon-tl--display-media-p t)) - (goto-char (point-min)) - (mastodon-tl--timeline (list toot)) + (goto-char (point-min)) + (if (equal (buffer-name) + (concat "*mastodon-async-display-notifications-" + mastodon-instance-url "*")) + (mastodon-notifications--timeline (list toot)) + (mastodon-tl--timeline (list toot))) (if (equal previous 1) (goto-char 1) (goto-char (+ previous (- (point-max) old-max))))))))) @@ -305,7 +334,7 @@ Full messages are seperated by two newlines" (goto-char (max-char)) (insert (decode-coding-string string 'utf-8)) (goto-char 0) - (let((next(re-search-forward "\n\n" nil t))) + (let ((next (re-search-forward "\n\n" nil t))) (when next (let ((return-string (buffer-substring 1 next)) (inhibit-read-only t)) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index d40815a..4bf30f1 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -140,11 +140,11 @@ (defun mastodon-notifications--get () "Display NOTIFICATIONS in buffer." (interactive) + (message "Loading your nofications...") (mastodon-tl--init - "*mastodon-notifications*" "notifications" - 'mastodon-notifications--timeline) - (message "Loading your nofications...")) + "notifications" + 'mastodon-notifications--timeline)) (provide 'mastodon-notifications) ;;; mastodon-notifications.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6096c55..4d0b940 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -72,6 +72,7 @@ (autoload 'mastodon-async--stream-federated "mastodon-async") (autoload 'mastodon-async--stream-local "mastodon-async") (autoload 'mastodon-async--stream-home "mastodon-async") +(autoload 'mastodon-async--stream-notifications "mastodon-async") (defgroup mastodon nil "Interface with Mastodon." @@ -139,6 +140,10 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) (define-key map (kbd "v") #'mastodon-profile--view-favourites) (define-key map (kbd "R") #'mastodon-profile--view-follow-requests) + (define-key map (kbd "C-c h") #'mastodon-async--stream-home) + (define-key map (kbd "C-c f") #'mastodon-async--stream-federated) + (define-key map (kbd "C-c l") #'mastodon-async--stream-local) + (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From a32a239d7e64d46df8e76c712a2335cecf8776e9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Jun 2021 12:43:19 +0200 Subject: implement updating user profile note uses a tiny minor mode 'profile-update', with bindings. U is a general binding for it. --- README.org | 8 +++--- lisp/mastodon-http.el | 25 +++++++++++++++++- lisp/mastodon-profile.el | 69 +++++++++++++++++++++++++++++++++++++++++++----- lisp/mastodon.el | 4 ++- 4 files changed, 94 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index 6da0f4b..c6eab5a 100644 --- a/README.org +++ b/README.org @@ -6,13 +6,15 @@ It adds the following features: | Profiles: | | | | display profile metadata fields | +| | display pinned toots on profiles | | | display relationship (follows you/followed by you) on profiles | | | display toots/follows/followers counts on profiles | -| | links and tags in profiles are tab stops like in posts | +| | links and tags in profiles and metadata fields are tab stops like in posts | | =R=, =a=, =r= | view/accept/reject follow requests | | =v= | view your favorited toots | -| =i= | (un)pin toots, display pinned toots on profiles | +| =i= | (un)pin toots | | =S-C-P= | jump to your profile | +| =U= | update your profile bio note | | Timelines: | | | =W=, =M=, =B= | (un)follow, (un)mute, (un)block users | | | images are links to the full image, can be zoomed/rotated/saved (see their keymap) | @@ -37,7 +39,7 @@ I did this for my own use and to learn more Elisp. If the code is terrible, feel (code adapted from https://github.com/alexjgriffith/mastodon-future.el). -Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream= +Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=. ** NB: dependency diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index e85429f..678e628 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -137,7 +137,7 @@ Pass response buffer to CALLBACK function." (with-temp-buffer (url-retrieve-synchronously url)))) -;; http functions for search: +;; search functions: (defun mastodon-http--process-json-search () "Process JSON returned by a search query to the server." (goto-char (point-min)) @@ -168,6 +168,29 @@ Pass response buffer to CALLBACK function." (url-retrieve-synchronously url) (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) +;; profile update functions + +(defun mastodon-http--patch-json (url) + "Make synchronous PATCH request to URL. Return JSON response." + (with-current-buffer (mastodon-http--patch url) + (mastodon-http--process-json))) + +;; hard coded just for bio note for now: +(defun mastodon-http--patch (base-url &optional note) + "Make synchronous PATCH request to URL. + +Pass response buffer to CALLBACK function." + (let ((url-request-method "PATCH") + (url (if note + (concat base-url "?note=" (url-hexify-string note)) + base-url)) + (url-request-extra-headers + `(("Authorization" . ,(concat "Bearer " + (mastodon-auth--access-token)))))) + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + ;; Asynchronous functions (defun mastodon-http--get-async (url &optional callback &rest cbargs) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 84664c0..0b7ecc4 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -53,15 +53,28 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-tl--toot "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl.el") +(autoload 'mastodon-http--patch "mastodon-http") +(autoload 'mastodon-http--patch-json "mastodon-http") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--update-point) + (defvar mastodon-profile--account nil "The data for the account being described in the current profile buffer.") (make-variable-buffer-local 'mastodon-profile--account) +;; this way you can update it with C-M-x: +(defvar mastodon-profile-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "O") #'mastodon-profile--open-followers) + (define-key map (kbd "o") #'mastodon-profile--open-following) + (define-key map (kbd "a") #'mastodon-profile--follow-request-accept) + (define-key map (kbd "r") #'mastodon-profile--follow-request-reject) + map) + "Keymap for `mastodon-profile-mode'.") + (define-minor-mode mastodon-profile-mode "Toggle mastodon profile minor mode. @@ -70,12 +83,26 @@ extra keybindings." :init-value nil ;; The mode line indicator. :lighter " Profile" - ;; The key bindings - :keymap '(((kbd "O") . mastodon-profile--open-followers) - ((kbd "o") . mastodon-profile--open-following) - ((kbd "a") . mastodon-profile--follow-request-accept) - ((kbd "r") . mastodon-profile--follow-request-reject)) - :group 'mastodon) + :keymap mastodon-profile-mode-map + ;; :keymap '(((kbd "O") . mastodon-profile--open-followers) + ;; ((kbd "o") . mastodon-profile--open-following) + ;; ((kbd "a") . mastodon-profile--follow-request-accept) + ;; ((kbd "r") . mastodon-profile--follow-request-reject) + :group 'mastodon + :global nil) + +(defvar mastodon-profile-update-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") #'mastodon-profile--user-profile-send-updated) + (define-key map (kbd "C-c C-k") #'kill-buffer-and-window) + map) + "Keymap for `mastodon-profile-update-mode'.") + +(define-minor-mode mastodon-profile-update-mode + "Minor mode to update Mastodon user profile." + :group 'mastodon-profile + :keymap mastodon-profile-update-mode-map + :global nil) (defun mastodon-profile--toot-json () "Get the next toot-json." @@ -112,6 +139,7 @@ following the current profile." (defun mastodon-profile--view-favourites () "Open a new buffer displaying the user's favourites." (interactive) + (message "Loading your favourited toots...") (mastodon-tl--init "favourites" "favourites" 'mastodon-tl--timeline)) @@ -164,6 +192,33 @@ following the current profile." name handle)))) (message "No account result at point?")))) +(defun mastodon-profile--update-user-profile-note () + "Fetch user's profile note and display for editing." + (interactive) + (let* ((url (concat mastodon-instance-url + "/api/v1/accounts/update_credentials")) + ;; (buffer (mastodon-http--patch url)) + (json (mastodon-http--patch-json url)) + (source (cdr (assoc 'source json))) + (note (cdr (assoc 'note source))) + (buffer (get-buffer-create "*mastodon-update-profile*")) + (inhibit-read-only t)) + (switch-to-buffer-other-window buffer) + (mastodon-profile-update-mode t) + (insert note) + (goto-char (point-min)) + (message "Edit your profile note. C-c C-c to send, C-c C-k to cancel."))) + +(defun mastodon-profile--user-profile-send-updated () + "Send PATCH request with the updated profile note." + (interactive) + (let* ((note (buffer-substring-no-properties (point-min) (point-max))) + (url (concat mastodon-instance-url + "/api/v1/accounts/update_credentials"))) + (kill-buffer-and-window) + (let ((response (mastodon-http--patch url note))) + (mastodon-http--triage response + (lambda () (message "Profile note updated!")))))) (defun mastodon-profile--relationships-get (id) "Fetch info about logged-in user's relationship to user with id ID." @@ -205,7 +260,7 @@ Returns a list of lists." (format " :: %s" (cadr field))) ;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_) ;; " |") - nil)) + field)) ; nil)) ; hack to make links tabstops fields ""))) (defun mastodon-profile--get-statuses-pinned (account) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 4d0b940..c1c4360 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -73,6 +73,7 @@ (autoload 'mastodon-async--stream-local "mastodon-async") (autoload 'mastodon-async--stream-home "mastodon-async") (autoload 'mastodon-async--stream-notifications "mastodon-async") +(autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (defgroup mastodon nil "Interface with Mastodon." @@ -143,7 +144,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-c h") #'mastodon-async--stream-home) (define-key map (kbd "C-c f") #'mastodon-async--stream-federated) (define-key map (kbd "C-c l") #'mastodon-async--stream-local) - (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) + (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) + (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From af3705d107a248c1edc0742f6a8533bef533b6a5 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Jun 2021 17:09:10 +0200 Subject: only get-home-timeline if mastodon buffers not already open. requires cl-lib --- lisp/mastodon.el | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index c1c4360..50acc18 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -30,6 +30,8 @@ ;; it is a labor of love. ;;; Code: +(require 'cl-lib) ; for some call in mastodon + (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") (declare-function request "request") @@ -180,8 +182,19 @@ Use. e.g. \"%c\" for your locale's date and time format." (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." (interactive) - (mastodon-tl--get-home-timeline) - (message "Loading Mastodon account %s on %s..." (mastodon-auth--get-account-name) mastodon-instance-url)) + (let* ((tls (list "home" + "local" + "federated" + (concat (mastodon-auth--get-account-name) "-statuses") ; profile + "favourites" + "search")) + (buffer (cl-some (lambda (el) + (get-buffer (concat "*mastodon-" el "*"))) + tls))) ; return first buff that exists + (if buffer + (switch-to-buffer buffer) + (mastodon-tl--get-home-timeline) + (message "Loading Mastodon account %s on %s..." (mastodon-auth--get-account-name) mastodon-instance-url)))) ;;;###autoload (defun mastodon-toot (&optional user reply-to-id) -- cgit v1.2.3 From dfa1db177bfb2c1d5ff044c99a78a380da89ec33 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 8 Jun 2021 09:49:58 +0200 Subject: use mastodon-auth--user-acct instead of get-account-name in mastodon the former first checks if the value is stored in var mastodon-auth--acct-alist, and only makes a request if it doesn't get the handle from there. and if run it also stores the value. --- lisp/mastodon.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 50acc18..e166671 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -76,6 +76,7 @@ (autoload 'mastodon-async--stream-home "mastodon-async") (autoload 'mastodon-async--stream-notifications "mastodon-async") (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") +(autoload 'mastodon-auth--user-acct "mastodon-auth") (defgroup mastodon nil "Interface with Mastodon." @@ -185,7 +186,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (let* ((tls (list "home" "local" "federated" - (concat (mastodon-auth--get-account-name) "-statuses") ; profile + (concat (mastodon-auth--user-acct) "-statuses") ; profile "favourites" "search")) (buffer (cl-some (lambda (el) @@ -194,7 +195,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (if buffer (switch-to-buffer buffer) (mastodon-tl--get-home-timeline) - (message "Loading Mastodon account %s on %s..." (mastodon-auth--get-account-name) mastodon-instance-url)))) + (message "Loading Mastodon account %s on %s..." (mastodon-auth--user-acct) mastodon-instance-url)))) ;;;###autoload (defun mastodon-toot (&optional user reply-to-id) -- cgit v1.2.3 From c9a80513b451ebab95eca3b4dda7e2ece6bcbbd2 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 14 Jun 2021 14:29:42 +0200 Subject: typos and readme --- README.org | 44 +++++++++++++++++++++++------------------- lisp/mastodon-notifications.el | 2 +- lisp/mastodon.el | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index c6eab5a..21ae34a 100644 --- a/README.org +++ b/README.org @@ -39,7 +39,11 @@ I did this for my own use and to learn more Elisp. If the code is terrible, feel (code adapted from https://github.com/alexjgriffith/mastodon-future.el). -Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=. +Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=, and you can load various timelines from within a mastodon session like so: +- =C-c h= (home) +- =C-c f= (federated) +- =C-c l= (local) +- =C-c n= (notifications). ** NB: dependency @@ -64,9 +68,9 @@ I might add a few more features if the ones I added turn out to work ok. Possibl It looks like 2-factor auth was never completed in the original repo. It's not a priority for me, auth ain't my thing. If you want to hack on it, its on the develop branch in the original repo. -** Original README +* Original README -*** Installation +** Installation Clone this repository and add the lisp directory to your load path. Then, require it and go. @@ -83,7 +87,7 @@ Or, with =use-package=: :ensure t) #+END_SRC -**** MELPA +*** MELPA Add =MELPA= to your archives: @@ -99,12 +103,12 @@ Update and install: =M-x package-install RET mastodon RET= -**** Emoji +*** Emoji =mastodon-mode= will enable [[https://github.com/iqbalansari/emacs-emojify][Emojify]] if it is loaded in your Emacs environment, so there's no need to write your own hook anymore. =emojify-mode= is not required. -**** Discover +*** Discover =mastodon-mode= can provide a context menu for its keybindings if [[https://github.com/mickeynp/discover.el][Discover]] is installed. It is not required. @@ -125,12 +129,12 @@ Or, with =use-package=: (mastodon-discover)) #+END_SRC -*** Usage -**** 2 Factor Auth +** Usage +*** 2 Factor Auth 2FA is not supported yet. It is in the [[https://github.com/jdenen/mastodon.el/milestone/2][plans]] for the =1.0.0= release. If you have 2FA enabled and try to use mastodon.el, your Emacs client will hang until you `C-g` your way out. -**** Instance +*** Instance Set =mastodon-instance-url= in your =.emacs= or =customize=. Defaults to the [[https://mastodon.social][flagship]]. @@ -142,13 +146,13 @@ There is an option to have your user credentials (email address and password) sa The default is not to do this because if not properly configured it would save these unencrypted which is not a good default to have. Customize the variable =mastodon-auth-source-file= if you want to enable this feature. -**** Timelines +*** Timelines =M-x mastodon= Opens a =*mastodon-home*= buffer in the major mode so you can see toots. You will be prompted for email and password. The app registration process will take place if your =mastodon-token-file= does not contain =:client_id= and =:client_secret=. -***** Keybindings +**** Keybindings |-----------------+---------------------------------------------------------| | Key | Action | @@ -181,7 +185,7 @@ Opens a =*mastodon-home*= buffer in the major mode so you can see toots. You wil | =Q= | Quit mastodon buffer and kill window | |-----------------+---------------------------------------------------------| -***** Legend +**** Legend |--------+-------------------------| | Marker | Meaning | @@ -190,7 +194,7 @@ Opens a =*mastodon-home*= buffer in the major mode so you can see toots. You wil | =(F)= | I favourited this toot. | |--------+-------------------------| -**** Toot toot +*** Toot toot =M-x mastodon-toot= @@ -205,12 +209,12 @@ Authentication stores your access token in the =mastodon-auth--token= variable. It is not stored on your filesystem, so you will have to re-authenticate when you close/reopen Emacs. -***** Customization +**** Customization The default toot visibility can be changed by setting or customizing the =mastodon-toot--default-visibility= variable. Valid values are ="public"=, ="unlisted"=, ="private"=, or =direct=. Toot visibility can also be changed on a per-toot basis from the new toot buffer. -***** Keybindings +**** Keybindings |-----------+------------------------| | Key | Action | @@ -221,28 +225,28 @@ Toot visibility can also be changed on a per-toot basis from the new toot buffer | =C-c C-v= | Change toot visibility | |-----------+------------------------| -*** Roadmap +** Roadmap [[https://github.com/jdenen/mastodon.el/milestone/1][Here]] are the features I plan to implement before putting mastodon.el on MELPA. [[https://github.com/jdenen/mastodon.el/milestone/2][Here]] are the plans I have for the =1.0.0= release. -*** Contributing +** Contributing PRs, issues, and feature requests are very welcome! -**** Features +*** Features 1. Create an [[https://github.com/jdenen/mastodon.el/issues][issue]] detailing the feature you'd like to add. 2. Fork the repository and create a branch off of =develop=. 3. Create a pull request referencing the issue created in step 1. -**** Fixes +*** Fixes 1. In an [[https://github.com/jdenen/mastodon.el/issues][issue]], let me know that you're working to fix it. 2. Fork the repository and create a branch off of =develop=. 3. Create a pull request referencing the issue from step 1. -*** Connect +** Connect If you want to get in touch with me, give me a [[https://mastodon.social/@johnson][toot]] or leave an [[https://github.com/jdenen/mastodon.el/issues][issue]]. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 4bf30f1..51806a3 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -140,7 +140,7 @@ (defun mastodon-notifications--get () "Display NOTIFICATIONS in buffer." (interactive) - (message "Loading your nofications...") + (message "Loading your notifications...") (mastodon-tl--init "notifications" "notifications" diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e166671..430362d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -30,7 +30,7 @@ ;; it is a labor of love. ;;; Code: -(require 'cl-lib) ; for some call in mastodon +(require 'cl-lib) ; for `some' call in mastodon (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") -- cgit v1.2.3 From f9452225da575a8272b2880214a241b72efd5e4f Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 19 Jun 2021 12:37:07 +0200 Subject: hack to ensure toot buffer bindings are always enabled. make mastodon-toot-mode is run in mastodon-toot--compose-buffer before after-change-functions bugs. this makes mastodon-toot work properly even if mastodon-mode has not yet been run/loaded yet. --- lisp/mastodon-toot.el | 4 ++-- lisp/mastodon.el | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a0f886c..d9f895c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -516,9 +516,9 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (when (not buffer-exists) (mastodon-toot--display-docs-and-status-fields) (mastodon-toot--setup-as-reply reply-to-user reply-to-id)) + (mastodon-toot-mode t) (push #'mastodon-toot--update-status-fields after-change-functions) - (mastodon-toot--update-status-fields) - (mastodon-toot-mode t))) + (mastodon-toot--update-status-fields))) (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 430362d..96a092f 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -30,7 +30,7 @@ ;; it is a labor of love. ;;; Code: -(require 'cl-lib) ; for `some' call in mastodon +(require 'cl-lib) ; for `cl-some' call in mastodon (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") -- cgit v1.2.3 From 2efdb5eb4ddc824ad269af096cb508b8f6867077 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 9 Aug 2021 17:46:19 +0200 Subject: follow requests accept/reject from notifications + - new bindings for f-req accept/reject (in both notifs and in f-req views) - check if we are at an f-req before accept/rejecting - flycheck / docstrings - fix notifs byline formatting for f-reqs --- README.org | 1 + lisp/mastodon-notifications.el | 77 ++++++++++++++++++++++++++++++++------- lisp/mastodon-profile.el | 81 ++++++++++++++++++++++-------------------- lisp/mastodon.el | 4 +++ 4 files changed, 111 insertions(+), 52 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index cb4a37a..5969950 100644 --- a/README.org +++ b/README.org @@ -62,6 +62,7 @@ I might add a few more features if the ones I added turn out to work ok. Possibl - [X] update profile note. - [X] fix loading more notifications re-loads the same ones +- [X] view/accept/reject follow requests in notifications view. - voting on polls - better display of polls - display number of boosts/faves in toot byline diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 676b4a8..caeb9cd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -54,7 +54,7 @@ ("Followed" . "you") ("Favourited" . "your status from") ("Boosted" . "your status from") - ("Follow request" . "requested to follow you")) + ("Requested to follow" . "you")) "Alist of subjects for notification types.") (defun mastodon-notifications--byline-concat (message) @@ -65,6 +65,59 @@ " " (cdr (assoc message mastodon-notifications--response-alist)))) + +(defun mastodon-notifications--follow-request-accept-notifs () + "Accept the follow request of user at point, in notifications view." + (interactive) + (when (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((toot-json (mastodon-tl--property 'toot-json)) + (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) + (if f-req-p + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc 'username account)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/authorize" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (mastodon-notifications--get) + (message "Follow request of %s (@%s) accepted!" + name handle)))) + (message "No account result at point?"))) + (message "No follow request at point?"))))) + +(defun mastodon-notifications--follow-request-reject-notifs () + "Reject the follow request of user at point, in notifications view." + (interactive) + (when (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((toot-json (mastodon-tl--property 'toot-json)) + (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) + (if f-req-p + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc 'username account)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/reject" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (mastodon-notifications--get) + (message "Follow request of %s (@%s) rejected!" + name handle)))) + (message "No account result at point?"))) + (message "No follow request at point?"))))) + (defun mastodon-notifications--mention (note) "Format for a `mention' NOTE." (let ((id (cdr (assoc 'id note))) @@ -97,19 +150,16 @@ (defun mastodon-notifications--follow-request (note) "Format for a `follow-request' NOTE." (let ((id (cdr (assoc 'id note))) - (status (mastodon-tl--field 'status note)) (follower (cdr (assoc 'username (cdr (assoc 'account note)))))) (mastodon-notifications--insert-status - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - (cons '(reblog (id . nil)) note) - (propertize (format "You have a follow request from... %s" follower) - 'face 'default) - 'mastodon-tl--byline-author - (lambda (_status) - (mastodon-notifications--byline-concat - "Requested to follow you")) - id))) + (cons '(reblog (id . nil)) note) + (propertize (format "You have a follow request from... %s" follower) + 'face 'default) + 'mastodon-tl--byline-author + (lambda (_status) + (mastodon-notifications--byline-concat + "Requested to follow")) + id))) (defun mastodon-notifications--favourite (note) "Format for a `favourite' NOTE." @@ -155,7 +205,8 @@ 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'" +it is `mastodon-tl--byline-boosted'. +ID is the notification's own id, which is attached as a property." (let ((start-pos (point))) (insert (propertize diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0c1ec91..82eb4db 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -46,6 +46,7 @@ (autoload 'mastodon-tl--byline-author "mastodon-tl.el") (autoload 'mastodon-tl--goto-next-toot "mastodon-tl.el") (autoload 'mastodon-tl--property "mastodon-tl.el") +(autoload 'mastodon-tl--find-property-range "mastodon-tl.el") (autoload 'mastodon-tl--render-text "mastodon-tl.el") (autoload 'mastodon-tl--set-face "mastodon-tl.el") (autoload 'mastodon-tl--timeline "mastodon-tl.el") @@ -70,8 +71,8 @@ (let ((map (make-sparse-keymap))) (define-key map (kbd "O") #'mastodon-profile--open-followers) (define-key map (kbd "o") #'mastodon-profile--open-following) - (define-key map (kbd "C-c a") #'mastodon-profile--follow-request-accept) - (define-key map (kbd "C-c r") #'mastodon-profile--follow-request-reject) + (define-key map (kbd "a") #'mastodon-profile--follow-request-accept) + (define-key map (kbd "j") #'mastodon-profile--follow-request-reject) map) "Keymap for `mastodon-profile-mode'.") @@ -110,13 +111,12 @@ extra keybindings." (mastodon-tl--property 'toot-json)) (defun mastodon-profile--make-author-buffer (account) - "Take a ACCOUNT and inserts a user account into a new buffer." + "Take a ACCOUNT and insert a user account into a new buffer." (mastodon-profile--make-profile-buffer-for account "statuses" #'mastodon-tl--timeline)) (defun mastodon-profile--open-following () - "Open a profile buffer for the current profile showing the accounts -that current profile follows." + "Open a profile buffer showing the accounts that current profile follows." (interactive) (if mastodon-profile--account (mastodon-profile--make-profile-buffer-for @@ -126,8 +126,7 @@ that current profile follows." (error "Not in a mastodon profile"))) (defun mastodon-profile--open-followers () - "Open a profile buffer for the current profile showing the accounts -following the current profile." + "Open a profile buffer showing the accounts following the current profile." (interactive) (if mastodon-profile--account (mastodon-profile--make-profile-buffer-for @@ -155,42 +154,46 @@ following the current profile." (defun mastodon-profile--follow-request-accept () "Accept the follow request of user at point." (interactive) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (cdr (assoc 'id acct-json))) - (handle (cdr (assoc 'acct acct-json))) - (name (cdr (assoc 'username acct-json)))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/authorize" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (message "Follow request of %s (@%s) accepted!" - name handle)))) - (message "No account result at point?")))) + (if (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((acct-json (mastodon-profile--toot-json)) + (id (cdr (assoc 'id acct-json))) + (handle (cdr (assoc 'acct acct-json))) + (name (cdr (assoc 'username acct-json)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/authorize" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (message "Follow request of %s (@%s) accepted!" + name handle)))) + (message "No account result at point?"))) + (message "No follow request at point?"))) (defun mastodon-profile--follow-request-reject () "Reject the follow request of user at point." (interactive) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (cdr (assoc 'id acct-json))) - (handle (cdr (assoc 'acct acct-json))) - (name (cdr (assoc 'username acct-json)))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/reject" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (message "Follow request of %s (@%s) rejected!" - name handle)))) - (message "No account result at point?")))) + (if (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((acct-json (mastodon-profile--toot-json)) + (id (cdr (assoc 'id acct-json))) + (handle (cdr (assoc 'acct acct-json))) + (name (cdr (assoc 'username acct-json)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/reject" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (message "Follow request of %s (@%s) rejected!" + name handle)))) + (message "No account result at point?"))) + (message "No follow request at point?"))) (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 96a092f..a918b44 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -66,6 +66,8 @@ (autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-profile--view-favourites "mastodon-profile") (autoload 'mastodon-profile--view-follow-requests "mastodon-profile") +(autoload 'mastodon-notifications--follow-request-accept-notifs "mastodon-profile") +(autoload 'mastodon-notifications--follow-request-reject-notifs "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") (autoload 'mastodon-toot--delete-toot "mastodon-toot") (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") @@ -149,6 +151,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-c l") #'mastodon-async--stream-local) (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) + (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) + (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From d91d881a634f84e50c70e8be882bcfb278c64823 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 9 Aug 2021 23:14:44 +0200 Subject: functions to vote on polls in timelines, bound to "v" - masto view favorites binding moved to "V", in line with other separate views being in capitals --- README.org | 5 +++-- lisp/mastodon-tl.el | 46 ++++++++++++++++++++++++++++++++++++++++++---- lisp/mastodon.el | 4 +++- 3 files changed, 48 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index 5969950..6cf318e 100644 --- a/README.org +++ b/README.org @@ -63,12 +63,13 @@ I might add a few more features if the ones I added turn out to work ok. Possibl - [X] update profile note. - [X] fix loading more notifications re-loads the same ones - [X] view/accept/reject follow requests in notifications view. -- voting on polls +- [X] fix sometimes usernames don't appear in timelines +- [X] voting on polls - better display of polls - display number of boosts/faves in toot byline - mention all thread participants in replies - handle newlines in toots better, for poetry, etc. -- improve async. +- improve (or even partially disable) async. It looks like 2-factor auth was never completed in the original repo. It's not a priority for me, auth ain't my thing. If you want to hack on it, its on the develop branch in the original repo. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8f368a3..107f7eb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -52,7 +52,7 @@ (autoload 'mastodon-http--triage "mastodon-http") (autoload 'mastodon-http--get-json-async "mastodon-http") (autoload 'mastodon-profile--lookup-account-in-status "mastodon-profile") - +(autoload 'mastodon-profile-mode "mastodon-profile") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this @@ -691,15 +691,53 @@ it is `mastodon-tl--byline-boosted'" (defun mastodon-tl--get-poll (toot) "If post TOOT is a poll, return a formatted string of poll." (let* ((poll (mastodon-tl--field 'poll toot)) - (options (mastodon-tl--field 'options poll))) + (options (mastodon-tl--field 'options poll)) + (option-counter 0)) (concat "Poll: \n\n" (mapconcat (lambda (option) - (format "Option: %s, %s votes.\n" + (progn + (format "Option %s: %s, %s votes.\n" + (setq option-counter (1+ option-counter)) (cdr (assoc 'title option)) - (cdr (assoc 'votes_count option)))) + (cdr (assoc 'votes_count option))))) options "\n") "\n"))) +(defun mastodon-tl--poll-vote () + "If toot at point is poll, call `mastodon-tl--poll-vote-yes'." + (interactive) + ;; hack coz i don't know how to put this if test before my interactive + (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) + (message "No poll here.") + (call-interactively 'mastodon-tl--poll-vote-yes))) + +(defun mastodon-tl--poll-vote-yes (option) + "Prompt user for OPTION to vote on poll at point." + (interactive + (list + (let* ((toot (mastodon-tl--property 'toot-json)) + (poll (mastodon-tl--field 'poll toot)) + (options (mastodon-tl--field 'options poll)) + (options-number-seq (number-sequence 1 (length options))) + (options-numbers (mapcar (lambda(x) + (number-to-string x)) + options-number-seq))) + (completing-read "Poll option to vote for: " + options-numbers + nil ;predicate + t)))) ;require match + (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) + (message "No poll here.") + (let* ((toot (mastodon-tl--property 'toot-json)) + (poll (mastodon-tl--field 'poll toot)) + (poll-id (cdr (assoc 'id poll))) + (url (mastodon-http--api (format "polls/%s/votes" poll-id))) + (arg `(("choices[]" . ,option))) + (response (mastodon-http--post url arg nil))) + (mastodon-http--triage response + (lambda () + (message "You voted for option %s!" option)))))) + (defun mastodon-tl--toot (toot) "Formats TOOT and insertes it into the buffer." (mastodon-tl--insert-status diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a918b44..fd00ee9 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -79,6 +79,7 @@ (autoload 'mastodon-async--stream-notifications "mastodon-async") (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") +(autoload 'mastodon-tl--poll-vote "mastodon-http") (defgroup mastodon nil "Interface with Mastodon." @@ -144,7 +145,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "d") #'mastodon-toot--delete-toot) (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) - (define-key map (kbd "v") #'mastodon-profile--view-favourites) + (define-key map (kbd "V") #'mastodon-profile--view-favourites) (define-key map (kbd "R") #'mastodon-profile--view-follow-requests) (define-key map (kbd "C-c h") #'mastodon-async--stream-home) (define-key map (kbd "C-c f") #'mastodon-async--stream-federated) @@ -153,6 +154,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) + (define-key map (kbd "v") #'mastodon-tl--poll-vote) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 53616d194cfcab743558f91e88526e83204ee704 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 22 Sep 2021 17:48:10 +0200 Subject: package-lint: bump to emacs 26.1, disable stream keybindings --- README.org | 10 +++------- lisp/mastodon-async.el | 2 +- lisp/mastodon-auth--test.el | 2 +- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- 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-search.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon.el | 18 +++++++++--------- 15 files changed, 25 insertions(+), 29 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index e7960bf..4be82c6 100644 --- a/README.org +++ b/README.org @@ -32,19 +32,15 @@ It also makes some small cosmetic changes to make timelines easier to read, and This updated version is not on MELPA, to use it you need to clone and require it as per the installation instructions below. -The minimum Emacs version is now 25.1. But if you are running an older version it shouldn't be very hard to get it working. +The minimum Emacs version is now 26.1. But if you are running an older version it shouldn't be very hard to get it working. I did this for my own use and to learn more Elisp. Feel free to improve it. ** live-updating timelines -(code adapted from https://github.com/alexjgriffith/mastodon-future.el.) +(code taken from https://github.com/alexjgriffith/mastodon-future.el.) -Works for federated, local, and home timelines and for notifications. It's pretty necro, sometimes it goes off the rails, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=, and you can load various timelines from within a mastodon session like so: -- =C-c h= (home) -- =C-c f= (federated) -- =C-c l= (local) -- =C-c n= (notifications) +Works for federated, local, and home timelines and for notifications. It's pretty necro, sometimes it goes off the rails, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=. ** NB: dependency diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 4367cc9..6a421d1 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.7.1 -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-auth--test.el b/lisp/mastodon-auth--test.el index b8705f5..9a765b9 100644 --- a/lisp/mastodon-auth--test.el +++ b/lisp/mastodon-auth--test.el @@ -5,7 +5,7 @@ ;; Author: Ian Eure ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 4628e74..3f4ee7d 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 90f1375..6439c0a 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 2387feb..9c946be 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 94aa85d..31ea483 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "25.1") (request "0.2.0")) +;; Package-Requires: ((emacs "26.1") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index c5a8d5d..9559b21 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 2100553..c3873df 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index caeb9cd..7524038 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index eb75247..98d11f7 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "25.1") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 5e8253f..3b7e399 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen , martyhiatt ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c5240db..af6f0a2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index d9f895c..c9184fc 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Version: 0.9.1 ;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.1")) ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index fd00ee9..460fe29 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "25.1") (request "0.2.0") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (request "0.2.0") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -73,10 +73,10 @@ (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") (autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") -(autoload 'mastodon-async--stream-federated "mastodon-async") -(autoload 'mastodon-async--stream-local "mastodon-async") -(autoload 'mastodon-async--stream-home "mastodon-async") -(autoload 'mastodon-async--stream-notifications "mastodon-async") +;; (autoload 'mastodon-async--stream-federated "mastodon-async") +;; (autoload 'mastodon-async--stream-local "mastodon-async") +;; (autoload 'mastodon-async--stream-home "mastodon-async") +;; (autoload 'mastodon-async--stream-notifications "mastodon-async") (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") @@ -147,10 +147,10 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) (define-key map (kbd "V") #'mastodon-profile--view-favourites) (define-key map (kbd "R") #'mastodon-profile--view-follow-requests) - (define-key map (kbd "C-c h") #'mastodon-async--stream-home) - (define-key map (kbd "C-c f") #'mastodon-async--stream-federated) - (define-key map (kbd "C-c l") #'mastodon-async--stream-local) - (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) + ;; (define-key map (kbd "C-c h") #'mastodon-async--stream-home) + ;; (define-key map (kbd "C-c f") #'mastodon-async--stream-federated) + ;; (define-key map (kbd "C-c l") #'mastodon-async--stream-local) + ;; (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) -- cgit v1.2.3 From 4499e9471c4a7ba923ef950954a9e42f9a7ed6e9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 23 Sep 2021 13:09:17 +0200 Subject: basic delete-and-redraft-toot, text status only for now. --- lisp/mastodon-toot.el | 25 +++++++++++++++++++++++++ lisp/mastodon.el | 2 ++ 2 files changed, 27 insertions(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1c8a475..1f65cbf 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -234,6 +234,31 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (mastodon-tl--reload-timeline-or-profile) (message "Toot deleted!")))))))) +;; TODO: handle media/poll for redrafting toots +(defun mastodon-toot--delete-and-redraft-toot () + "Delete and redraft user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s" id)))) + (if (or (cdr (assoc 'reblog toot)) + (not (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (message "You can only delete and redraft your own toots.") + (if (y-or-n-p (format "Delete and redraft this toot? ")) + (let* ((response (mastodon-http--delete url))) + (mastodon-http--triage + response + (lambda () + (with-current-buffer response + (let* ((json-response (mastodon-http--process-json)) + (content (cdr (assoc 'text json-response))) + (media (cdr (assoc 'media_attachments json-response)))) + (mastodon-toot--compose-buffer nil nil) + (goto-char (point-max)) + (insert content)))))))))) + (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." (kill-buffer-and-window)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 460fe29..acb9e12 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -80,6 +80,7 @@ (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") +(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." @@ -143,6 +144,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) (define-key map (kbd "d") #'mastodon-toot--delete-toot) + (define-key map (kbd "D") #'mastodon-toot--delete-and-redraft-toot) (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) (define-key map (kbd "V") #'mastodon-profile--view-favourites) -- cgit v1.2.3 From e9188a2cdb2575e9b0c1c322431e1ebd686c4b9b Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 1 Oct 2021 14:09:09 +0200 Subject: kill-current-buffer instead of kill-this-buffer kill-this-buffer doesn't always work if not called from the menu bar, as stated in its docstring. --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index acb9e12..a06b18d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -122,7 +122,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "P") #'mastodon-profile--show-user) (define-key map (kbd "T") #'mastodon-tl--thread) ;; navigation out of mastodon - (define-key map (kbd "q") #'kill-this-buffer) + (define-key map (kbd "q") #'kill-current-buffer) (define-key map (kbd "Q") #'kill-buffer-and-window) ;; timeline actions (define-key map (kbd "b") #'mastodon-toot--toggle-boost) -- cgit v1.2.3 From 299356ebee27abb8b97cdd4546164b9918727844 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 21 Oct 2021 15:28:27 +0200 Subject: replies to toots adopt their visibility status by default. this makes it so that if you reply to a direct message, your toot will also be direct by default. - we feed the reply's full toot JSON through the chain of functions called, all the way down to "setup-as-reply". that way, if anything else needs to be extracted when setting up a reply, it's all there. --- lisp/mastodon-toot.el | 18 +++++++++++------- lisp/mastodon.el | 5 ++--- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 51c2431..fa44645 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -444,7 +444,7 @@ The prefix string is tested against both user handles and display names." mentions)) (concat (mastodon-toot--process-local user) mentions))) - id))) + id toot))) (defun mastodon-toot--toggle-warning () "Toggle `mastodon-toot--content-warning'." @@ -620,12 +620,16 @@ on the status of NSFW, content warning flags, media attachments, etc." 'read-only "Edit your message below." 'toot-post-header t)))) -(defun mastodon-toot--setup-as-reply (reply-to-user reply-to-id) +(defun mastodon-toot--setup-as-reply (reply-to-user reply-to-id reply-json) "If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." - (when reply-to-user - (insert (format "%s " reply-to-user)) - (setq mastodon-toot--reply-to-id reply-to-id))) + (let ((reply-visibility (cdr (assoc 'visibility reply-json)))) + (when reply-to-user + (insert (format "%s " reply-to-user)) + (setq mastodon-toot--reply-to-id reply-to-id) + (if (not (equal mastodon-toot--visibility + reply-visibility)) + (setq mastodon-toot--visibility reply-visibility))))) (defun mastodon-toot--update-status-fields (&rest args) "Update the status fields in the header based on the current state." @@ -663,7 +667,7 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (list 'invisible (not mastodon-toot--content-warning) 'face 'mastodon-cw-face))))) -(defun mastodon-toot--compose-buffer (reply-to-user reply-to-id) +(defun mastodon-toot--compose-buffer (reply-to-user reply-to-id reply-json) "Create a new buffer to capture text for a new toot. If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." @@ -674,7 +678,7 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (mastodon-toot-mode t) (when (not buffer-exists) (mastodon-toot--display-docs-and-status-fields) - (mastodon-toot--setup-as-reply reply-to-user reply-to-id)) + (mastodon-toot--setup-as-reply reply-to-user reply-to-id reply-json)) (mastodon-toot-mode t) (when mastodon-toot--enable-completion-for-mentions (set (make-local-variable 'company-backends) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a06b18d..e6a01f8 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -206,13 +206,12 @@ Use. e.g. \"%c\" for your locale's date and time format." (message "Loading Mastodon account %s on %s..." (mastodon-auth--user-acct) mastodon-instance-url)))) ;;;###autoload -(defun mastodon-toot (&optional user reply-to-id) +(defun mastodon-toot (&optional user reply-to-id reply-json) "Update instance with new toot. Content is captured in a new buffer. - If USER is non-nil, insert after @ symbol to begin new toot. If REPLY-TO-ID is non-nil, attach new toot to a conversation." (interactive) - (mastodon-toot--compose-buffer user reply-to-id)) + (mastodon-toot--compose-buffer user reply-to-id reply-json)) ;;;###autoload (add-hook 'mastodon-mode-hook (lambda () -- cgit v1.2.3 From 9dbf6e52c5c9f53a5adcf54bf3f9bcdc51c1332c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 22 Oct 2021 12:59:43 +0200 Subject: bookmarks keybinding --- lisp/mastodon.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e6a01f8..e1bd2be 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -81,6 +81,7 @@ (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") +(autoload 'mastodon-profile--view-bookmarks "mastodon-profile") (defgroup mastodon nil "Interface with Mastodon." @@ -157,6 +158,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) (define-key map (kbd "v") #'mastodon-tl--poll-vote) + (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) map) "Keymap for `mastodon-mode'.") -- cgit v1.2.3 From 635bf869e3f87ad182d0288f0947ae4bf842ff4d Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 22 Oct 2021 13:00:04 +0200 Subject: flycheck, autoloads, docstrings --- lisp/mastodon-http.el | 5 +++-- lisp/mastodon-search.el | 3 ++- lisp/mastodon-toot.el | 8 ++++++-- lisp/mastodon.el | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index ea18da8..f092a2d 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -114,7 +114,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." (url-retrieve-synchronously url nil nil mastodon-http--timeout))))) (defun mastodon-http--read-file-as-string (filename) - "" + "Read a file FILENAME as a string. Used to generate image preview." (with-temp-buffer (insert-file-contents filename) (string-to-unibyte (buffer-string)))) @@ -170,7 +170,8 @@ Pass response buffer to CALLBACK function." (json-read-from-string json-string))) (defun mastodon-http--get-search-json (url query &optional param) - "Make GET request to URL, searching for QUERY and return JSON response." + "Make GET request to URL, searching for QUERY and return JSON response. +PARAM is any extra parameters to send with the request." (let ((buffer (mastodon-http--get-search url query param))) (with-current-buffer buffer (mastodon-http--process-json-search)))) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 40f134d..ccac5e6 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -42,6 +42,7 @@ (defvar mastodon-instance-url) (defvar mastodon-tl--link-keymap) (defvar mastodon-http--timeout) +(defvar mastodon-toot--enable-completion-for-mentions) ;; functions for company completion of mentions in mastodon-toot @@ -55,7 +56,7 @@ Returns a nested list containing user handle, display name, and URL." (interactive "sSearch mastodon for: ") (let* ((url (format "%s/api/v1/accounts/search" mastodon-instance-url)) - (buffer (format "*mastodon-search-%s*" query)) + ;; (buffer (format "*mastodon-search-%s*" query)) (response (if (equal mastodon-toot--enable-completion-for-mentions "followers") (mastodon-http--get-search-json url query "following=true") (mastodon-http--get-search-json url query)))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 80c63f6..d4068ea 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -31,6 +31,7 @@ (defvar mastodon-instance-url) (defvar mastodon-media--attachment-height) +(defvar mastodon-toot--enable-completion-for-mentions) (when (require 'emojify nil :noerror) (declare-function emojify-insert-emoji "emojify")) @@ -44,6 +45,7 @@ (autoload 'mastodon-http--triage "mastodon-http") (autoload 'mastodon-http--delete "mastodon-http") (autoload 'mastodon-http--process-json "mastodon-http") +(autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-tl--clean-tabs-and-nl "mastodon-tl") (autoload 'mastodon-tl--field "mastodon-tl") @@ -709,7 +711,8 @@ on the status of NSFW, content warning flags, media attachments, etc." (defun mastodon-toot--setup-as-reply (reply-to-user reply-to-id reply-json) "If REPLY-TO-USER is provided, inject their handle into the message. -If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." +If REPLY-TO-ID is provided, set `mastodon-toot--reply-to-id'. +REPLY-JSON is the full JSON of the toot being replied to." (let ((reply-visibility (cdr (assoc 'visibility reply-json))) (reply-cw (cdr (assoc 'spoiler_text reply-json)))) (when reply-to-user @@ -762,7 +765,8 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (defun mastodon-toot--compose-buffer (reply-to-user reply-to-id &optional reply-json) "Create a new buffer to capture text for a new toot. If REPLY-TO-USER is provided, inject their handle into the message. -If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." +If REPLY-TO-ID is provided, set the `mastodon-toot--reply-to-id' var. +REPLY-JSON is the full JSON of the toot being replied to." (let* ((buffer-exists (get-buffer "*new toot*")) (buffer (or buffer-exists (get-buffer-create "*new toot*"))) (inhibit-read-only t)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e1bd2be..387e9eb 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -211,7 +211,8 @@ Use. e.g. \"%c\" for your locale's date and time format." (defun mastodon-toot (&optional user reply-to-id reply-json) "Update instance with new toot. Content is captured in a new buffer. If USER is non-nil, insert after @ symbol to begin new toot. -If REPLY-TO-ID is non-nil, attach new toot to a conversation." +If REPLY-TO-ID is non-nil, attach new toot to a conversation. +If REPLY-JSON is the json of the toot being replied to." (interactive) (mastodon-toot--compose-buffer user reply-to-id reply-json)) -- cgit v1.2.3 From 143dc33f576fe9a6a4bff38d6f732efa2aede654 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 22 Oct 2021 23:17:25 +0200 Subject: bookmark-toot keybinding --- lisp/mastodon.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 387e9eb..57f5721 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -158,6 +158,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) (define-key map (kbd "v") #'mastodon-tl--poll-vote) + (define-key map (kbd "k") #'mastodon-toot--bookmark-toot) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) map) -- cgit v1.2.3 From f892c5b28b829943619a0e810903c426308aa174 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 23 Oct 2021 11:31:52 +0200 Subject: rewrite bookmark-toot as toggle --- lisp/mastodon-toot.el | 37 +++++++++++++++++-------------------- lisp/mastodon.el | 3 ++- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index cfc5182..983515e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -323,29 +323,26 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (setq mastodon-toot--content-warning-from-reply-or-redraft toot-cw)) (mastodon-toot--update-status-fields)))))))))) -(defun mastodon-toot--bookmark-toot () - "Bookmark toot at point synchronously." +(defun mastodon-toot--bookmark-toot-toggle () + "Bookmark or unbookmark toot at point synchronously." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/bookmark" id)))) - (if (y-or-n-p (format "Bookmark this toot? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot bookmarked!"))))))) - -(defun mastodon-toot--unbookmark-toot () - "Bookmark toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/unbookmark" id)))) - (if (y-or-n-p (format "Remove this toot from your bookmarks? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot unbookmarked!"))))))) + (bookmarked (cdr (assoc 'bookmarked toot))) + (url (mastodon-http--api (if (equal bookmarked t) + (format "statuses/%s/unbookmark" id) + (format "statuses/%s/bookmark" id)))) + (prompt (if (equal bookmarked t) + (format "Toot already bookmarked. Remove? ") + (format "Bookmark this toot? "))) + (message (if (equal bookmarked t) + "Bookmark removed!" + "Toot bookmarked!"))) + (when (y-or-n-p prompt) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message message))))))) (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 57f5721..7f4b773 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -82,6 +82,7 @@ (autoload 'mastodon-tl--poll-vote "mastodon-http") (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") +(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." @@ -158,7 +159,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) (define-key map (kbd "v") #'mastodon-tl--poll-vote) - (define-key map (kbd "k") #'mastodon-toot--bookmark-toot) + (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) map) -- cgit v1.2.3 From 998bfd60ed0ad1c4de161dd9a32c7786ee34b48a Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 28 Oct 2021 17:50:19 +0200 Subject: mastodon-async readme --- README.org | 4 ++-- lisp/mastodon.el | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index 7c9b18e..2455124 100644 --- a/README.org +++ b/README.org @@ -54,13 +54,13 @@ The minimum Emacs version is now 26.1. But if you are running an older version i I did this for my own use and to learn more Elisp. Feel free to improve it. -** live-updating timelines +** live-updating timelines: =mastodon-async-mode= (code taken from https://github.com/alexjgriffith/mastodon-future.el.) Works for federated, local, and home timelines and for notifications. It's pretty necro, sometimes it goes off the rails, so use at your own risk. Not a super high priority for me, but some people dig it. -To enable, run =mastodon-async-mode=. Then view a timeline with one of the commands that begin with =mastodon-async--stream=. +To enable, it, add =(require 'mastodon-async)= to your =init.el=. Then you can view a timeline with one of the commands that begin with =mastodon-async--stream-=. ** NB: dependency diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 7f4b773..25fb829 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -77,6 +77,7 @@ ;; (autoload 'mastodon-async--stream-local "mastodon-async") ;; (autoload 'mastodon-async--stream-home "mastodon-async") ;; (autoload 'mastodon-async--stream-notifications "mastodon-async") +;; (autoload 'mastodon-async-mode "mastodon-async") (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") -- cgit v1.2.3 From bceb7286a70dc90680bca4a9703db5d847b1e920 Mon Sep 17 00:00:00 2001 From: mousebot Date: Thu, 28 Oct 2021 19:01:42 +0200 Subject: require mastodon-toot in mastodon.el, for customize visibility - & no need for all other mastodon-toot autoloads --- lisp/mastodon.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 25fb829..159b9b2 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -31,6 +31,7 @@ ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon +(require 'mastodon-toot) ; hack to make mastodon-toot customs visible (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") @@ -51,10 +52,10 @@ (autoload 'mastodon-profile--get-toot-author "mastodon-profile") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--show-user "mastodon-profile") -(autoload 'mastodon-toot--compose-buffer "mastodon-toot") -(autoload 'mastodon-toot--reply "mastodon-toot") -(autoload 'mastodon-toot--toggle-boost "mastodon-toot") -(autoload 'mastodon-toot--toggle-favourite "mastodon-toot") +;; (autoload 'mastodon-toot--compose-buffer "mastodon-toot") +;; (autoload 'mastodon-toot--reply "mastodon-toot") +;; (autoload 'mastodon-toot--toggle-boost "mastodon-toot") +;; (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") (autoload 'mastodon-tl--block-user "mastodon-tl") @@ -69,9 +70,9 @@ (autoload 'mastodon-notifications--follow-request-accept-notifs "mastodon-profile") (autoload 'mastodon-notifications--follow-request-reject-notifs "mastodon-profile") (autoload 'mastodon-search--search-query "mastodon-search") -(autoload 'mastodon-toot--delete-toot "mastodon-toot") -(autoload 'mastodon-toot--copy-toot-url "mastodon-toot") -(autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") +;; (autoload 'mastodon-toot--delete-toot "mastodon-toot") +;; (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") +;; (autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") ;; (autoload 'mastodon-async--stream-federated "mastodon-async") ;; (autoload 'mastodon-async--stream-local "mastodon-async") @@ -81,9 +82,9 @@ (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") -(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") +;; (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") -(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") +;; (autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From e7c7da386c812f9452b072567e822077180f3dc5 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Mon, 1 Nov 2021 15:53:37 +0100 Subject: Fix tests. These needed a bit of tender love and care to get back into passing state. - Move the auth tests to the `test` directory. No idea what it was doing in `lisp`. - Image tests are mostly broken because with later Emacsen we no longer need the `imagemagic` option on create-image. - Some method signatures have changed and mocking calls needed to follow suit. --- Cask | 1 + lisp/mastodon-auth--test.el | 47 ------------------------------------- lisp/mastodon-http.el | 16 +++++++++---- lisp/mastodon-profile.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon.el | 2 +- test/ert-helper.el | 11 ++++++--- test/mastodon-auth-test.el | 47 +++++++++++++++++++++++++++++++++++++ test/mastodon-http-tests.el | 2 +- test/mastodon-media-tests.el | 34 ++++++++++++++++++--------- test/mastodon-notifications-test.el | 2 +- test/mastodon-tl-tests.el | 6 ++--- 12 files changed, 99 insertions(+), 73 deletions(-) delete mode 100644 lisp/mastodon-auth--test.el create mode 100644 test/mastodon-auth-test.el (limited to 'lisp/mastodon.el') diff --git a/Cask b/Cask index ebb7669..60a064c 100644 --- a/Cask +++ b/Cask @@ -4,6 +4,7 @@ (package-file "lisp/mastodon.el") (files "lisp/*.el") +(depends-on "request") (depends-on "seq") (development diff --git a/lisp/mastodon-auth--test.el b/lisp/mastodon-auth--test.el deleted file mode 100644 index 9a765b9..0000000 --- a/lisp/mastodon-auth--test.el +++ /dev/null @@ -1,47 +0,0 @@ -;;; mastodon-auth--test.el --- Tests for mastodon-auth -*- lexical-binding: t; -*- - -;; Copyright (C) 2020 Ian Eure - -;; Author: Ian Eure -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el -;; Package-Requires: ((emacs "26.1")) - -;; This file is not part of GNU Emacs. - -;; This file is part of mastodon.el. - -;; 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: - -;; mastodon-auth--test.el provides ERT tests for mastodon-auth.el - -;;; Code: - -(require 'ert) - -(ert-deftest mastodon-auth--handle-token-response--good () - (should (string= "foo" (mastodon-auth--handle-token-response '(:access_token "foo" :token_type "Bearer" :scope "read write follow" :created_at 0))))) - -(ert-deftest mastodon-auth--handle-token-response--unknown () - :expected-result :failed - (mastodon-auth--handle-token-response '(:herp "derp"))) - -(ert-deftest mastodon-auth--handle-token-response--failure () - :expected-result :failed - (mastodon-auth--handle-token-response '(:error "invalid_grant" :error_description "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."))) - -(provide 'mastodon-auth--test) -;;; mastodon-auth--test.el ends here diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 27f8ef0..875e9bf 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (request "0.2.0")) +;; Package-Requires: ((emacs "27.1") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -127,9 +127,17 @@ Pass response buffer to CALLBACK function." (url-request-extra-headers `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))) - (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) - (url-retrieve-synchronously url) - (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + (mastodon-http--url-retrieve-synchronously url))) + +(defun mastodon-http--url-retrieve-synchronously (url) + "Retrieve URL asynchronously. + +This is a thin abstraction over the system +`url-retrieve-synchronously`. Depending on which version of this +is available we will call it with or without a timeout." + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout))) (defun mastodon-http--get-json (url) "Make synchronous GET request to URL. Return JSON response." diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 22120fe..018af21 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (seq "1.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e5ded3f..3cb4ccb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1321,7 +1321,7 @@ JSON is the data returned from the server." (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. -UPDATE-FUNCTION is used to recieve more toots. +UPDATE-FUNCTION is used to receive more toots. Runs synchronously." (let* ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*")) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 159b9b2..d405bed 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (request "0.2.0") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (request "0.3.2") (seq "1.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/test/ert-helper.el b/test/ert-helper.el index 6979837..d3e0016 100644 --- a/test/ert-helper.el +++ b/test/ert-helper.el @@ -1,8 +1,13 @@ +(load-file "lisp/mastodon-async.el") (load-file "lisp/mastodon-http.el") -(load-file "lisp/mastodon-client.el") (load-file "lisp/mastodon-auth.el") -(load-file "lisp/mastodon-toot.el") +(load-file "lisp/mastodon-client.el") +(load-file "lisp/mastodon-discover.el") +(load-file "lisp/mastodon-inspect.el") (load-file "lisp/mastodon-media.el") -(load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-notifications.el") +(load-file "lisp/mastodon-profile.el") +(load-file "lisp/mastodon-search.el") +(load-file "lisp/mastodon-tl.el") +(load-file "lisp/mastodon-toot.el") (load-file "lisp/mastodon.el") diff --git a/test/mastodon-auth-test.el b/test/mastodon-auth-test.el new file mode 100644 index 0000000..9a765b9 --- /dev/null +++ b/test/mastodon-auth-test.el @@ -0,0 +1,47 @@ +;;; mastodon-auth--test.el --- Tests for mastodon-auth -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Ian Eure + +;; Author: Ian Eure +;; Version: 0.9.1 +;; Homepage: https://github.com/jdenen/mastodon.el +;; Package-Requires: ((emacs "26.1")) + +;; This file is not part of GNU Emacs. + +;; This file is part of mastodon.el. + +;; 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: + +;; mastodon-auth--test.el provides ERT tests for mastodon-auth.el + +;;; Code: + +(require 'ert) + +(ert-deftest mastodon-auth--handle-token-response--good () + (should (string= "foo" (mastodon-auth--handle-token-response '(:access_token "foo" :token_type "Bearer" :scope "read write follow" :created_at 0))))) + +(ert-deftest mastodon-auth--handle-token-response--unknown () + :expected-result :failed + (mastodon-auth--handle-token-response '(:herp "derp"))) + +(ert-deftest mastodon-auth--handle-token-response--failure () + :expected-result :failed + (mastodon-auth--handle-token-response '(:error "invalid_grant" :error_description "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."))) + +(provide 'mastodon-auth--test) +;;; mastodon-auth--test.el ends here diff --git a/test/mastodon-http-tests.el b/test/mastodon-http-tests.el index 972cedb..d0f715e 100644 --- a/test/mastodon-http-tests.el +++ b/test/mastodon-http-tests.el @@ -4,6 +4,6 @@ "Should make a `url-retrieve' of the given URL." (let ((callback-double (lambda () "double"))) (with-mock - (mock (url-retrieve-synchronously "https://foo.bar/baz")) + (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz")) (mock (mastodon-auth--access-token) => "test-token") (mastodon-http--get "https://foo.bar/baz")))) diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el index a586be9..20993f9 100644 --- a/test/mastodon-media-tests.el +++ b/test/mastodon-media-tests.el @@ -4,7 +4,7 @@ "Should return text with all expected properties." (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => :mock-image) + (mock (create-image * (when (version< emacs-version "27.1") 'imagemagick) t :height 123) => :mock-image) (let* ((mastodon-media--avatar-height 123) (result (mastodon-media--get-avatar-rendering "http://example.org/img.png")) @@ -37,12 +37,15 @@ (mastodon-media--avatar-height 123)) (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => '(image foo)) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) (mock (copy-marker 7) => :my-marker ) (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker (:height 123) 1)) + `(:my-marker (:height 123) 1 ,url)) => :called-as-expected) (with-temp-buffer @@ -62,7 +65,7 @@ (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker () 1)) + `(:my-marker () 1 ,url)) => :called-as-expected) (with-temp-buffer @@ -82,7 +85,7 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker (:max-height 321) 5)) + '(:my-marker (:max-height 321) 5 "http://example.org/image.png")) => :called-as-expected) (with-temp-buffer (insert (concat "Start:" @@ -101,7 +104,7 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker () 5)) + '(:my-marker () 5 "http://example.org/image.png")) => :called-as-expected) (with-temp-buffer @@ -117,7 +120,10 @@ (mastodon-media--avatar-height 123)) (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => '(image foo)) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) (stub url-retrieve => (error "url-retrieve failed")) (with-temp-buffer @@ -139,9 +145,11 @@ (insert "start:") (setq used-marker (copy-marker (point)) saved-marker (copy-marker (point))) - ;; Mock needed for the preliminary image created in mastodon-media--get-avatar-rendering + ;; Mock needed for the preliminary image created in + ;; mastodon-media--get-avatar-rendering (stub create-image => :fake-image) - (insert (mastodon-media--get-avatar-rendering "http://example.org/image.png") + (insert (mastodon-media--get-avatar-rendering + "http://example.org/image.png.") ":end") (with-temp-buffer (insert "some irrelevant\n" @@ -150,9 +158,13 @@ "fake\nimage\ndata") (goto-char (point-min)) - (mock (create-image "fake\nimage\ndata" 'imagemagick t ':image :option) => :fake-image) + (mock (create-image + "fake\nimage\ndata" + (when (version< emacs-version "27.1") 'imagemagick) + t ':image :option) => :fake-image) - (mastodon-media--process-image-response () used-marker '(:image :option) 1) + (mastodon-media--process-image-response + () used-marker '(:image :option) 1 "http://example.org/image.png") ;; the used marker has been unset: (should (null (marker-position used-marker))) diff --git a/test/mastodon-notifications-test.el b/test/mastodon-notifications-test.el index 19b591d..778d350 100644 --- a/test/mastodon-notifications-test.el +++ b/test/mastodon-notifications-test.el @@ -185,7 +185,7 @@ "Ensure get request format for notifictions is accurate." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json-async "https://instance.url/api/v1/notifications" 'mastodon-tl--init* "*mastodon-notifications*" "notifications" 'mastodon-notifications--timeline)) + (mock (mastodon-http--get-json "https://instance.url/api/v1/notifications" )) (mastodon-notifications--get)))) (defun mastodon-notifications--test-type (fun sample) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index c7dfc9a..24de5d0 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -285,7 +285,7 @@ a string or a numeric." (mastodon-tl--byline mastodon-tl-test-base-toot 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted)) - " Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -395,8 +395,8 @@ a string or a numeric." (mastodon-tl--byline toot 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted)) - " Account 42 (@acct42@example.space) - Boosted Account 43 (@acct43@example.space) original time + "Account 42 (@acct42@example.space) + Boosted Account 43 (@acct43@example.space) original time ------------ "))))) -- cgit v1.2.3 From 93950dbee4165c733fd8e0a4938fd7d0f462d908 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Tue, 2 Nov 2021 20:30:27 +0100 Subject: Reformat all code. Basically, in Emacs for each file: select all text and `indent-region`. - This also removes one redundant comment, and - fixes an error with json decoding where the `json-read-from-string` was actually not within the intended `unless` clause (which explains the warning about "result of (string-equal "" json-string) will be ignored" which I never understood. --- lisp/mastodon-async.el | 22 +- lisp/mastodon-http.el | 87 ++++---- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 4 +- lisp/mastodon-notifications.el | 68 +++--- lisp/mastodon-profile.el | 24 +-- lisp/mastodon-search.el | 78 +++---- lisp/mastodon-tl.el | 54 ++--- lisp/mastodon-toot.el | 106 ++++----- lisp/mastodon.el | 4 +- test/mastodon-auth-tests.el | 14 +- test/mastodon-client-tests.el | 64 +++--- test/mastodon-http-tests.el | 6 +- test/mastodon-media-tests.el | 266 +++++++++++------------ test/mastodon-notifications-test.el | 4 +- test/mastodon-tl-tests.el | 420 ++++++++++++++++++------------------ test/mastodon-toot-tests.el | 6 +- 17 files changed, 614 insertions(+), 615 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index f7bbdff..1fabee2 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -59,10 +59,10 @@ "The intermediate queue buffer name.") (defvar-local mastodon-async--buffer "" ;;"*mastodon-async-buffer*" - "User facing output buffer name.") + "User facing output buffer name.") (defvar-local mastodon-async--http-buffer "" ;;"" - "Buffer variable bound to http output.") + "Buffer variable bound to http output.") (defun mastodon-async--display-http () "Display the async HTTP input buffer." @@ -177,16 +177,16 @@ is not known when `mastodon-async--setup-buffer' is called." NAME is used to generate the display buffer and the queue." (let ((queue-name (concat " *mastodon-async-queue-" name "-" - mastodon-instance-url "*")) + mastodon-instance-url "*")) (buffer-name (concat "*mastodon-async-display-" name "-" - mastodon-instance-url "*"))) + mastodon-instance-url "*"))) (mastodon-async--set-local-variables http-buffer http-buffer buffer-name queue-name))) (defun mastodon-async--setup-queue (http-buffer name) "Sets up the buffer for the async queue." (let ((queue-name (concat " *mastodon-async-queue-" name "-" - mastodon-instance-url "*")) + mastodon-instance-url "*")) (buffer-name(concat "*mastodon-async-display-" name "-" mastodon-instance-url "*"))) (mastodon-async--set-local-variables queue-name http-buffer @@ -203,8 +203,8 @@ ENPOINT is the endpoint for the stream and timeline." mastodon-instance-url "*")) (buffer-name (concat "*mastodon-async-display-" name "-" mastodon-instance-url "*")) - ;; if user stream, we need "timelines/home" not "timelines/user" - ;; if notifs, we need "notifications" not "timelines/notifications" + ;; if user stream, we need "timelines/home" not "timelines/user" + ;; if notifs, we need "notifications" not "timelines/notifications" (endpoint (if (equal name "notifications") "notifications" (if (equal name "home") "timelines/home" (format "timelines/%s" endpoint))))) @@ -285,8 +285,8 @@ Filter the toots using FILTER." ;; NB notification events in streams include follow requests (let* ((split-strings (split-string string "\n" t)) (event-type (replace-regexp-in-string - "^event: " "" - (car split-strings))) + "^event: " "" + (car split-strings))) (data (replace-regexp-in-string "^data: " "" (cadr split-strings)))) (when (equal "notification" event-type) @@ -304,8 +304,8 @@ Filter the toots using FILTER." (defun mastodon-async--account-local-p (json) "Test JSON to see if account is local." (not (string-match-p - "@" - (cdr (assoc 'acct (cdr (assoc 'account json))))))) + "@" + (cdr (assoc 'acct (cdr (assoc 'account json))))))) (defun mastodon-async--output-toot (toot) "Process TOOT and prepend it to the async user-facing buffer." diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 875e9bf..a183ed7 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -153,8 +153,8 @@ is available we will call it with or without a timeout." (buffer-substring-no-properties (point) (point-max)) 'utf-8))) (kill-buffer) - (unless (or (string-equal "" json-string) (null json-string))) - (json-read-from-string json-string))) + (unless (or (string-equal "" json-string) (null json-string)) + (json-read-from-string json-string)))) (defun mastodon-http--delete (url) "Make DELETE request to URL." @@ -256,8 +256,8 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." args "&"))) (url-request-extra-headers - (append `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))) - headers))) + (append `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))) + headers))) (with-temp-buffer (url-retrieve url callback cbargs)))) @@ -269,46 +269,45 @@ The upload is asynchronous. On succeeding, item uploaded, and `mastodon-toot--update-status-fields' is run." (let* ((file (file-name-nondirectory filename)) (request-backend 'curl)) - ;; (response - (request - url - :type "POST" - :params `(("description" . ,caption)) - :files `(("file" . (,file :file ,filename - :mime-type "multipart/form-data"))) - :parser 'json-read - :headers `(("Authorization" . ,(concat "Bearer " - (mastodon-auth--access-token)))) - :sync t - :success (cl-function - (lambda (&key data &allow-other-keys) - (when data - (progn - (push (cdr (assoc 'id data)) - mastodon-toot--media-attachment-ids) ; add ID to list - (message "%s file %s with id %S and caption '%s' uploaded!" - (capitalize (cdr (assoc 'type data))) - file - (cdr (assoc 'id data)) - (cdr (assoc 'description data))) - (mastodon-toot--update-status-fields))))) - :error (cl-function - (lambda (&key error-thrown &allow-other-keys) - (cond - ;; handle curl errors first (eg 26, can't read file/path) - ;; because the '=' test below fails for them - ;; they have the form (error . error message 24) - ((not (proper-list-p error-thrown)) ; not dotted list - (message "Got error: %s. Shit went south." (cdr error-thrown))) - ;; handle mastodon api errors - ;; they have the form (error http 401) - ((= (car (last error-thrown)) 401) - (message "Got error: %s Unauthorized: The access token is invalid" error-thrown)) - ((= (car (last error-thrown)) 422) - (message "Got error: %s Unprocessable entity: file or file type is unsupported or invalid" error-thrown)) - (t - (message "Got error: %s Shit went south" - error-thrown)))))))) + (request + url + :type "POST" + :params `(("description" . ,caption)) + :files `(("file" . (,file :file ,filename + :mime-type "multipart/form-data"))) + :parser 'json-read + :headers `(("Authorization" . ,(concat "Bearer " + (mastodon-auth--access-token)))) + :sync t + :success (cl-function + (lambda (&key data &allow-other-keys) + (when data + (progn + (push (cdr (assoc 'id data)) + mastodon-toot--media-attachment-ids) ; add ID to list + (message "%s file %s with id %S and caption '%s' uploaded!" + (capitalize (cdr (assoc 'type data))) + file + (cdr (assoc 'id data)) + (cdr (assoc 'description data))) + (mastodon-toot--update-status-fields))))) + :error (cl-function + (lambda (&key error-thrown &allow-other-keys) + (cond + ;; handle curl errors first (eg 26, can't read file/path) + ;; because the '=' test below fails for them + ;; they have the form (error . error message 24) + ((not (proper-list-p error-thrown)) ; not dotted list + (message "Got error: %s. Shit went south." (cdr error-thrown))) + ;; handle mastodon api errors + ;; they have the form (error http 401) + ((= (car (last error-thrown)) 401) + (message "Got error: %s Unauthorized: The access token is invalid" error-thrown)) + ((= (car (last error-thrown)) 422) + (message "Got error: %s Unprocessable entity: file or file type is unsupported or invalid" error-thrown)) + (t + (message "Got error: %s Shit went south" + error-thrown)))))))) (provide 'mastodon-http) ;;; mastodon-http.el ends here diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 2181ea2..4647335 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -59,7 +59,7 @@ (concat "*mastodon-inspect-toot-" (mastodon-tl--as-string (mastodon-tl--property 'toot-id)) "*") - (mastodon-tl--property 'toot-json))) + (mastodon-tl--property 'toot-json))) (defun mastodon-inspect--download-single-toot (toot-id) "Download the toot/status represented by TOOT-ID." diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 5f8f46c..f7386c6 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -161,7 +161,7 @@ with the image." t image-options)))) (when mastodon-media--enable-image-caching (unless (url-is-cached url) ; cache if not already cached - (url-store-in-cache url-buffer))) + (url-store-in-cache url-buffer))) (with-current-buffer (marker-buffer marker) ;; Save narrowing in our buffer (let ((inhibit-read-only t)) @@ -239,7 +239,7 @@ found." ;; Avatars are just one character in the buffer ((eq media-type 'avatar) (list next-pos (+ next-pos 1) 'avatar)) - ;; Media links are 5 character ("[img]") + ;; Media links are 5 character ("[img]") ((eq media-type 'media-link) (list next-pos (+ next-pos 5) 'media-link))))))) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 36f9d4a..2430bcc 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -80,23 +80,23 @@ (let* ((toot-json (mastodon-tl--property 'toot-json)) (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) (if f-req-p - (let* ((account (cdr (assoc 'account toot-json))) - (id (cdr (assoc 'id account))) - (handle (cdr (assoc 'acct account))) - (name (cdr (assoc 'username account)))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/authorize" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (mastodon-notifications--get) - (message "Follow request of %s (@%s) accepted!" - name handle)))) - (message "No account result at point?"))) + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc 'username account)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/authorize" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (mastodon-notifications--get) + (message "Follow request of %s (@%s) accepted!" + name handle)))) + (message "No account result at point?"))) (message "No follow request at point?"))))) (defun mastodon-notifications--follow-request-reject-notifs () @@ -106,23 +106,23 @@ (let* ((toot-json (mastodon-tl--property 'toot-json)) (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) (if f-req-p - (let* ((account (cdr (assoc 'account toot-json))) - (id (cdr (assoc 'id account))) - (handle (cdr (assoc 'acct account))) - (name (cdr (assoc 'username account)))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/reject" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (mastodon-notifications--get) - (message "Follow request of %s (@%s) rejected!" - name handle)))) - (message "No account result at point?"))) + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc 'username account)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/reject" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (mastodon-notifications--get) + (message "Follow request of %s (@%s) rejected!" + name handle)))) + (message "No account result at point?"))) (message "No follow request at point?"))))) (defun mastodon-notifications--mention (note) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 31499ed..b68be6f 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -256,20 +256,20 @@ Returns a list of lists." (let* ((car-fields (mapcar 'car fields)) ;; (cdr-fields (mapcar 'cadr fields)) ;; (cdr-fields-rendered - ;; (list - ;; (mapcar (lambda (x) - ;; (mastodon-tl--render-text x nil)) - ;; cdr-fields))) + ;; (list + ;; (mapcar (lambda (x) + ;; (mastodon-tl--render-text x nil)) + ;; cdr-fields))) (left-width (car (sort (mapcar 'length car-fields) '>)))) - ;; (right-width (car (sort (mapcar 'length cdr-fields) '>)))) + ;; (right-width (car (sort (mapcar 'length cdr-fields) '>)))) (mapconcat (lambda (field) (mastodon-tl--render-text (concat (format "_ %s " (car field)) (make-string (- (+ 1 left-width) (length (car field))) ?_) (format " :: %s" (cadr field))) - ;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_) - ;; " |") + ;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_) + ;; " |") field)) ; nil)) ; hack to make links tabstops fields ""))) @@ -307,7 +307,7 @@ Returns a list of lists." account 'statuses_count))) (relationships (mastodon-profile--relationships-get id)) (followed-by-you (cdr (assoc 'following - (aref relationships 0)))) + (aref relationships 0)))) (follows-you (cdr (assoc 'followed_by (aref relationships 0)))) (followsp (or (equal follows-you 't) (equal followed-by-you 't))) @@ -327,9 +327,9 @@ Returns a list of lists." (is-followers (string= endpoint-type "followers")) (is-following (string= endpoint-type "following")) (endpoint-name (cond - (is-statuses " TOOTS ") - (is-followers " FOLLOWERS ") - (is-following " FOLLOWING ")))) + (is-statuses " TOOTS ") + (is-followers " FOLLOWERS ") + (is-following " FOLLOWING ")))) (insert "\n" (mastodon-profile--image-from-account account) @@ -382,7 +382,7 @@ Returns a list of lists." 'success)) (setq mastodon-tl--update-point (point)) (mastodon-media--inline-images (point-min) (point)) - ;; insert pinned toots first + ;; insert pinned toots first (when (and pinned (equal endpoint-type "statuses")) (mastodon-profile--insert-statuses-pinned pinned) (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 5f52bb7..cbb452d 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -80,7 +80,7 @@ Returns a nested list containing user handle, display name, and URL." (tags-list (mapcar #'mastodon-search--get-hashtag-info tags)) ;; (status-list (mapcar #'mastodon-search--get-status-info - ;; statuses)) + ;; statuses)) (status-ids-list (mapcar 'mastodon-search--get-id-from-status statuses)) (toots-list-json (mapcar #'mastodon-search--fetch-full-status-from-id @@ -97,42 +97,42 @@ Returns a nested list containing user handle, display name, and URL." " ------------\n\n") 'success)) (mapc (lambda (el) - (insert (propertize (car el) 'face 'mastodon-display-name-face) - " : \n : " - (propertize (concat "@" (car (cdr el))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (car (cdr el))) - 'help-echo (concat "Browse user profile of @" (car (cdr el)))) - " : \n" - "\n")) - user-ids) - ;; hashtag results: - (insert (mastodon-tl--set-face - (concat "\n ------------\n" - " HASHTAGS\n" - " ------------\n\n") - 'success)) - (mapc (lambda (el) - (insert " : #" - (propertize (car el) - 'mouse-face 'highlight - 'mastodon-tag (car el) - 'mastodon-tab-stop 'hashtag - 'help-echo (concat "Browse tag #" (car el)) - 'keymap mastodon-tl--link-keymap) - " : \n\n")) - tags-list) - ;; status results: - (insert (mastodon-tl--set-face - (concat "\n ------------\n" - " STATUSES\n" - " ------------\n") - 'success)) - (mapc 'mastodon-tl--toot toots-list-json) - (goto-char (point-min)))))) + (insert (propertize (car el) 'face 'mastodon-display-name-face) + " : \n : " + (propertize (concat "@" (car (cdr el))) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (car (cdr el))) + 'help-echo (concat "Browse user profile of @" (car (cdr el)))) + " : \n" + "\n")) + user-ids) + ;; hashtag results: + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " HASHTAGS\n" + " ------------\n\n") + 'success)) + (mapc (lambda (el) + (insert " : #" + (propertize (car el) + 'mouse-face 'highlight + 'mastodon-tag (car el) + 'mastodon-tab-stop 'hashtag + 'help-echo (concat "Browse tag #" (car el)) + 'keymap mastodon-tl--link-keymap) + " : \n\n")) + tags-list) + ;; status results: + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " STATUSES\n" + " ------------\n") + 'success)) + (mapc 'mastodon-tl--toot toots-list-json) + (goto-char (point-min)))))) (defun mastodon-search--get-user-info (account) "Get user handle, display name and account URL from ACCOUNT." @@ -153,7 +153,7 @@ Returns a nested list containing user handle, display name, and URL." (cdr (assoc 'content status)))) (defun mastodon-search--get-id-from-status (status) - "Fetch the id from a STATUS returned by a search call to the server. + "Fetch the id from a STATUS returned by a search call to the server. We use this to fetch the complete status from the server." (cdr (assoc 'id status))) @@ -164,7 +164,7 @@ We use this to fetch the complete status from the server." This allows us to access the full account etc. details and to render them properly." (let* ((url (concat mastodon-instance-url "/api/v1/statuses/" (mastodon-tl--as-string id))) - (json (mastodon-http--get-json url))) + (json (mastodon-http--get-json url))) json)) (provide 'mastodon-search) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e4c179c..d300a09 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -91,10 +91,10 @@ width fonts when rendering HTML text")) :type '(boolean :tag "Whether to display user avatars in timelines")) ;; (defvar mastodon-tl--show-avatars nil - ;; (if (version< emacs-version "27.1") - ;; (image-type-available-p 'imagemagick) - ;; (image-transforms-p)) - ;; "A boolean value stating whether to show avatars in timelines.") +;; (if (version< emacs-version "27.1") +;; (image-type-available-p 'imagemagick) +;; (image-transforms-p)) +;; "A boolean value stating whether to show avatars in timelines.") (defvar-local mastodon-tl--update-point nil "When updating a mastodon buffer this is where new toots will be inserted. @@ -463,7 +463,7 @@ START and END are the boundaries of the link in the toot." (url-instance (concat "https://" (url-host (url-generic-parse-url url)))) (maybe-userhandle (if (string= mastodon-instance-url url-instance) - ; if handle is local, then no instance suffix: + ; if handle is local, then no instance suffix: (buffer-substring-no-properties start end) (mastodon-tl--extract-userhandle-from-url url (buffer-substring-no-properties start end))))) @@ -652,12 +652,12 @@ message is a link which unhides/hides the main body." (mastodon-tl--render-text spoiler toot)) 'default)) (message (concat ;"\n" - " ---------------\n" - " " (mastodon-tl--make-link - (concat "CW: " string) - 'content-warning) - "\n" - " ---------------\n")) + " ---------------\n" + " " (mastodon-tl--make-link + (concat "CW: " string) + 'content-warning) + "\n" + " ---------------\n")) (cw (mastodon-tl--set-face message 'mastodon-cw-face))) (concat cw @@ -747,10 +747,10 @@ takes a single function. By default it is (concat "Poll: \n\n" (mapconcat (lambda (option) (progn - (format "Option %s: %s, %s votes.\n" - (setq option-counter (1+ option-counter)) - (cdr (assoc 'title option)) - (cdr (assoc 'votes_count option))))) + (format "Option %s: %s, %s votes.\n" + (setq option-counter (1+ option-counter)) + (cdr (assoc 'title option)) + (cdr (assoc 'votes_count option))))) options "\n") "\n"))) @@ -764,8 +764,8 @@ takes a single function. By default it is (mastodon-tl--field 'poll toot))) (options (mastodon-tl--field 'options poll)) (options-titles (mapcar (lambda (x) - (cdr (assoc 'title x))) - options)) + (cdr (assoc 'title x))) + options)) (options-number-seq (number-sequence 1 (length options))) (options-numbers (mapcar (lambda(x) (number-to-string x)) @@ -775,16 +775,16 @@ takes a single function. By default it is ;; but also store both as cons cell as cdr, as we need it below (candidates (mapcar (lambda (cell) (cons (format "%s | %s" (car cell) (cdr cell)) - cell)) + cell)) options-alist))) (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) (message "No poll here.") ;; var "option" = just the cdr, a cons of option number and desc (cdr (assoc (completing-read "Poll option to vote for: " - candidates - nil ; (predicate) - t) ; require match + candidates + nil ; (predicate) + t) ; require match candidates)))))) (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) (message "No poll here.") @@ -961,7 +961,7 @@ webapp" nil ; predicate 'confirm)))) (let* ((account (mastodon-profile--lookup-account-in-status - user-handle (mastodon-profile--toot-json))) + user-handle (mastodon-profile--toot-json))) (user-id (mastodon-profile--account-field account 'id)) (name (mastodon-profile--account-field account 'display_name)) (url (mastodon-http--api (format "accounts/%s/follow" user-id)))) @@ -983,7 +983,7 @@ webapp" nil ; predicate 'confirm)))) (let* ((account (mastodon-profile--lookup-account-in-status - user-handle (mastodon-profile--toot-json))) + user-handle (mastodon-profile--toot-json))) (user-id (mastodon-profile--account-field account 'id)) (name (mastodon-profile--account-field account 'display_name)) (url (mastodon-http--api (format "accounts/%s/unfollow" user-id)))) @@ -1006,7 +1006,7 @@ webapp" nil ; predicate 'confirm)))) (let* ((account (mastodon-profile--lookup-account-in-status - user-handle (mastodon-profile--toot-json))) + user-handle (mastodon-profile--toot-json))) (user-id (mastodon-profile--account-field account 'id)) (name (mastodon-profile--account-field account 'display_name)) (url (mastodon-http--api (format "accounts/%s/mute" user-id)))) @@ -1026,7 +1026,7 @@ webapp" (mutes-json (mastodon-http--get-json mutes-url)) (muted-accts (mapcar (lambda (muted) (cdr (assoc 'acct muted))) - mutes-json))) + mutes-json))) (completing-read "Handle of user to unmute: " muted-accts nil ; predicate @@ -1055,7 +1055,7 @@ webapp" nil ; predicate 'confirm)))) (let* ((account (mastodon-profile--lookup-account-in-status - user-handle (mastodon-profile--toot-json))) + user-handle (mastodon-profile--toot-json))) (user-id (mastodon-profile--account-field account 'id)) (name (mastodon-profile--account-field account 'display_name)) (url (mastodon-http--api (format "accounts/%s/block" user-id)))) @@ -1074,7 +1074,7 @@ webapp" (let* ((blocks-url (mastodon-http--api (format "blocks"))) (blocks-json (mastodon-http--get-json blocks-url)) (blocked-accts (mapcar (lambda (blocked) - (cdr (assoc 'acct blocked))) + (cdr (assoc 'acct blocked))) blocks-json))) (completing-read "Handle of user to unblock: " blocked-accts diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 07b52e3..22eb626 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -184,9 +184,9 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." "Take ACTION on toot at point, then execute CALLBACK." (let* ((id (mastodon-tl--property 'base-toot-id)) (url (mastodon-http--api (concat "statuses/" - (mastodon-tl--as-string id) - "/" - action)))) + (mastodon-tl--as-string id) + "/" + action)))) (let ((response (mastodon-http--post url nil nil))) (mastodon-http--triage response callback)))) @@ -312,7 +312,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (with-current-buffer response (let* ((json-response (mastodon-http--process-json)) (content (cdr (assoc 'text json-response)))) - ;; (media (cdr (assoc 'media_attachments json-response)))) + ;; (media (cdr (assoc 'media_attachments json-response)))) (mastodon-toot--compose-buffer nil nil) (goto-char (point-max)) (insert content) @@ -338,8 +338,8 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (format "Toot already bookmarked. Remove? ") (format "Bookmark this toot? "))) (message (if (equal bookmarked t) - "Bookmark removed!" - "Toot bookmarked!"))) + "Bookmark removed!" + "Toot bookmarked!"))) (when (y-or-n-p prompt) (let ((response (mastodon-http--post url nil nil))) (mastodon-http--triage response @@ -496,10 +496,10 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." "Extract mentions from STATUS and process them into a string." (interactive) (let* ((boosted (mastodon-tl--field 'reblog status)) - (mentions - (if boosted - (cdr (assoc 'mentions (cdr (assoc 'reblog status)))) - (cdr (assoc 'mentions status))))) + (mentions + (if boosted + (cdr (assoc 'mentions (cdr (assoc 'reblog status)))) + (cdr (assoc 'mentions status))))) (mapconcat (lambda(x) (mastodon-toot--process-local (cdr (assoc 'acct x)))) ;; reverse does not work on vectors in 24.5 @@ -534,19 +534,19 @@ The prefix can match against both user handles and display names." (defun mastodon-toot--mentions-completion (command &optional arg &rest ignored) "A company completion backend for toot mentions." - (interactive (list 'interactive)) - (cl-case command - (interactive (company-begin-backend 'mastodon-toot--mentions-completion)) - (prefix (when (and (bound-and-true-p mastodon-toot-mode) ; if masto toot minor mode - (save-excursion - (forward-whitespace -1) - (forward-whitespace 1) - (looking-at "@"))) - ;; @ + thing before point - (concat "@" (company-grab-symbol)))) - (candidates (mastodon-toot--mentions-company-candidates arg)) - (annotation (mastodon-toot--mentions-company-annotation arg)) - (meta (mastodon-toot--mentions-company-meta arg)))) + (interactive (list 'interactive)) + (cl-case command + (interactive (company-begin-backend 'mastodon-toot--mentions-completion)) + (prefix (when (and (bound-and-true-p mastodon-toot-mode) ; if masto toot minor mode + (save-excursion + (forward-whitespace -1) + (forward-whitespace 1) + (looking-at "@"))) + ;; @ + thing before point + (concat "@" (company-grab-symbol)))) + (candidates (mastodon-toot--mentions-company-candidates arg)) + (annotation (mastodon-toot--mentions-company-annotation arg)) + (meta (mastodon-toot--mentions-company-meta arg)))) (defun mastodon-toot--reply () "Reply to toot at `point'." @@ -803,38 +803,38 @@ REPLY-JSON is the full JSON of the toot being replied to." "Update the status fields in the header based on the current state." (ignore-errors ;; called from after-change-functions so let's not leak errors (let ((inhibit-read-only t) - (header-region (mastodon-tl--find-property-range 'toot-post-header + (header-region (mastodon-tl--find-property-range 'toot-post-header + (point-min))) + (count-region (mastodon-tl--find-property-range 'toot-post-counter (point-min))) - (count-region (mastodon-tl--find-property-range 'toot-post-counter + (visibility-region (mastodon-tl--find-property-range + 'toot-post-visibility (point-min))) + (nsfw-region (mastodon-tl--find-property-range 'toot-post-nsfw-flag (point-min))) - (visibility-region (mastodon-tl--find-property-range - 'toot-post-visibility (point-min))) - (nsfw-region (mastodon-tl--find-property-range 'toot-post-nsfw-flag - (point-min))) - (cw-region (mastodon-tl--find-property-range 'toot-post-cw-flag - (point-min)))) - (add-text-properties (car count-region) (cdr count-region) - (list 'display - (format "%s/%s characters" - (- (point-max) (cdr header-region)) - mastodon-toot--max-toot-chars))) - (add-text-properties (car visibility-region) (cdr visibility-region) - (list 'display - (format "Visibility: %s" - (if (equal - mastodon-toot--visibility - "private") - "followers-only" - mastodon-toot--visibility)))) - (add-text-properties (car nsfw-region) (cdr nsfw-region) - (list 'display (if mastodon-toot--content-nsfw - (if mastodon-toot--media-attachments - "NSFW" "NSFW (no effect until attachments added)") - "") - 'face 'mastodon-cw-face)) - (add-text-properties (car cw-region) (cdr cw-region) - (list 'invisible (not mastodon-toot--content-warning) - 'face 'mastodon-cw-face))))) + (cw-region (mastodon-tl--find-property-range 'toot-post-cw-flag + (point-min)))) + (add-text-properties (car count-region) (cdr count-region) + (list 'display + (format "%s/%s characters" + (- (point-max) (cdr header-region)) + mastodon-toot--max-toot-chars))) + (add-text-properties (car visibility-region) (cdr visibility-region) + (list 'display + (format "Visibility: %s" + (if (equal + mastodon-toot--visibility + "private") + "followers-only" + mastodon-toot--visibility)))) + (add-text-properties (car nsfw-region) (cdr nsfw-region) + (list 'display (if mastodon-toot--content-nsfw + (if mastodon-toot--media-attachments + "NSFW" "NSFW (no effect until attachments added)") + "") + 'face 'mastodon-cw-face)) + (add-text-properties (car cw-region) (cdr cw-region) + (list 'invisible (not mastodon-toot--content-warning) + 'face 'mastodon-cw-face))))) (defun mastodon-toot--compose-buffer (reply-to-user reply-to-id &optional reply-json) "Create a new buffer to capture text for a new toot. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index d405bed..826787a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -204,8 +204,8 @@ Use. e.g. \"%c\" for your locale's date and time format." "favourites" "search")) (buffer (cl-some (lambda (el) - (get-buffer (concat "*mastodon-" el "*"))) - tls))) ; return first buff that exists + (get-buffer (concat "*mastodon-" el "*"))) + tls))) ; return first buff that exists (if buffer (switch-to-buffer buffer) (mastodon-tl--get-home-timeline) diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 7daa4db..69c34a4 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -45,10 +45,10 @@ "Should generate token and return JSON response." (with-temp-buffer (with-mock - (mock (mastodon-auth--generate-token) => (progn - (insert "\n\n{\"access_token\":\"abcdefg\"}") - (current-buffer))) - (should (equal (mastodon-auth--get-token) '(:access_token "abcdefg")))))) + (mock (mastodon-auth--generate-token) => (progn + (insert "\n\n{\"access_token\":\"abcdefg\"}") + (current-buffer))) + (should (equal (mastodon-auth--get-token) '(:access_token "abcdefg")))))) (ert-deftest access-token-found () "Should return value in `mastodon-auth--token-alist' if found." @@ -61,6 +61,6 @@ (let ((mastodon-instance-url "https://instance.url") (mastodon-auth--token nil)) (with-mock - (mock (mastodon-auth--get-token) => '(:access_token "foobaz")) - (should (string= (mastodon-auth--access-token) "foobaz")) - (should (equal mastodon-auth--token-alist '(("https://instance.url" . "foobaz"))))))) + (mock (mastodon-auth--get-token) => '(:access_token "foobaz")) + (should (string= (mastodon-auth--access-token) "foobaz")) + (should (equal mastodon-auth--token-alist '(("https://instance.url" . "foobaz"))))))) diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index dfe175b..d7f750d 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -17,30 +17,30 @@ "Should return client registration JSON." (with-temp-buffer (with-mock - (mock (mastodon-client--register) => (progn - (insert "\n\n{\"foo\":\"bar\"}") - (current-buffer))) - (should (equal (mastodon-client--fetch) '(:foo "bar")))))) + (mock (mastodon-client--register) => (progn + (insert "\n\n{\"foo\":\"bar\"}") + (current-buffer))) + (should (equal (mastodon-client--fetch) '(:foo "bar")))))) (ert-deftest store-1 () "Should return the client plist." (let ((mastodon-instance-url "http://mastodon.example") (plist '(:client_id "id" :client_secret "secret"))) (with-mock - (mock (mastodon-client--token-file) => "stubfile.plstore") - (mock (mastodon-client--fetch) => '(:client_id "id" :client_secret "secret")) - (let* ((plstore (plstore-open "stubfile.plstore")) - (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) - (should (equal (mastodon-client--store) plist)))))) + (mock (mastodon-client--token-file) => "stubfile.plstore") + (mock (mastodon-client--fetch) => '(:client_id "id" :client_secret "secret")) + (let* ((plstore (plstore-open "stubfile.plstore")) + (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) + (should (equal (mastodon-client--store) plist)))))) (ert-deftest store-2 () - "Should store client in `mastodon-client--token-file'." - (let* ((mastodon-instance-url "http://mastodon.example") - (plstore (plstore-open "stubfile.plstore")) - (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) - (plstore-close plstore) - (should (string= (plist-get client :client_id) "id")) - (should (string= (plist-get client :client_secret) "secret")))) + "Should store client in `mastodon-client--token-file'." + (let* ((mastodon-instance-url "http://mastodon.example") + (plstore (plstore-open "stubfile.plstore")) + (client (cdr (plstore-get plstore "mastodon-http://mastodon.example")))) + (plstore-close plstore) + (should (string= (plist-get client :client_id) "id")) + (should (string= (plist-get client :client_secret) "secret")))) (ert-deftest read-finds-match () "Should return mastodon client from `mastodon-token-file' if it exists." @@ -60,8 +60,8 @@ (ert-deftest read-empty-store () "Should return nil if mastodon client is not present in the plstore." (with-mock - (mock (mastodon-client--token-file) => "fixture/empty.plstore") - (should (equal (mastodon-client--read) nil)))) + (mock (mastodon-client--token-file) => "fixture/empty.plstore") + (should (equal (mastodon-client--read) nil)))) (ert-deftest client-set-and-matching () "Should return `mastondon-client' if `mastodon-client--client-details-alist' is non-nil and instance url is included." @@ -75,29 +75,29 @@ (let ((mastodon-instance-url "http://mastodon.example") (mastodon-client--client-details-alist '(("http://other.example" :wrong)))) (with-mock - (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar")) - (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar"))) - (should (equal mastodon-client--client-details-alist - '(("http://mastodon.example" :client_id "foo" :client_secret "bar") - ("http://other.example" :wrong))))))) + (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar")) + (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar"))) + (should (equal mastodon-client--client-details-alist + '(("http://mastodon.example" :client_id "foo" :client_secret "bar") + ("http://other.example" :wrong))))))) (ert-deftest client-unset () "Should read from `mastodon-token-file' if available." (let ((mastodon-instance-url "http://mastodon.example") (mastodon-client--client-details-alist nil)) (with-mock - (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar")) - (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar"))) - (should (equal mastodon-client--client-details-alist - '(("http://mastodon.example" :client_id "foo" :client_secret "bar"))))))) + (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar")) + (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar"))) + (should (equal mastodon-client--client-details-alist + '(("http://mastodon.example" :client_id "foo" :client_secret "bar"))))))) (ert-deftest client-unset-and-not-in-storage () "Should store client data in plstore if it can't be read." (let ((mastodon-instance-url "http://mastodon.example") (mastodon-client--client-details-alist nil)) (with-mock - (mock (mastodon-client--read)) - (mock (mastodon-client--store) => '(:client_id "foo" :client_secret "baz")) - (should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz"))) - (should (equal mastodon-client--client-details-alist - '(("http://mastodon.example" :client_id "foo" :client_secret "baz"))))))) + (mock (mastodon-client--read)) + (mock (mastodon-client--store) => '(:client_id "foo" :client_secret "baz")) + (should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz"))) + (should (equal mastodon-client--client-details-alist + '(("http://mastodon.example" :client_id "foo" :client_secret "baz"))))))) diff --git a/test/mastodon-http-tests.el b/test/mastodon-http-tests.el index d0f715e..03d4f94 100644 --- a/test/mastodon-http-tests.el +++ b/test/mastodon-http-tests.el @@ -4,6 +4,6 @@ "Should make a `url-retrieve' of the given URL." (let ((callback-double (lambda () "double"))) (with-mock - (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz")) - (mock (mastodon-auth--access-token) => "test-token") - (mastodon-http--get "https://foo.bar/baz")))) + (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz")) + (mock (mastodon-auth--access-token) => "test-token") + (mastodon-http--get "https://foo.bar/baz")))) diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el index 20993f9..b537dfe 100644 --- a/test/mastodon-media-tests.el +++ b/test/mastodon-media-tests.el @@ -3,143 +3,143 @@ (ert-deftest mastodon-media:get-avatar-rendering () "Should return text with all expected properties." (with-mock - (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * (when (version< emacs-version "27.1") 'imagemagick) t :height 123) => :mock-image) - - (let* ((mastodon-media--avatar-height 123) - (result (mastodon-media--get-avatar-rendering "http://example.org/img.png")) - (result-no-properties (substring-no-properties result)) - (properties (text-properties-at 0 result))) - (should (string= " " result-no-properties)) - (should (string= "http://example.org/img.png" (plist-get properties 'media-url))) - (should (eq 'needs-loading (plist-get properties 'media-state))) - (should (eq 'avatar (plist-get properties 'media-type))) - (should (eq :mock-image (plist-get properties 'display)))))) + (mock (image-type-available-p 'imagemagick) => t) + (mock (create-image * (when (version< emacs-version "27.1") 'imagemagick) t :height 123) => :mock-image) + + (let* ((mastodon-media--avatar-height 123) + (result (mastodon-media--get-avatar-rendering "http://example.org/img.png")) + (result-no-properties (substring-no-properties result)) + (properties (text-properties-at 0 result))) + (should (string= " " result-no-properties)) + (should (string= "http://example.org/img.png" (plist-get properties 'media-url))) + (should (eq 'needs-loading (plist-get properties 'media-state))) + (should (eq 'avatar (plist-get properties 'media-type))) + (should (eq :mock-image (plist-get properties 'display)))))) (ert-deftest mastodon-media:get-media-link-rendering () "Should return text with all expected properties." (with-mock - (mock (create-image * nil t) => :mock-image) - - (let* ((mastodon-media--preview-max-height 123) - (result (mastodon-media--get-media-link-rendering "http://example.org/img.png")) - (result-no-properties (substring-no-properties result)) - (properties (text-properties-at 0 result))) - (should (string= "[img] " result-no-properties)) - (should (string= "http://example.org/img.png" (plist-get properties 'media-url))) - (should (eq 'needs-loading (plist-get properties 'media-state))) - (should (eq 'media-link (plist-get properties 'media-type))) - (should (eq :mock-image (plist-get properties 'display)))))) + (mock (create-image * nil t) => :mock-image) + + (let* ((mastodon-media--preview-max-height 123) + (result (mastodon-media--get-media-link-rendering "http://example.org/img.png")) + (result-no-properties (substring-no-properties result)) + (properties (text-properties-at 0 result))) + (should (string= "[img] " result-no-properties)) + (should (string= "http://example.org/img.png" (plist-get properties 'media-url))) + (should (eq 'needs-loading (plist-get properties 'media-state))) + (should (eq 'media-link (plist-get properties 'media-type))) + (should (eq :mock-image (plist-get properties 'display)))))) (ert-deftest mastodon-media:load-image-from-url:avatar-with-imagemagic () "Should make the right call to url-retrieve." (let ((url "http://example.org/image.png") (mastodon-media--avatar-height 123)) (with-mock - (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image - * - (when (version< emacs-version "27.1") 'imagemagick) - t :height 123) => '(image foo)) - (mock (copy-marker 7) => :my-marker ) - (mock (url-retrieve - url - #'mastodon-media--process-image-response - `(:my-marker (:height 123) 1 ,url)) - => :called-as-expected) - - (with-temp-buffer - (insert (concat "Start:" - (mastodon-media--get-avatar-rendering "http://example.org/img.png") - ":rest")) - - (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'avatar 7 1))))))) + (mock (image-type-available-p 'imagemagick) => t) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) + (mock (copy-marker 7) => :my-marker ) + (mock (url-retrieve + url + #'mastodon-media--process-image-response + `(:my-marker (:height 123) 1 ,url)) + => :called-as-expected) + + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-avatar-rendering "http://example.org/img.png") + ":rest")) + + (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'avatar 7 1))))))) (ert-deftest mastodon-media:load-image-from-url:avatar-without-imagemagic () "Should make the right call to url-retrieve." (let ((url "http://example.org/image.png")) (with-mock - (mock (image-type-available-p 'imagemagick) => nil) - (mock (create-image * nil t) => '(image foo)) - (mock (copy-marker 7) => :my-marker ) - (mock (url-retrieve - url - #'mastodon-media--process-image-response - `(:my-marker () 1 ,url)) - => :called-as-expected) - - (with-temp-buffer - (insert (concat "Start:" - (mastodon-media--get-avatar-rendering "http://example.org/img.png") - ":rest")) - - (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'avatar 7 1))))))) + (mock (image-type-available-p 'imagemagick) => nil) + (mock (create-image * nil t) => '(image foo)) + (mock (copy-marker 7) => :my-marker ) + (mock (url-retrieve + url + #'mastodon-media--process-image-response + `(:my-marker () 1 ,url)) + => :called-as-expected) + + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-avatar-rendering "http://example.org/img.png") + ":rest")) + + (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'avatar 7 1))))))) (ert-deftest mastodon-media:load-image-from-url:media-link-with-imagemagic () "Should make the right call to url-retrieve." (let ((url "http://example.org/image.png")) (with-mock - (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * nil t) => '(image foo)) - (mock (copy-marker 7) => :my-marker ) - (mock (url-retrieve - "http://example.org/image.png" - #'mastodon-media--process-image-response - '(:my-marker (:max-height 321) 5 "http://example.org/image.png")) - => :called-as-expected) - (with-temp-buffer - (insert (concat "Start:" - (mastodon-media--get-media-link-rendering url) - ":rest")) - (let ((mastodon-media--preview-max-height 321)) - (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) + (mock (image-type-available-p 'imagemagick) => t) + (mock (create-image * nil t) => '(image foo)) + (mock (copy-marker 7) => :my-marker ) + (mock (url-retrieve + "http://example.org/image.png" + #'mastodon-media--process-image-response + '(:my-marker (:max-height 321) 5 "http://example.org/image.png")) + => :called-as-expected) + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-media-link-rendering url) + ":rest")) + (let ((mastodon-media--preview-max-height 321)) + (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) (ert-deftest mastodon-media:load-image-from-url:media-link-without-imagemagic () "Should make the right call to url-retrieve." (let ((url "http://example.org/image.png")) (with-mock - (mock (image-type-available-p 'imagemagick) => nil) - (mock (create-image * nil t) => '(image foo)) - (mock (copy-marker 7) => :my-marker ) - (mock (url-retrieve - "http://example.org/image.png" - #'mastodon-media--process-image-response - '(:my-marker () 5 "http://example.org/image.png")) - => :called-as-expected) - - (with-temp-buffer - (insert (concat "Start:" - (mastodon-media--get-avatar-rendering url) - ":rest")) - (let ((mastodon-media--preview-max-height 321)) - (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) + (mock (image-type-available-p 'imagemagick) => nil) + (mock (create-image * nil t) => '(image foo)) + (mock (copy-marker 7) => :my-marker ) + (mock (url-retrieve + "http://example.org/image.png" + #'mastodon-media--process-image-response + '(:my-marker () 5 "http://example.org/image.png")) + => :called-as-expected) + + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-avatar-rendering url) + ":rest")) + (let ((mastodon-media--preview-max-height 321)) + (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) (ert-deftest mastodon-media:load-image-from-url:url-fetching-fails () "Should cope with failures in url-retrieve." (let ((url "http://example.org/image.png") (mastodon-media--avatar-height 123)) (with-mock - (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image - * - (when (version< emacs-version "27.1") 'imagemagick) - t :height 123) => '(image foo)) - (stub url-retrieve => (error "url-retrieve failed")) - - (with-temp-buffer - (insert (concat "Start:" - (mastodon-media--get-avatar-rendering "http://example.org/img.png") - ":rest")) - - (should (eq :loading-failed (mastodon-media--load-image-from-url url 'avatar 7 1))) - ;; the media state was updated so we won't load this again: - (should (eq 'loading-failed (get-text-property 7 'media-state))))))) + (mock (image-type-available-p 'imagemagick) => t) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) + (stub url-retrieve => (error "url-retrieve failed")) + + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-avatar-rendering "http://example.org/img.png") + ":rest")) + + (should (eq :loading-failed (mastodon-media--load-image-from-url url 'avatar 7 1))) + ;; the media state was updated so we won't load this again: + (should (eq 'loading-failed (get-text-property 7 'media-state))))))) (ert-deftest mastodon-media:process-image-response () "Should process the HTTP response and adjust the source buffer." (with-temp-buffer (with-mock - (let ((source-buffer (current-buffer)) + (let ((source-buffer (current-buffer)) used-marker saved-marker) (insert "start:") @@ -175,35 +175,35 @@ (ert-deftest mastodon-media:inline-images () "Should process all media in buffer." (with-mock - ;; Stub needed for the test setup: - (stub create-image => '(image ignored)) - - (let (marker-media-link marker-media-link-bad-url marker-false-media marker-avatar) - (with-temp-buffer - (insert "Some text before\n") - (setq marker-media-link (copy-marker (point))) - (insert (mastodon-media--get-media-link-rendering "http://example.org/i.jpg") - " some more text ") - (setq marker-media-link-bad-url (copy-marker (point))) - (insert (mastodon-media--get-media-link-rendering "/files/small/missing.png") - " some more text ") - (setq marker-false-media (copy-marker (point))) - (insert - ;; text that looks almost like an avatar but lacks the media-url property - (propertize "this won't be processed" - 'media-state 'needs-loading - 'media-type 'avatar) - "even more text ") - (setq marker-avatar (copy-marker (point))) - (insert (mastodon-media--get-avatar-rendering "http://example.org/avatar.png") - " end of text") - (goto-char (point-min)) - - ;; stub for the actual test: - (stub mastodon-media--load-image-from-url) - (mastodon-media--inline-images (point-min) (point-max)) - - (should (eq 'loading (get-text-property marker-media-link 'media-state))) - (should (eq 'invalid-url (get-text-property marker-media-link-bad-url 'media-state))) - (should (eq 'loading (get-text-property marker-avatar 'media-state))) - (should (eq 'needs-loading (get-text-property marker-false-media 'media-state))))))) + ;; Stub needed for the test setup: + (stub create-image => '(image ignored)) + + (let (marker-media-link marker-media-link-bad-url marker-false-media marker-avatar) + (with-temp-buffer + (insert "Some text before\n") + (setq marker-media-link (copy-marker (point))) + (insert (mastodon-media--get-media-link-rendering "http://example.org/i.jpg") + " some more text ") + (setq marker-media-link-bad-url (copy-marker (point))) + (insert (mastodon-media--get-media-link-rendering "/files/small/missing.png") + " some more text ") + (setq marker-false-media (copy-marker (point))) + (insert + ;; text that looks almost like an avatar but lacks the media-url property + (propertize "this won't be processed" + 'media-state 'needs-loading + 'media-type 'avatar) + "even more text ") + (setq marker-avatar (copy-marker (point))) + (insert (mastodon-media--get-avatar-rendering "http://example.org/avatar.png") + " end of text") + (goto-char (point-min)) + + ;; stub for the actual test: + (stub mastodon-media--load-image-from-url) + (mastodon-media--inline-images (point-min) (point-max)) + + (should (eq 'loading (get-text-property marker-media-link 'media-state))) + (should (eq 'invalid-url (get-text-property marker-media-link-bad-url 'media-state))) + (should (eq 'loading (get-text-property marker-avatar 'media-state))) + (should (eq 'needs-loading (get-text-property marker-false-media 'media-state))))))) diff --git a/test/mastodon-notifications-test.el b/test/mastodon-notifications-test.el index 778d350..3047ae6 100644 --- a/test/mastodon-notifications-test.el +++ b/test/mastodon-notifications-test.el @@ -185,8 +185,8 @@ "Ensure get request format for notifictions is accurate." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json "https://instance.url/api/v1/notifications" )) - (mastodon-notifications--get)))) + (mock (mastodon-http--get-json "https://instance.url/api/v1/notifications" )) + (mastodon-notifications--get)))) (defun mastodon-notifications--test-type (fun sample) "Test notification draw functions. diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index 24de5d0..4edf5d5 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -114,19 +114,19 @@ (ert-deftest as-string-1 () "Should accept a string or number and return a string." (let ((id "1000")) - (should (string= (mastodon-tl--as-string id) id)))) + (should (string= (mastodon-tl--as-string id) id)))) (ert-deftest as-string-2 () "Should accept a string or number and return a string." (let ((id 1000)) - (should (string= (mastodon-tl--as-string id) (number-to-string id))))) + (should (string= (mastodon-tl--as-string id) (number-to-string id))))) (ert-deftest more-json () "Should request toots older than max_id." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345")) - (mastodon-tl--more-json "timelines/foo" 12345)))) + (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345")) + (mastodon-tl--more-json "timelines/foo" 12345)))) (ert-deftest more-json-id-string () "Should request toots older than max_id. @@ -135,8 +135,8 @@ a string or a numeric." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345")) - (mastodon-tl--more-json "timelines/foo" "12345")))) + (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345")) + (mastodon-tl--more-json "timelines/foo" "12345")))) (ert-deftest update-json-id-string () "Should request toots more recent than since_id. @@ -145,8 +145,8 @@ a string or a numeric." a string or a numeric." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?since_id=12345")) - (mastodon-tl--updated-json "timelines/foo" "12345")))) + (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?since_id=12345")) + (mastodon-tl--updated-json "timelines/foo" "12345")))) (ert-deftest mastodon-tl--relative-time-description () "Should format relative time as expected" @@ -156,10 +156,10 @@ a string or a numeric." (weeks (n) (* n (days 7))) (years (n) (* n (days 365))) (format-seconds-since (seconds) - (let ((timestamp (time-subtract (current-time) (seconds-to-time seconds)))) - (mastodon-tl--relative-time-description timestamp))) + (let ((timestamp (time-subtract (current-time) (seconds-to-time seconds)))) + (mastodon-tl--relative-time-description timestamp))) (check (seconds expected) - (should (string= (format-seconds-since seconds) expected)))) + (should (string= (format-seconds-since seconds) expected)))) (check 1 "less than a minute ago") (check 59 "less than a minute ago") (check 60 "one minute ago") @@ -195,33 +195,33 @@ a string or a numeric." (weeks (n) (* n (days 7))) (years (n) (* n (days 365.25))) (next-update (seconds-ago) - (let* ((timestamp (time-subtract current-time - (seconds-to-time seconds-ago)))) - (cdr (mastodon-tl--relative-time-details timestamp current-time)))) + (let* ((timestamp (time-subtract current-time + (seconds-to-time seconds-ago)))) + (cdr (mastodon-tl--relative-time-details timestamp current-time)))) (check (seconds-ago) - (let* ((timestamp (time-subtract current-time (seconds-to-time seconds-ago))) - (at-now (mastodon-tl--relative-time-description timestamp current-time)) - (at-one-second-before (mastodon-tl--relative-time-description - timestamp - (time-subtract (next-update seconds-ago) - (seconds-to-time 1)))) - (at-result (mastodon-tl--relative-time-description - timestamp - (next-update seconds-ago)))) - (when nil ;; change to t to debug test failures - (prin1 (format "\nFor %s: %s / %s" - seconds-ago - (time-to-seconds - (time-subtract (next-update seconds-ago) - timestamp)) - (round - (time-to-seconds - (time-subtract (next-update seconds-ago) - current-time)))))) - ;; a second earlier the description is the same as at current time - (should (string= at-now at-one-second-before)) - ;; but at the result time it is different - (should-not (string= at-one-second-before at-result))))) + (let* ((timestamp (time-subtract current-time (seconds-to-time seconds-ago))) + (at-now (mastodon-tl--relative-time-description timestamp current-time)) + (at-one-second-before (mastodon-tl--relative-time-description + timestamp + (time-subtract (next-update seconds-ago) + (seconds-to-time 1)))) + (at-result (mastodon-tl--relative-time-description + timestamp + (next-update seconds-ago)))) + (when nil ;; change to t to debug test failures + (prin1 (format "\nFor %s: %s / %s" + seconds-ago + (time-to-seconds + (time-subtract (next-update seconds-ago) + timestamp)) + (round + (time-to-seconds + (time-subtract (next-update seconds-ago) + current-time)))))) + ;; a second earlier the description is the same as at current time + (should (string= at-now at-one-second-before)) + ;; but at the result time it is different + (should-not (string= at-one-second-before at-result))))) (check 0) (check 1) (check 59) @@ -253,39 +253,39 @@ a string or a numeric." (let ((mastodon-tl--show-avatars-p nil) (timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot)))) (with-mock - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (let ((byline (mastodon-tl--byline mastodon-tl-test-base-toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - (handle-location 20)) - (should (string= (substring-no-properties - byline) - "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (let ((byline (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + (handle-location 20)) + (should (string= (substring-no-properties + byline) + "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ ")) - (should (eq (get-text-property handle-location 'mastodon-tab-stop byline) - 'user-handle)) - (should (string= (get-text-property handle-location 'mastodon-handle byline) - "@acct42@example.space")) - (should (equal (get-text-property handle-location 'help-echo byline) - "Browse user profile of @acct42@example.space")))))) + (should (eq (get-text-property handle-location 'mastodon-tab-stop byline) + 'user-handle)) + (should (string= (get-text-property handle-location 'mastodon-handle byline) + "@acct42@example.space")) + (should (equal (get-text-property handle-location 'help-echo byline) + "Browse user profile of @acct42@example.space")))))) (ert-deftest mastodon-tl--byline-regular-with-avatar () "Should format the regular toot correctly." (let ((mastodon-tl--show-avatars-p t) (timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot)))) (with-mock - (stub create-image => '(image "fake data")) - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (should (string= (substring-no-properties - (mastodon-tl--byline mastodon-tl-test-base-toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + (stub create-image => '(image "fake data")) + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (should (string= (substring-no-properties + (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -295,14 +295,14 @@ a string or a numeric." (toot (cons '(reblogged . t) mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (should (string= (substring-no-properties - (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - "(B) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + "(B) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -312,14 +312,14 @@ a string or a numeric." (toot (cons '(favourited . t) mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (should (string= (substring-no-properties - (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - "(F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + "(F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -330,14 +330,14 @@ a string or a numeric." (toot `((favourited . t) (reblogged . t) ,@mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (should (string= (substring-no-properties - (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - "(B) (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + "(B) (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -349,31 +349,31 @@ a string or a numeric." (timestamp (cdr (assoc 'created_at toot))) (original-timestamp (cdr (assoc 'created_at original-toot)))) (with-mock - ;; We don't expect to use the toot's timestamp but the timestamp of the - ;; reblogged toot: - (mock (date-to-time timestamp) => '(1 2)) - (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") - (mock (date-to-time original-timestamp) => '(3 4)) - (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - - (let ((byline (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - (handle1-location 20) - (handle2-location 65)) - (should (string= (substring-no-properties byline) - "Account 42 (@acct42@example.space) + ;; We don't expect to use the toot's timestamp but the timestamp of the + ;; reblogged toot: + (mock (date-to-time timestamp) => '(1 2)) + (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") + (mock (date-to-time original-timestamp) => '(3 4)) + (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") + + (let ((byline (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + (handle1-location 20) + (handle2-location 65)) + (should (string= (substring-no-properties byline) + "Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------ ")) - (should (eq (get-text-property handle1-location 'mastodon-tab-stop byline) - 'user-handle)) - (should (equal (get-text-property handle1-location 'help-echo byline) - "Browse user profile of @acct42@example.space")) - (should (eq (get-text-property handle2-location 'mastodon-tab-stop byline) - 'user-handle)) - (should (equal (get-text-property handle2-location 'help-echo byline) - "Browse user profile of @acct43@example.space")))))) + (should (eq (get-text-property handle1-location 'mastodon-tab-stop byline) + 'user-handle)) + (should (equal (get-text-property handle1-location 'help-echo byline) + "Browse user profile of @acct42@example.space")) + (should (eq (get-text-property handle2-location 'mastodon-tab-stop byline) + 'user-handle)) + (should (equal (get-text-property handle2-location 'help-echo byline) + "Browse user profile of @acct43@example.space")))))) (ert-deftest mastodon-tl--byline-reblogged-with-avatars () "Should format the reblogged toot correctly." @@ -383,19 +383,19 @@ a string or a numeric." (timestamp (cdr (assoc 'created_at toot))) (original-timestamp (cdr (assoc 'created_at original-toot)))) (with-mock - ;; We don't expect to use the toot's timestamp but the timestamp of the - ;; reblogged toot: - (stub create-image => '(image "fake data")) - (mock (date-to-time timestamp) => '(1 2)) - (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") - (mock (date-to-time original-timestamp) => '(3 4)) - (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - - (should (string= (substring-no-properties - (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - "Account 42 (@acct42@example.space) + ;; We don't expect to use the toot's timestamp but the timestamp of the + ;; reblogged toot: + (stub create-image => '(image "fake data")) + (mock (date-to-time timestamp) => '(1 2)) + (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") + (mock (date-to-time original-timestamp) => '(3 4)) + (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") + + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + "Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------ "))))) @@ -408,17 +408,17 @@ a string or a numeric." (timestamp (cdr (assoc 'created_at toot))) (original-timestamp (cdr (assoc 'created_at original-toot)))) (with-mock - ;; We don't expect to use the toot's timestamp but the timestamp of the - ;; reblogged toot: - (mock (date-to-time timestamp) => '(1 2)) - (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") - (mock (date-to-time original-timestamp) => '(3 4)) - (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - - (should (string= (substring-no-properties - (mastodon-tl--byline toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) + ;; We don't expect to use the toot's timestamp but the timestamp of the + ;; reblogged toot: + (mock (date-to-time timestamp) => '(1 2)) + (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time") + (mock (date-to-time original-timestamp) => '(3 4)) + (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") + + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) "(B) (F) Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------ @@ -429,17 +429,17 @@ a string or a numeric." (let ((mastodon-tl--show-avatars-p nil) (timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot)))) (with-mock - (mock (date-to-time timestamp) => '(22782 21551)) - (mock (current-time) => '(22782 22000)) - (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - - (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot - 'mastodon-tl--byline-author - 'mastodon-tl--byline-boosted)) - (timestamp-start (string-match "2999-99-99" formatted-string)) - (properties (text-properties-at timestamp-start formatted-string))) - (should (equal '(22782 21551) (plist-get properties 'timestamp))) - (should (string-equal "7 minutes ago" (plist-get properties 'display))))))) + (mock (date-to-time timestamp) => '(22782 21551)) + (mock (current-time) => '(22782 22000)) + (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") + + (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) + (timestamp-start (string-match "2999-99-99" formatted-string)) + (properties (text-properties-at timestamp-start formatted-string))) + (should (equal '(22782 21551) (plist-get properties 'timestamp))) + (should (string-equal "7 minutes ago" (plist-get properties 'display))))))) (ert-deftest mastodon-tl--consider-timestamp-for-updates-no-active-callback () "Should update the timestamp update variables as expected." @@ -454,33 +454,33 @@ a string or a numeric." ;; something a later update doesn't update: (with-mock - (mock (mastodon-tl--relative-time-details 'fake-timestamp) => - (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100)))) + (mock (mastodon-tl--relative-time-details 'fake-timestamp) => + (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100)))) - (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) + (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) - (should (null mastodon-tl--timestamp-update-timer)) - (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) + (should (null mastodon-tl--timestamp-update-timer)) + (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) ;; something only shortly sooner doesn't update: (with-mock - (mock (mastodon-tl--relative-time-details 'fake-timestamp) => - (cons "xxx ago" (time-subtract long-in-the-future (seconds-to-time 9)))) + (mock (mastodon-tl--relative-time-details 'fake-timestamp) => + (cons "xxx ago" (time-subtract long-in-the-future (seconds-to-time 9)))) - (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) + (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) - (should (null mastodon-tl--timestamp-update-timer)) - (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) + (should (null mastodon-tl--timestamp-update-timer)) + (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) ;; something much sooner, does update (with-mock - (mock (mastodon-tl--relative-time-details 'fake-timestamp) => - (cons "xxx ago" soon-in-the-future)) + (mock (mastodon-tl--relative-time-details 'fake-timestamp) => + (cons "xxx ago" soon-in-the-future)) - (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) + (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) - (should (null mastodon-tl--timestamp-update-timer)) - (should (eq mastodon-tl--timestamp-next-update soon-in-the-future))) + (should (null mastodon-tl--timestamp-update-timer)) + (should (eq mastodon-tl--timestamp-next-update soon-in-the-future))) ))) (ert-deftest mastodon-tl--consider-timestamp-for-updates-with-active-callback () @@ -496,27 +496,27 @@ a string or a numeric." ;; something a later update doesn't update: (with-mock - (mock (mastodon-tl--relative-time-details 'fake-timestamp) => - (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100)))) + (mock (mastodon-tl--relative-time-details 'fake-timestamp) => + (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100)))) - (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) + (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) - (should (eq 'initial-timer mastodon-tl--timestamp-update-timer)) - (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) + (should (eq 'initial-timer mastodon-tl--timestamp-update-timer)) + (should (eq mastodon-tl--timestamp-next-update long-in-the-future))) ;; something much sooner, does update (with-mock - (mock (mastodon-tl--relative-time-details 'fake-timestamp) => - (cons "xxx ago" soon-in-the-future)) - (mock (cancel-timer 'initial-timer)) - (mock (run-at-time soon-in-the-future nil - #'mastodon-tl--update-timestamps-callback - (current-buffer) nil) => 'new-timer) + (mock (mastodon-tl--relative-time-details 'fake-timestamp) => + (cons "xxx ago" soon-in-the-future)) + (mock (cancel-timer 'initial-timer)) + (mock (run-at-time soon-in-the-future nil + #'mastodon-tl--update-timestamps-callback + (current-buffer) nil) => 'new-timer) - (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) + (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp) - (should (eq 'new-timer mastodon-tl--timestamp-update-timer)) - (should (eq mastodon-tl--timestamp-next-update soon-in-the-future))) + (should (eq 'new-timer mastodon-tl--timestamp-update-timer)) + (should (eq mastodon-tl--timestamp-next-update soon-in-the-future))) ))) (ert-deftest mastodon-tl--find-property-range--no-tag () @@ -769,45 +769,45 @@ constant." (let ((now (current-time)) markers) (cl-labels ((insert-timestamp (n) - (insert (format "\nSome text before timestamp %s:" n)) - (insert (propertize - (format "timestamp #%s" n) - 'timestamp (time-subtract now (seconds-to-time (* 60 n))) - 'display (format "unset %s" n))) - (push (copy-marker (point)) markers) - (insert " some more text."))) + (insert (format "\nSome text before timestamp %s:" n)) + (insert (propertize + (format "timestamp #%s" n) + 'timestamp (time-subtract now (seconds-to-time (* 60 n))) + 'display (format "unset %s" n))) + (push (copy-marker (point)) markers) + (insert " some more text."))) (with-temp-buffer (cl-dotimes (n 12) (insert-timestamp (+ n 2))) (setq markers (nreverse markers)) (with-mock - (mock (current-time) => now) - (stub run-at-time => 'fake-timer) - - ;; make the initial call - (mastodon-tl--update-timestamps-callback (current-buffer) nil) - (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" - "unset 7" "unset 8" "unset 9" "unset 10" "unset 11" "unset 12" "unset 13") - (tl-tests--property-values-at 'display - (tl-tests--all-regions-with-property 'timestamp)))) - - ;; fake the follow-up call - (mastodon-tl--update-timestamps-callback (current-buffer) (nth 4 markers)) - (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" - "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago" - "unset 12" "unset 13") - (tl-tests--property-values-at 'display - (tl-tests--all-regions-with-property 'timestamp)))) - (should (null (marker-position (nth 4 markers)))) - - ;; fake the follow-up call - (mastodon-tl--update-timestamps-callback (current-buffer) (nth 9 markers)) - (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" - "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago" - "12 minutes ago" "13 minutes ago") - (tl-tests--property-values-at 'display - (tl-tests--all-regions-with-property 'timestamp)))) - (should (null (marker-position (nth 9 markers))))))))) + (mock (current-time) => now) + (stub run-at-time => 'fake-timer) + + ;; make the initial call + (mastodon-tl--update-timestamps-callback (current-buffer) nil) + (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" + "unset 7" "unset 8" "unset 9" "unset 10" "unset 11" "unset 12" "unset 13") + (tl-tests--property-values-at 'display + (tl-tests--all-regions-with-property 'timestamp)))) + + ;; fake the follow-up call + (mastodon-tl--update-timestamps-callback (current-buffer) (nth 4 markers)) + (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" + "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago" + "unset 12" "unset 13") + (tl-tests--property-values-at 'display + (tl-tests--all-regions-with-property 'timestamp)))) + (should (null (marker-position (nth 4 markers)))) + + ;; fake the follow-up call + (mastodon-tl--update-timestamps-callback (current-buffer) (nth 9 markers)) + (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago" + "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago" + "12 minutes ago" "13 minutes ago") + (tl-tests--property-values-at 'display + (tl-tests--all-regions-with-property 'timestamp)))) + (should (null (marker-position (nth 9 markers))))))))) (ert-deftest mastodon-tl--has-spoiler () "Should be able to detect toots with spoiler text as expected" @@ -925,13 +925,13 @@ constant." (ert-deftest mastodon-tl--extract-hashtag-from-url-wrong-instance () (should (null (mastodon-tl--extract-hashtag-from-url - "https://example.org/tags/foo" - "https://other.example.org")))) + "https://example.org/tags/foo" + "https://other.example.org")))) (ert-deftest mastodon-tl--extract-hashtag-from-url-not-tag () (should (null (mastodon-tl--extract-hashtag-from-url - "https://example.org/@userid" - "https://example.org")))) + "https://example.org/@userid" + "https://example.org")))) (ert-deftest mastodon-tl--userhandles () "Should recognise iserhandles in a toot and add the required properties to it." diff --git a/test/mastodon-toot-tests.el b/test/mastodon-toot-tests.el index 06da870..abc66d0 100644 --- a/test/mastodon-toot-tests.el +++ b/test/mastodon-toot-tests.el @@ -41,6 +41,6 @@ (ert-deftest cancel () (with-mock - (mock (kill-buffer-and-window)) - (mastodon-toot--cancel) - (mock-verify))) + (mock (kill-buffer-and-window)) + (mastodon-toot--cancel) + (mock-verify))) -- cgit v1.2.3 From 3dd4fea29835702a9664d7dd36014066edd1e49a Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 10 Nov 2021 08:38:28 +0100 Subject: move profile--my-profile binding to 'O' to avoid using C-S- bindings, which don't always work for others. --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 826787a..f9c18a0 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -145,7 +145,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-B") #'mastodon-tl--unblock-user) (define-key map (kbd "M") #'mastodon-tl--mute-user) (define-key map (kbd "C-S-M") #'mastodon-tl--unmute-user) - (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) + (define-key map (kbd "O") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) (define-key map (kbd "d") #'mastodon-toot--delete-toot) (define-key map (kbd "D") #'mastodon-toot--delete-and-redraft-toot) -- cgit v1.2.3 From 834dabcb9147e45633166b3f3b35b2b1d6fc64cc Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 15 Dec 2021 21:16:24 +0100 Subject: customize option to enable custom emoji by default. --- lisp/mastodon-toot.el | 5 +++++ lisp/mastodon.el | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9112fc9..cb3cd44 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -106,6 +106,11 @@ This is only used if company mode is installed." (const :tag "following only" "following") (const :tag "all users" "all"))) +(defcustom mastodon-toot--enable-custom-instance-emoji nil + "Whether to enable your instance's custom emoji by default." + :group 'mastodon-toot + :type 'boolean) + (defvar-local mastodon-toot--content-warning nil "A flag whether the toot should be marked with a content warning.") diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f9c18a0..662b691 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -223,7 +223,9 @@ If REPLY-JSON is the json of the toot being replied to." ;;;###autoload (add-hook 'mastodon-mode-hook (lambda () (when (require 'emojify nil :noerror) - (emojify-mode t)))) + (emojify-mode t) + (when mastodon-toot--enable-custom-instance-emoji + (mastodon-toot--enable-custom-emoji))))) (define-derived-mode mastodon-mode special-mode "Mastodon" "Major mode for Mastodon, the federated microblogging network." -- cgit v1.2.3 From fc8005c8fe3c5466c7e2d2b510e24f6eba661431 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 17 Dec 2021 15:03:00 +0100 Subject: bump version, change homepage link, readme --- README.org | 2 +- lisp/mastodon-async.el | 4 ++-- lisp/mastodon-auth.el | 4 ++-- lisp/mastodon-client.el | 4 ++-- lisp/mastodon-discover.el | 4 ++-- lisp/mastodon-http.el | 4 ++-- lisp/mastodon-inspect.el | 4 ++-- 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.el | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/README.org b/README.org index ab2dbff..fff4bc8 100644 --- a/README.org +++ b/README.org @@ -32,7 +32,7 @@ It adds the following features: | | images are links to the full image, can be zoomed/rotated/saved (see image keymap) | | | images scale properly | | | toot visibility (direct, followers only) icon appears in toot bylines | -| | display a toot's favorites, boosts and replies count in thread view | +| | display toot's number of favorites, boosts and replies | | | customize option to cache images | | Toots: | | | | mention booster in replies by default | diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 524e13d..3651bd5 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.7.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 8d0d7c6..8355200 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index bdfbca9..cb8eb26 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 33ce3d5..6b2eadf 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index a4f126f..00a0718 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1") (request "0.2.0")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 57240f3..4d91948 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 457628f..bbab816 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 15633be..5efb7d4 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7a9edc3..d21f5c0 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1") (seq "1.0")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index fcfaec9..a7dcda9 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen , martyhiatt -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9355480..89604b5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 2ff7f83..c89acc7 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 -;; Homepage: https://github.com/jdenen/mastodon.el +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1")) +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 662b691..2411e20 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -2,9 +2,9 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.9.1 +;; Version: 0.9.2 ;; Package-Requires: ((emacs "26.1") (request "0.3.2") (seq "1.0")) -;; Homepage: https://github.com/jdenen/mastodon.el +;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3 From 3a87f6caa62cbd0e925c765d2ac2840ba55f8db1 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 17 Dec 2021 16:22:46 +0100 Subject: depend on emacs 27.1, flychecks, docstrings, etc. strictly, the 27.1 dependency is only for proper-list-p in -http.el. --- lisp/mastodon-async.el | 25 +++++++++++++++---------- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-discover.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 4 +++- lisp/mastodon-media.el | 2 +- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-profile.el | 2 +- lisp/mastodon-search.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 10 +++++++--- lisp/mastodon.el | 5 +++-- 13 files changed, 37 insertions(+), 25 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 3651bd5..77fdb8e 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. @@ -32,6 +32,8 @@ (require 'json) (require 'url-http) +(defvar url-http-end-of-headers) + (autoload 'mastodon-auth--access-token "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-json "mastodon-http") @@ -153,10 +155,10 @@ NAME is the center portion of the buffer name for (url-retrieve url callback))) (defun mastodon-async--set-http-buffer (buffer http-buffer) - "Initializes for BUFFER a local variable `mastodon-async--http-buffer'. + "Initialize for BUFFER a local variable `mastodon-async--http-buffer'. HTTP-BUFFER is the initializing value. Use this funcion if HTTP-BUFFER -is not known when `mastodon-async--setup-buffer' is called." +is not known when `mastodon-async--setup-buffer' is called." (with-current-buffer (get-buffer-create buffer) (setq mastodon-async--http-buffer http-buffer))) @@ -164,6 +166,7 @@ is not known when `mastodon-async--setup-buffer' is called." http-buffer buffer-name queue-name) + "Set local variables for BUFFER, HTTP-BUFFER, BUFFER-NAME, and QUEUE-NAME." (with-current-buffer (get-buffer-create buffer) (let ((value mastodon-instance-url)) (make-local-variable 'mastodon-instance-url) @@ -173,7 +176,7 @@ is not known when `mastodon-async--setup-buffer' is called." (setq mastodon-async--queue queue-name))) (defun mastodon-async--setup-http (http-buffer name) - "Adds local variables to HTTP-BUFFER. + "Add local variables to HTTP-BUFFER. NAME is used to generate the display buffer and the queue." (let ((queue-name (concat " *mastodon-async-queue-" name "-" @@ -184,7 +187,8 @@ NAME is used to generate the display buffer and the queue." buffer-name queue-name))) (defun mastodon-async--setup-queue (http-buffer name) - "Sets up the buffer for the async queue." + "Set up HTTP-BUFFER buffer for the async queue. +NAME is used to generate the display buffer and the queue." (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) (buffer-name(concat "*mastodon-async-display-" name "-" @@ -194,11 +198,11 @@ NAME is used to generate the display buffer and the queue." queue-name)) (defun mastodon-async--setup-buffer (http-buffer name endpoint) - "Sets up the buffer timeline like `mastodon-tl--init'. + "Set up the buffer timeline like `mastodon-tl--init'. HTTP-BUFFER the name of the http-buffer, if unknown, set to... NAME is the name of the stream for the buffer name. -ENPOINT is the endpoint for the stream and timeline." +ENDPOINT is the endpoint for the stream and timeline." (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) (buffer-name (concat "*mastodon-async-display-" name "-" @@ -211,7 +215,7 @@ ENPOINT is the endpoint for the stream and timeline." (t (format "timelines/%s" endpoint))))) (mastodon-async--set-local-variables buffer-name http-buffer buffer-name queue-name) - ;; Similar to timeline init. + ;; Similar to timeline init. (with-current-buffer (get-buffer-create buffer-name) (setq inhibit-read-only t) ; for home timeline? (make-local-variable 'mastodon-tl--enable-relative-timestamps) @@ -238,7 +242,8 @@ ENPOINT is the endpoint for the stream and timeline." (defun mastodon-async--start-process (endpoint filter &optional name) "Start an async mastodon stream at ENDPOINT. -Filter the toots using FILTER." +Filter the toots using FILTER. +NAME is used for the queue and display buffer." (let* ((stream (concat "streaming/" endpoint)) (async-queue (mastodon-async--setup-queue "" (or name stream))) (async-buffer (mastodon-async--setup-buffer "" (or name stream) endpoint)) @@ -249,7 +254,7 @@ Filter the toots using FILTER." (message "HTTP SOURCE CLOSED"))))) (mastodon-async--setup-http http-buffer (or name stream)) (mastodon-async--set-http-buffer async-buffer http-buffer) - (mastodon-async--set-http-buffer async-queue http-buffer) + (mastodon-async--set-http-buffer async-queue http-buffer) (set-process-filter (get-buffer-process http-buffer) (mastodon-async--http-hook filter)) http-buffer)) diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 8355200..31df2ae 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index cb8eb26..a03d035 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 6b2eadf..21a0f95 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 00a0718..4461ea2 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "27.1") (request "0.2.0")) +;; Package-Requires: ((emacs "27.1") (request "0.3.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 4d91948..c9a9277 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. @@ -98,6 +98,7 @@ (defvar mastodon-inspect--search-result-tags) (defun mastodon-inspect--get-search-result (query) + "Inspect function for a search result for QUERY." (interactive) (setq mastodon-inspect--search-query-full-result (append ; convert vector to list @@ -111,6 +112,7 @@ nil))) (defun mastodon-inspect--get-search-account (query) + "Return JSON for a single account after search QUERY." (interactive) (setq mastodon-inspect--search-query-accounts-result (append ; convert vector to list diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index bbab816..6e02ebb 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 5efb7d4..ebf98ba 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index d21f5c0..dbe5686 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1") (seq "1.0")) +;; Package-Requires: ((emacs "27.1") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index a7dcda9..6317895 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen , martyhiatt ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 89604b5..71e08de 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c89acc7..6cf337a 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. @@ -545,7 +545,11 @@ The prefix can match against both user handles and display names." (propertize handle 'annot display-name 'meta url))) (defun mastodon-toot-mentions (command &optional arg &rest ignored) - "A company completion backend for toot mentions." + "A company completion backend for toot mentions. +COMMAND is either prefix, to fetch a prefix query, candidates, to +build a list of candidates with query ARG, annotation, to format +an annotation for candidate ARG, or meta, to format meta info for +candidate ARG. IGNORED remains a mystery." (interactive (list 'interactive)) (cl-case command (interactive (company-begin-backend 'mastodon-toot-mentions)) @@ -645,7 +649,7 @@ File is actually attached to the toot upon posting." (mastodon-toot--upload-attached-media (car (last mastodon-toot--media-attachments))))) (defun mastodon-toot--upload-attached-media (attachment) - "Upload a single attachment using `mastodon-http--post-media-attachment'. + "Upload a single ATTACHMENT using `mastodon-http--post-media-attachment'. The item's id is added to `mastodon-toot--media-attachment-ids', which is used to attach it to a toot when posting." (let* ((filename (expand-file-name diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2411e20..adc1ac8 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Version: 0.9.2 -;; Package-Requires: ((emacs "26.1") (request "0.3.2") (seq "1.0")) +;; Package-Requires: ((emacs "27.1") (request "0.3.2") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el ;; This file is not part of GNU Emacs. @@ -31,7 +31,8 @@ ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon -(require 'mastodon-toot) ; hack to make mastodon-toot customs visible +;; hack to make mastodon-toot customizes visible prior to running mastodon-toot: +(require 'mastodon-toot) (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") -- cgit v1.2.3 From 242628c090adad5e6f6292b108c6626bd78bf11a Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 17 Dec 2021 18:06:41 +0100 Subject: boilerplate maintainer contact --- lisp/mastodon-async.el | 2 ++ lisp/mastodon-auth.el | 1 + lisp/mastodon-client.el | 1 + lisp/mastodon-discover.el | 1 + lisp/mastodon-http.el | 1 + lisp/mastodon-inspect.el | 1 + lisp/mastodon-media.el | 1 + lisp/mastodon-notifications.el | 1 + lisp/mastodon-profile.el | 1 + lisp/mastodon-search.el | 4 +++- lisp/mastodon-tl.el | 1 + lisp/mastodon-toot.el | 1 + lisp/mastodon.el | 1 + 13 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 77fdb8e..bda6a4d 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -2,6 +2,8 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen +;; Alex J. Griffith +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 31df2ae..0b9a0dd 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index a03d035..2ecfff4 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 21a0f95..c8e3fd0 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 4461ea2..0447e22 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1") (request "0.3.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index c9a9277..209e8dd 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 6e02ebb..5e2699a 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index ebf98ba..ac0d339 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index dbe5686..0ed4d04 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 6317895..04b3e23 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,7 +1,9 @@ ;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Author: Johnson Denen , martyhiatt +;; Author: Johnson Denen +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 71e08de..45b905d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 6cf337a..5b46f5e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon.el b/lisp/mastodon.el index adc1ac8..9a0fe37 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -2,6 +2,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Maintainer: Marty Hiatt ;; Version: 0.9.2 ;; Package-Requires: ((emacs "27.1") (request "0.3.2") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el -- cgit v1.2.3 From c1aa61bb361cca5d107896a83b1b729315c4d79a Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 17 Dec 2021 18:18:28 +0100 Subject: bump version to a round number --- lisp/mastodon-async.el | 2 +- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- 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-search.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon.el | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index bda6a4d..6ff09e3 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Alex J. Griffith ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 0b9a0dd..e4f5934 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 2ecfff4..b27d434 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index c8e3fd0..10abc59 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 0447e22..33182ff 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 209e8dd..b0270ee 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 5e2699a..acce473 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index ac0d339..6d48681 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0ed4d04..e8025ed 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 04b3e23..78c2ab4 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -4,7 +4,7 @@ ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 67cdf82..62550cd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 5b46f5e..e813b33 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 9a0fe37..d5f9b6e 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt -;; Version: 0.9.2 +;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.2") (seq "1.0")) ;; Homepage: https://git.blast.noho.st/mouse/mastodon.el -- cgit v1.2.3