From ddcaf0e1b2db6097d5e942eb75ffb27b86c6b1cb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 31 May 2024 13:08:09 +0200 Subject: add max-id to buffer-spec, and set when calling tl--more --- lisp/mastodon-tl.el | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index aa70507..14603b8 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1657,7 +1657,8 @@ If NO-ERROR is non-nil, do not error when property is empty." property))))) (defun mastodon-tl--set-buffer-spec - (buffer endpoint update-fun &optional link-header update-params hide-replies) + (buffer endpoint update-fun + &optional link-header update-params hide-replies max-id) "Set `mastodon-tl--buffer-spec' for the current buffer. BUFFER is buffer name, ENDPOINT is buffer's enpoint, UPDATE-FUN is its update function. @@ -1672,7 +1673,8 @@ HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer." update-function ,update-fun link-header ,link-header update-params ,update-params - hide-replies ,hide-replies))) + hide-replies ,hide-replies + max-id ,max-id))) ;;; BUFFERS @@ -2622,13 +2624,14 @@ and profile pages when showing followers or accounts followed." (mastodon-tl--update-params) 'mastodon-tl--more* (current-buffer) (point))) (t;; max_id paginate (timelines, items with ids/timestamps): - (mastodon-tl--more-json-async - (mastodon-tl--endpoint) - (mastodon-tl--oldest-id) - (mastodon-tl--update-params) - 'mastodon-tl--more* (current-buffer) (point)))))) - -(defun mastodon-tl--more* (response buffer point-before &optional headers) + (let ((max-id (mastodon-tl--oldest-id))) + (mastodon-tl--more-json-async + (mastodon-tl--endpoint) + max-id + (mastodon-tl--update-params) + 'mastodon-tl--more* (current-buffer) (point) nil max-id)))))) + +(defun mastodon-tl--more* (response buffer point-before &optional headers max-id) "Append older toots to timeline, asynchronously. Runs the timeline's update function on RESPONSE, in BUFFER. When done, places point at POINT-BEFORE. @@ -2663,13 +2666,13 @@ HEADERS is the http headers returned in the response, if any." (message "No more results.") (funcall (mastodon-tl--update-function) json) (goto-char point-before) - ;; update buffer spec to new link-header: + ;; update buffer spec to new link-header or max-id: ;; (other values should just remain as they were) - (when headers - (mastodon-tl--set-buffer-spec (mastodon-tl--buffer-name) - (mastodon-tl--endpoint) - (mastodon-tl--update-function) - link-header)) + (mastodon-tl--set-buffer-spec (mastodon-tl--buffer-name) + (mastodon-tl--endpoint) + (mastodon-tl--update-function) + link-header + nil nil max-id) (message "Loading... done."))))))) (defun mastodon-tl--find-property-range (property start-point -- cgit v1.2.3 From 2b426fb913b248d161122de9cca5368c60f72cea Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 31 May 2024 14:11:49 +0200 Subject: working max-id arg for hometimeline/reload --- lisp/mastodon-tl.el | 19 ++++++++++++------- lisp/mastodon-toot.el | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 14603b8..070c153 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -460,14 +460,18 @@ With a double PREFIX arg, only show posts with media." params (when (eq prefix 4) t)))) -(defun mastodon-tl--get-home-timeline (&optional arg) +(defun mastodon-tl--get-home-timeline (&optional arg max-id) "Open home timeline. With a single prefix ARG, hide replies." (interactive "p") - (message "Loading home timeline...") - (mastodon-tl--init "home" "timelines/home" 'mastodon-tl--timeline nil - `(("limit" . ,mastodon-tl--timeline-posts-count)) - (when (eq arg 4) t))) + (let* ((params + `(("limit" . ,mastodon-tl--timeline-posts-count) + ,(when max-id + `("max_id" . ,(mastodon-tl--buffer-property 'max-id)))))) + (message "Loading home timeline...") + (mastodon-tl--init "home" "timelines/home" 'mastodon-tl--timeline nil + params ;`(("limit" . ,mastodon-tl--timeline-posts-count)) + (when (eq arg 4) t)))) (defun mastodon-tl--get-remote-local-timeline () "Prompt for an instance domain and try to display its local timeline. @@ -2544,10 +2548,11 @@ the current view." (defun mastodon-tl--reload-timeline-or-profile (&optional pos) "Reload the current timeline or profile page. For use after e.g. deleting a toot. -POS is a number, where point will be placed." +POS is a number, where point will be placed. +Aims to respect any pagination in effect." (let ((type (mastodon-tl--get-buffer-type))) (cond ((eq type 'home) - (mastodon-tl--get-home-timeline)) + (mastodon-tl--get-home-timeline nil :max-id)) ((eq type 'federated) (mastodon-tl--get-federated-timeline)) ((eq type 'local) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 654918c..aaff19b 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -906,6 +906,7 @@ instance to edit a toot." (mastodon-http--triage response (lambda (_) + ;; kill buffer: (mastodon-toot--kill) (if scheduled (message "Toot scheduled!") @@ -914,6 +915,7 @@ instance to edit a toot." (when scheduled-id (mastodon-views--cancel-scheduled-toot scheduled-id :no-confirm)) + ;; window config: (mastodon-toot--restore-previous-window-config prev-window-config) ;; reload previous view in certain cases: ;; we reload: - when we have been editing -- cgit v1.2.3 From 06627d5d3dfad265fabf5b80d39ebe82a070d1a9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 1 Jun 2024 10:12:39 +0200 Subject: max-id arg for other -tl.el timelines --- lisp/mastodon-tl.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 070c153..af1ce45 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -442,7 +442,7 @@ Used on initializing a timeline or thread." ;;; TIMELINES -(defun mastodon-tl--get-federated-timeline (&optional prefix local) +(defun mastodon-tl--get-federated-timeline (&optional prefix local max-id) "Open federated timeline. If LOCAL, get only local timeline. With a single PREFIX arg, hide-replies. @@ -454,6 +454,9 @@ With a double PREFIX arg, only show posts with media." (push '("only_media" . "true") params)) (when local (push '("local" . "true") params)) + (when max-id + (push `("max_id" . ,(mastodon-tl--buffer-property 'max-id)) + params)) (message "Loading federated timeline...") (mastodon-tl--init (if local "local" "federated") "timelines/public" 'mastodon-tl--timeline nil @@ -470,7 +473,7 @@ With a single prefix ARG, hide replies." `("max_id" . ,(mastodon-tl--buffer-property 'max-id)))))) (message "Loading home timeline...") (mastodon-tl--init "home" "timelines/home" 'mastodon-tl--timeline nil - params ;`(("limit" . ,mastodon-tl--timeline-posts-count)) + params (when (eq arg 4) t)))) (defun mastodon-tl--get-remote-local-timeline () @@ -510,13 +513,13 @@ Use this to re-load remote-local items in order to interact with them." (uri (mastodon-tl--field 'uri toot))) (mastodon-url-lookup uri)))) -(defun mastodon-tl--get-local-timeline (&optional prefix) +(defun mastodon-tl--get-local-timeline (&optional prefix max-id) "Open local timeline. With a single PREFIX arg, hide-replies. With a double PREFIX arg, only show posts with media." (interactive "p") (message "Loading local timeline...") - (mastodon-tl--get-federated-timeline prefix :local)) + (mastodon-tl--get-federated-timeline prefix :local max-id)) (defun mastodon-tl--get-tag-timeline (&optional prefix tag) "Prompt for tag and opens its timeline. @@ -2554,9 +2557,9 @@ Aims to respect any pagination in effect." (cond ((eq type 'home) (mastodon-tl--get-home-timeline nil :max-id)) ((eq type 'federated) - (mastodon-tl--get-federated-timeline)) + (mastodon-tl--get-federated-timeline nil nil :max-id)) ((eq type 'local) - (mastodon-tl--get-local-timeline)) + (mastodon-tl--get-local-timeline nil :max-id)) ((eq type 'mentions) (mastodon-notifications--get-mentions)) ((eq type 'notifications) -- cgit v1.2.3 From 073ef686839944abc16f85883be8db84c95592ae Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 1 Jun 2024 10:26:37 +0200 Subject: max-id arg/param for notifs-get --- lisp/mastodon-tl.el | 10 +++++----- lisp/mastodon.el | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index af1ce45..7ffa96d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2563,7 +2563,7 @@ Aims to respect any pagination in effect." ((eq type 'mentions) (mastodon-notifications--get-mentions)) ((eq type 'notifications) - (mastodon-notifications-get nil nil :force)) + (mastodon-notifications-get nil nil :force :max-id)) ((eq type 'profile-statuses-no-boosts) (mastodon-profile--open-statuses-no-reblogs)) ((eq type 'profile-statuses) @@ -2932,10 +2932,10 @@ JSON and http headers, without it just the JSON." link-header update-params hide-replies) (mastodon-tl--do-init json update-function instance))))))) - (defun mastodon-tl--init-sync - (buffer-name endpoint update-function - &optional note-type params headers view-name binding-str) - "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. +(defun mastodon-tl--init-sync + (buffer-name endpoint update-function + &optional note-type params headers view-name binding-str) + "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. UPDATE-FUNCTION is used to receive more toots. Runs synchronously. Optional arg NOTE-TYPE means only get that type of notification. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index da3ffe2..42d9707 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -338,7 +338,7 @@ If REPLY-JSON is the json of the toot being replied to." (mastodon-toot--compose-buffer user reply-to-id reply-json)) ;;;###autoload -(defun mastodon-notifications-get (&optional type buffer-name force) +(defun mastodon-notifications-get (&optional type buffer-name force max-id) "Display NOTIFICATIONS in buffer. Optionally only print notifications of type TYPE, a string. BUFFER-NAME is added to \"*mastodon-\" to create the buffer name. @@ -356,7 +356,9 @@ from the server and load anew." (mastodon-tl--init-sync (or buffer-name "notifications") "notifications" 'mastodon-notifications--timeline - type) + type + (when max-id + `("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) (with-current-buffer buffer (use-local-map mastodon-notifications--map))))) -- cgit v1.2.3 From 13162773b6fcff121bf3449075201a49547f68c4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 1 Jun 2024 10:39:50 +0200 Subject: max-id arg/params for (so far only plain) profile view --- lisp/mastodon-profile.el | 22 +++++++++++++--------- lisp/mastodon-tl.el | 5 ++++- lisp/mastodon.el | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 46a56f6..37a6ec4 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -146,7 +146,7 @@ This variable is set from data in (mastodon-tl--property 'item-json)) (defun mastodon-profile--make-author-buffer - (account &optional no-reblogs no-replies only-media tag) + (account &optional no-reblogs no-replies only-media tag max-id) "Take an ACCOUNT json and insert a user account into a new buffer. NO-REBLOGS means do not display boosts in statuses. NO-REPLIES means to exlude replies. @@ -154,7 +154,7 @@ ONLY-MEDIA means show only posts containing attachments. TAG is a hashtag to restrict posts to." (mastodon-profile--make-profile-buffer-for account "statuses" #'mastodon-tl--timeline no-reblogs nil - no-replies only-media tag)) + no-replies only-media tag max-id)) ;; TODO: we shd just load all views' data then switch coz this is slow af: (defun mastodon-profile--account-view-cycle () @@ -594,7 +594,7 @@ FIELDS means provide a fields vector fetched by other means." (defun mastodon-profile--make-profile-buffer-for (account endpoint-type update-function - &optional no-reblogs headers no-replies only-media tag) + &optional no-reblogs headers no-replies only-media tag max-id) "Display profile of ACCOUNT, using ENDPOINT-TYPE and UPDATE-FUNCTION. NO-REBLOGS means do not display boosts in statuses. HEADERS means also fetch link headers for pagination. @@ -602,7 +602,11 @@ NO-REPLIES means to exlude replies. ONLY-MEDIA means show only posts containing attachments. TAG is a hashtag to restrict posts to." (let-alist account - (let* ((args `(("limit" . ,mastodon-tl--timeline-posts-count))) + (let* ((max-id-str (when max-id + (mastodon-tl--buffer-property 'max-id))) + (args `(("limit" . ,mastodon-tl--timeline-posts-count) + ,(when max-id + `("max_id" . ,max-id-str)))) (args (cond (no-reblogs (push '("exclude_reblogs" . "t") args)) (no-replies @@ -637,9 +641,8 @@ TAG is a hashtag to restrict posts to." (mastodon-profile-mode) (remove-overlays) (setq mastodon-profile--account account) - (mastodon-tl--set-buffer-spec buffer endpoint - update-function link-header - args) + (mastodon-tl--set-buffer-spec buffer endpoint update-function + link-header args nil max-id-str) (let* ((inhibit-read-only t) (is-statuses (string= endpoint-type "statuses")) (is-followers (string= endpoint-type "followers")) @@ -748,12 +751,13 @@ the format \"2000-01-31T00:00:00.000Z\"." (format-time-string "Joined: %d %B %Y" (parse-iso8601-time-string joined))) -(defun mastodon-profile--get-toot-author () +(defun mastodon-profile--get-toot-author (&optional max-id) "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 - (alist-get 'account (mastodon-profile--item-json)))) + (alist-get 'account (mastodon-profile--item-json)) + nil nil nil nil max-id)) (defun mastodon-profile--image-from-account (account img-type) "Return a avatar image from ACCOUNT. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7ffa96d..fe8f9f1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2565,9 +2565,12 @@ Aims to respect any pagination in effect." ((eq type 'notifications) (mastodon-notifications-get nil nil :force :max-id)) ((eq type 'profile-statuses-no-boosts) + ;; TODO: max-id arg needed here also (mastodon-profile--open-statuses-no-reblogs)) ((eq type 'profile-statuses) - (mastodon-profile--my-profile)) + (save-excursion + (goto-char (point-min)) + (mastodon-profile--get-toot-author :max-id))) ((eq type 'thread) (save-match-data (let ((endpoint (mastodon-tl--endpoint))) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 42d9707..24a6b4c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -358,7 +358,7 @@ from the server and load anew." 'mastodon-notifications--timeline type (when max-id - `("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) + `(("max_id" . ,(mastodon-tl--buffer-property 'max-id))))) (with-current-buffer buffer (use-local-map mastodon-notifications--map))))) -- cgit v1.2.3 From 9239f652265e0a3f29f73c442a1b2d3d0b3e5c16 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 1 Jun 2024 11:00:44 +0200 Subject: set max-id in buffer spec also after reloading --- lisp/mastodon-tl.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fe8f9f1..28177bc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2932,7 +2932,9 @@ JSON and http headers, without it just the JSON." (link-header (mastodon-tl--get-link-header-from-response headers))) (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer endpoint update-function - link-header update-params hide-replies) + link-header update-params hide-replies + ;; awful hack to fix multiple reloads: + (alist-get "max_id" update-params nil nil #'equal)) (mastodon-tl--do-init json update-function instance))))))) (defun mastodon-tl--init-sync @@ -2968,7 +2970,9 @@ BINDING-STR is a string explaining any bindins in the view." (insert (mastodon-tl--set-face (concat "[" binding-str "]\n\n") 'font-lock-comment-face))) (mastodon-tl--set-buffer-spec buffer endpoint update-function - link-header params) + link-header params nil + ;; awful hack to fix multiple reloads: + (alist-get "max_id" params nil nil #'equal)) (mastodon-tl--do-init json update-function) buffer))) -- cgit v1.2.3 From 63a07d2ff4bff73d377ab4931cf0fb1fd7d51146 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 2 Jun 2024 10:51:48 +0200 Subject: flycheck --- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-profile.el | 9 ++++++--- lisp/mastodon-tl.el | 12 ++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c26d0b0..5806893 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -261,7 +261,7 @@ Status notifications are given when (equal type 'follow-request) (equal type 'mention)) 'mastodon-tl--byline-author - (lambda (_status &rest args) ; unbreak stuff + (lambda (_status &rest _args) ; unbreak stuff (mastodon-tl--byline-author note))) ;; action-byline (lambda (_status) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 37a6ec4..b96caa0 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -151,7 +151,8 @@ This variable is set from data in NO-REBLOGS means do not display boosts in statuses. NO-REPLIES means to exlude replies. ONLY-MEDIA means show only posts containing attachments. -TAG is a hashtag to restrict posts to." +TAG is a hashtag to restrict posts to. +MAX-ID is a flag to include the max_id pagination parameter." (mastodon-profile--make-profile-buffer-for account "statuses" #'mastodon-tl--timeline no-reblogs nil no-replies only-media tag max-id)) @@ -600,7 +601,8 @@ NO-REBLOGS means do not display boosts in statuses. HEADERS means also fetch link headers for pagination. NO-REPLIES means to exlude replies. ONLY-MEDIA means show only posts containing attachments. -TAG is a hashtag to restrict posts to." +TAG is a hashtag to restrict posts to. +MAX-ID is a flag to include the max_id pagination parameter." (let-alist account (let* ((max-id-str (when max-id (mastodon-tl--buffer-property 'max-id))) @@ -753,7 +755,8 @@ the format \"2000-01-31T00:00:00.000Z\"." (defun mastodon-profile--get-toot-author (&optional max-id) "Open profile of author of toot under point. -If toot is a boost, opens the profile of the booster." +If toot is a boost, opens the profile of the booster. +MAX-ID is a flag to include the max_id pagination parameter." (interactive) (mastodon-profile--make-author-buffer (alist-get 'account (mastodon-profile--item-json)) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 28177bc..949414c 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -465,7 +465,8 @@ With a double PREFIX arg, only show posts with media." (defun mastodon-tl--get-home-timeline (&optional arg max-id) "Open home timeline. -With a single prefix ARG, hide replies." +With a single prefix ARG, hide replies. +MAX-ID is a flag to add the max_id pagination parameter." (interactive "p") (let* ((params `(("limit" . ,mastodon-tl--timeline-posts-count) @@ -516,7 +517,8 @@ Use this to re-load remote-local items in order to interact with them." (defun mastodon-tl--get-local-timeline (&optional prefix max-id) "Open local timeline. With a single PREFIX arg, hide-replies. -With a double PREFIX arg, only show posts with media." +With a double PREFIX arg, only show posts with media. +MAX-ID is a flag to add the max_id pagination parameter." (interactive "p") (message "Loading local timeline...") (mastodon-tl--get-federated-timeline prefix :local max-id)) @@ -1671,7 +1673,8 @@ BUFFER is buffer name, ENDPOINT is buffer's enpoint, UPDATE-FUN is its update function. LINK-HEADER is the http Link header if present. UPDATE-PARAMS is any http parameters needed for the update function. -HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer." +HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer. +MAX-ID is the pagination parameter." (setq mastodon-tl--buffer-spec `(account ,(cons mastodon-active-user mastodon-instance-url) @@ -2646,7 +2649,8 @@ and profile pages when showing followers or accounts followed." "Append older toots to timeline, asynchronously. Runs the timeline's update function on RESPONSE, in BUFFER. When done, places point at POINT-BEFORE. -HEADERS is the http headers returned in the response, if any." +HEADERS is the http headers returned in the response, if any. +MAX-ID is the pagination parameter, a string." (with-current-buffer buffer (if (not response) (message "No more results") -- cgit v1.2.3