From f67558804e899306f6495c934bd25adff814d092 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 25 Oct 2021 11:37:08 +0200 Subject: restore original tl--init as tl--init-sync. - use it for eg notifications - this because i suspect sync is sometimes faster. - with async init*, i often have to press a key to trigger the request - perhaps good to have both in the code, and choose which to use when - cd also poss make this a customize. --- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-tl.el | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c917124..2e9aea3 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -252,7 +252,7 @@ ID is the notification's own id, which is attached as a property." "Display NOTIFICATIONS in buffer." (interactive) (message "Loading your notifications...") - (mastodon-tl--init + (mastodon-tl--init-sync "notifications" "notifications" 'mastodon-notifications--timeline)) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7f9538b..a7767b8 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1314,5 +1314,36 @@ JSON is the data returned from the server." (current-buffer) nil))))) +(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. +Runs synchronously." + (let* ((url (mastodon-http--api endpoint)) + (buffer (concat "*mastodon-" buffer-name "*")) + (json (mastodon-http--get-json url))) + (with-output-to-temp-buffer buffer + (switch-to-buffer buffer) + (setq + ;; Initialize with a minimal interval; we re-scan at least once + ;; every 5 minutes to catch any timestamps we may have missed + mastodon-tl--timestamp-next-update (time-add (current-time) + (seconds-to-time 300))) + (funcall update-function json)) + (mastodon-mode) + (with-current-buffer buffer + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer-name + endpoint ,endpoint update-function + ,update-function) + mastodon-tl--timestamp-update-timer + (when mastodon-tl--enable-relative-timestamps + (run-at-time mastodon-tl--timestamp-next-update + nil ;; don't repeat + #'mastodon-tl--update-timestamps-callback + (current-buffer) + nil)))) + buffer)) + (provide 'mastodon-tl) ;;; mastodon-tl.el ends here -- cgit v1.2.3 From f0c6f8a97280fa429c5e8b8a34a03fa887a44937 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 25 Oct 2021 12:28:23 +0200 Subject: echo faves, boosts, replies counts when in thread view --- lisp/mastodon-tl.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a7767b8..b4e3ae2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -721,6 +721,14 @@ takes a single function. By default it is (mastodon-tl--byline toot author-byline action-byline)) 'toot-id (cdr (assoc 'id toot)) 'base-toot-id (mastodon-tl--toot-id toot) + 'help-echo (when (and mastodon-tl--buffer-spec + (string-match-p + "context" + (plist-get mastodon-tl--buffer-spec 'endpoint))) + (format "%s faves | %s boosts | %s replies" + (cdr (assoc 'favourites_count toot)) + (cdr (assoc 'reblogs_count toot)) + (cdr (assoc 'replies_count toot)))) 'toot-json toot) "\n") (when mastodon-tl--display-media-p -- cgit v1.2.3 From a79210d516d59d4603f243299cc0f313200d91f4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 25 Oct 2021 16:37:03 +0200 Subject: declare company-mode functions --- lisp/mastodon-toot.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 983515e..178df56 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -34,7 +34,11 @@ (declare-function emojify-insert-emoji "emojify")) (require 'cl-lib) -(require 'company nil :noerror) + +(when (require 'company nil :noerror) + (declare-function company-mode-on "company") + (declare-function company-begin-backend "company") + (declare-function company-grab-symbol "company")) (defvar mastodon-instance-url) (autoload 'mastodon-auth--user-acct "mastodon-auth") -- cgit v1.2.3 From 3a892a4caa8b77c7f634f192ea22620af6506877 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 25 Oct 2021 16:37:29 +0200 Subject: _args for update-status-fields --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 178df56..44b0b3b 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -731,7 +731,7 @@ REPLY-JSON is the full JSON of the toot being replied to." (setq mastodon-toot--content-warning t) (setq mastodon-toot--content-warning-from-reply-or-redraft reply-cw))))) -(defun mastodon-toot--update-status-fields (&rest args) +(defun mastodon-toot--update-status-fields (&rest _args) "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) -- cgit v1.2.3 From 0dd83c5ada4bb4c0b73ebc43de4dcc58825b3f6f Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 25 Oct 2021 16:58:39 +0200 Subject: revert tl--thread to sync request for speed. --- lisp/mastodon-tl.el | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b4e3ae2..4d30f51 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -915,23 +915,16 @@ webapp" (reblog (cdr (assoc 'reblog json)))) (if reblog (cdr (assoc 'id reblog)) id))) + (defun mastodon-tl--thread () - "Open thread buffer for toot under `point' asynchronously." + "Open thread buffer for toot under `point'." (interactive) (let* ((id (mastodon-tl--as-string (mastodon-tl--toot-id (mastodon-tl--property 'toot-json)))) - (toot (mastodon-tl--property 'toot-json)) + (url (mastodon-http--api (format "statuses/%s/context" id))) (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) - "Callback for async `mastodon-tl--thread'. - -Open thread buffer for TOOT with id ID under `point'asynchronously, -in new BUFFER. -CONTEXT is the previous and subsequent toots in the thread." + (toot (mastodon-tl--property 'toot-json)) + (context (mastodon-http--get-json url))) (when (member (cdr (assoc 'type toot)) '("reblog" "favourite")) (setq toot (cdr (assoc 'status toot)))) (if (> (+ (length (cdr (assoc 'ancestors context))) @@ -950,7 +943,7 @@ CONTEXT is the previous and subsequent toots in the thread." (cdr (assoc 'ancestors context)) `(,toot) (cdr (assoc 'descendants context)))))) - (message "No Thread!")));) + (message "No Thread!")))) (defun mastodon-tl--follow-user (user-handle) "Query for USER-HANDLE from current status and follow that user." -- cgit v1.2.3 From b0d78e394ac70487d38257838d9b57b0677923f4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 26 Oct 2021 11:49:52 +0200 Subject: switch followers-only and direct message icons to match web layout --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4d30f51..9bbc44f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -406,11 +406,11 @@ By default it is `mastodon-tl--byline-boosted'" (funcall author-byline toot) (cond ((equal visibility "direct") (if (fontp (char-displayable-p #10r128274)) - " 🔒" + " ✉" " [direct]")) ((equal visibility "private") (if (fontp (char-displayable-p #10r9993)) - " ✉" + " 🔒" " [followers]"))) (funcall action-byline toot) " " -- cgit v1.2.3 From 64673e103233b238f936d78b4ca4182ce2304b26 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 26 Oct 2021 14:23:38 +0200 Subject: display status of locked accounts in profile view --- lisp/mastodon-profile.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index a374061..22120fe 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -296,6 +296,7 @@ Returns a list of lists." (buffer (concat "*mastodon-" acct "-" endpoint-type "*")) (note (mastodon-profile--account-field account 'note)) (json (mastodon-http--get-json url)) + (locked (mastodon-profile--account-field account 'locked)) (followers-count (mastodon-tl--as-string (mastodon-profile--account-field account 'followers_count))) @@ -338,8 +339,13 @@ Returns a list of lists." account 'display_name) 'face 'mastodon-display-name-face) "\n" - (propertize acct + (propertize (concat "@" acct) 'face 'default) + (if (equal locked t) + (if (fontp (char-displayable-p #10r9993)) + " 🔒" + " [locked]") + "") "\n ------------\n" (mastodon-tl--render-text note account) ;; account here to enable tab-stops in profile note -- cgit v1.2.3 From f9a4bab4a81f96407c38a1a45719d45827b9f585 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 26 Oct 2021 17:51:53 +0200 Subject: toot--enable-completion-for-mentions only if company noerror - from testing with 'emacs -Q' --- lisp/mastodon-toot.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 44b0b3b..3e60d2d 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -784,10 +784,11 @@ REPLY-JSON is the full JSON of the toot being replied to." (mastodon-toot-mode t) (unless mastodon-toot--max-toot-chars (mastodon-toot--get-max-toot-chars)) - (when mastodon-toot--enable-completion-for-mentions - (set (make-local-variable 'company-backends) - (add-to-list 'company-backends 'mastodon-toot--mentions-completion)) - (company-mode-on)) + (when (require 'company nil :noerror) + (when mastodon-toot--enable-completion-for-mentions + (set (make-local-variable 'company-backends) + (add-to-list 'company-backends 'mastodon-toot--mentions-completion)) + (company-mode-on))) (make-local-variable 'after-change-functions) (push #'mastodon-toot--update-status-fields after-change-functions) (mastodon-toot--refresh-attachments-display) -- cgit v1.2.3 From c60eb355232e57fec9fe97f366a3a2176f8c4110 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 26 Oct 2021 18:28:50 +0200 Subject: api/v2 for media attachment uploads --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 3e60d2d..14dcc29 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -567,7 +567,7 @@ It adds the items' ids to `mastodon-toot--media-attachment-ids', which is used t (mapcar (lambda (attachment) (let* ((filename (cdr (assoc :filename attachment))) (caption (cdr (assoc :description attachment))) - (url (concat mastodon-instance-url "/api/v1/media"))) + (url (concat mastodon-instance-url "/api/v2/media"))) (message "Uploading %s..." (file-name-nondirectory filename)) (mastodon-http--post-media-attachment url filename caption))) mastodon-toot--media-attachments)) -- 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') 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