aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-06-02 13:21:47 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-06-02 13:21:47 +0200
commitf4a4d31f29956048f44fb9982788ff17753585de (patch)
tree52b9166fc2cc66ae4663f891b8dfc5ddb926d935
parent06cbc031c78210a4950a748b20142e0008728bef (diff)
parent63a07d2ff4bff73d377ab4931cf0fb1fd7d51146 (diff)
Merge branch 'reload-paginate' into develop
-rw-r--r--lisp/mastodon-notifications.el2
-rw-r--r--lisp/mastodon-profile.el31
-rw-r--r--lisp/mastodon-tl.el100
-rw-r--r--lisp/mastodon-toot.el2
-rw-r--r--lisp/mastodon.el6
5 files changed, 87 insertions, 54 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 46a56f6..b96caa0 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -146,15 +146,16 @@ 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.
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))
+ 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,15 +595,20 @@ 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.
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* ((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 +643,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 +753,14 @@ 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."
+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))))
+ (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 aa70507..949414c 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,20 +454,28 @@ 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
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."
+With a single prefix ARG, hide replies.
+MAX-ID is a flag to add the max_id pagination parameter."
(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
+ (when (eq arg 4) t))))
(defun mastodon-tl--get-remote-local-timeline ()
"Prompt for an instance domain and try to display its local timeline.
@@ -506,13 +514,14 @@ 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."
+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))
+ (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.
@@ -1657,13 +1666,15 @@ 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.
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)
@@ -1672,7 +1683,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
@@ -2542,22 +2554,26 @@ 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))
+ (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)
- (mastodon-notifications-get nil nil :force))
+ (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)))
@@ -2622,17 +2638,19 @@ 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.
-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")
@@ -2663,13 +2681,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
@@ -2918,13 +2936,15 @@ 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
- (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.
@@ -2954,7 +2974,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)))
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
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index a0b5bbc..490b9fa 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)))))