From c147e78b1aa6369eef4f3380b6d9df73055cb341 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 28 Dec 2022 15:57:44 +1100 Subject: FIX pagination of local timeline --- lisp/mastodon-tl.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 570baf8..8ae0ded 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -404,7 +404,8 @@ Used on initializing a timeline or thread." (interactive) (message "Loading local timeline...") (mastodon-tl--init - "local" "timelines/public?local=true" 'mastodon-tl--timeline)) + "local" "timelines/public" 'mastodon-tl--timeline + nil '(("local" . "true")))) (defun mastodon-tl--get-tag-timeline () "Prompt for tag and opens its timeline." @@ -2552,7 +2553,7 @@ For use after e.g. deleting a toot." (mastodon-tl--get-home-timeline)) ((equal (mastodon-tl--get-endpoint) "timelines/public") (mastodon-tl--get-federated-timeline)) - ((equal (mastodon-tl--get-endpoint) "timelines/public?local=true") + ((equal (mastodon-tl--get-buffer-property 'buffer-name "*mastodon-local*")) (mastodon-tl--get-local-timeline)) ((equal (mastodon-tl--get-endpoint) "notifications") (mastodon-notifications-get)) @@ -2785,7 +2786,7 @@ from the start if it is nil." (when headers (split-string (alist-get "Link" headers nil nil 'equal) ", "))) -(defun mastodon-tl--init (buffer-name endpoint update-function &optional headers) +(defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT asynchronously. UPDATE-FUNCTION is used to recieve more toots. HEADERS means to also collect the response headers. Used for paginating @@ -2794,9 +2795,9 @@ favourites and bookmarks." (buffer (concat "*mastodon-" buffer-name "*"))) (if headers (mastodon-http--get-response-async - url nil 'mastodon-tl--init* buffer endpoint update-function headers) + url params 'mastodon-tl--init* buffer endpoint update-function headers) (mastodon-http--get-json-async - url nil 'mastodon-tl--init* buffer endpoint update-function)))) + url params 'mastodon-tl--init* buffer endpoint update-function)))) (defun mastodon-tl--init* (response buffer endpoint update-function &optional headers) "Initialize BUFFER with timeline targeted by ENDPOINT. -- cgit v1.2.3 From 76c86951411a4a09042bc4444fbbceefdf4b9b2a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 28 Dec 2022 18:49:07 +1100 Subject: Revert "adapt messaging for following of locked accounts" This reverts commit 0eeb429d3531a3c11cc9ea3c3aef258b7c671edb. --- lisp/mastodon-tl.el | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8ae0ded..ee6858f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2281,15 +2281,6 @@ LANGS is an array parameters alist of languages to filer user's posts by." (mastodon-tl--do-user-action-and-response user-handle "follow" nil notify langs))) -(defun mastodon-tl--account-locked-p (response) - "Return non-nil if RESPONSE states that the account acted upon is locked." - (let* ((json (with-current-buffer response (mastodon-http--process-json))) - (locked-p (alist-get 'requested json))) - ;; handle :json-false in response: - (if (eq 't locked-p) - t - nil))) - (defun mastodon-tl--enable-notify-user-posts (user-handle) "Query for USER-HANDLE and enable notifications when they post." (interactive @@ -2477,23 +2468,20 @@ ARGS is an alist of any parameters to send with the request." (mastodon-http--triage response (lambda () - (let ((locked-p (mastodon-tl--account-locked-p response))) - (cond ((string-equal notify "true") - (message "Receiving notifications for user %s (@%s)!" - name user-handle)) - ((string-equal notify "false") - (message "Not receiving notifications for user %s (@%s)!" - name user-handle)) - ((or (string-equal action "mute") - (string-equal action "unmute")) - (message "User %s (@%s) %sd!" name user-handle action)) - ((assoc "languages[]" args #'equal) - (message "User %s filtered by language(s): %s" name - (mapconcat #'cdr args " "))) - (locked-p - (message "Requested to follow user %s (@%s)" name user-handle)) - ((eq notify nil) - (message "User %s (@%s) %sed!" name user-handle action)))))))) + (cond ((string-equal notify "true") + (message "Receiving notifications for user %s (@%s)!" + name user-handle)) + ((string-equal notify "false") + (message "Not receiving notifications for user %s (@%s)!" + name user-handle)) + ((or (string-equal action "mute") + (string-equal action "unmute")) + (message "User %s (@%s) %sd!" name user-handle action)) + ((assoc "languages[]" args #'equal) + (message "User %s filtered by language(s): %s" name + (mapconcat #'cdr args " "))) + ((eq notify nil) + (message "User %s (@%s) %sed!" name user-handle action))))))) ;; FOLLOW TAGS -- cgit v1.2.3 From f4d8a0719e370d85e7b1b8c11d4a706770b799b8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 28 Dec 2022 19:06:43 +1100 Subject: handle nil json response in tl--init* fixes #352 we should almost always have faves and other tls, but not always things like bookmarks. --- lisp/mastodon-tl.el | 76 +++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ee6858f..156675a 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2793,43 +2793,45 @@ UPDATE-FUNCTION is used to recieve more toots. RESPONSE is the data returned from the server by `mastodon-http--process-json', with arg HEADERS a cons cell of JSON and http headers, without it just the JSON." - (let* ((json (if headers (car response) response)) - (headers (if headers (cdr response) nil)) - (link-header (mastodon-tl--get-link-header-from-response headers))) - (with-output-to-temp-buffer buffer - (switch-to-buffer buffer) - ;; mastodon-mode wipes buffer-spec, so order must unforch be: - ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. - ;; which means we cannot use buffer-spec for update-function - ;; unless we set it both before and after the others - (mastodon-tl--set-buffer-spec buffer - endpoint - update-function - link-header) - (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 - (mastodon-tl--set-buffer-spec buffer - endpoint - update-function - link-header) - (setq mastodon-tl--timestamp-update-timer - (when mastodon-tl--enable-relative-timestamps - (run-at-time (time-to-seconds - (time-subtract mastodon-tl--timestamp-next-update - (current-time))) - nil ;; don't repeat - #'mastodon-tl--update-timestamps-callback - (current-buffer) - nil))) - (unless (string-prefix-p "accounts" endpoint) - ;; for everything save profiles - (mastodon-tl--goto-first-item))))) + (let ((json (if headers (car response) response))) + (if (not json) ; praying this is right here, else try "\n[]" + (message "Looks like nothing returned from endpoint: %s" endpoint) + (let* ((headers (if headers (cdr response) nil)) + (link-header (mastodon-tl--get-link-header-from-response headers))) + (with-output-to-temp-buffer buffer + (switch-to-buffer buffer) + ;; mastodon-mode wipes buffer-spec, so order must unforch be: + ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. + ;; which means we cannot use buffer-spec for update-function + ;; unless we set it both before and after the others + (mastodon-tl--set-buffer-spec buffer + endpoint + update-function + link-header) + (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 + (mastodon-tl--set-buffer-spec buffer + endpoint + update-function + link-header) + (setq mastodon-tl--timestamp-update-timer + (when mastodon-tl--enable-relative-timestamps + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) + nil ;; don't repeat + #'mastodon-tl--update-timestamps-callback + (current-buffer) + nil))) + (unless (string-prefix-p "accounts" endpoint) + ;; for everything save profiles + (mastodon-tl--goto-first-item))))))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. -- cgit v1.2.3 From 294bbb378a2f21c7d5b32a853567505b8128dbee Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Fri, 9 Dec 2022 20:40:06 +0100 Subject: Keep current position of point after updates (fixes #349) Set a marker (mastodon-tl--before-update-marker) before updating the buffer and reset point's position there afterwards. --- lisp/mastodon-tl.el | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 156675a..899377a 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -149,11 +149,24 @@ font settings do not support it." :type '(alist :key-type symbol :value-type string) :group 'mastodon-tl) +(defcustom mastodon-tl-position-after-update nil + "Defines where `point' should be located after a timeline update. +Valid values are: +- nil Top/bottom depending on timeline type +- keep-point Keep original position of point +- last-old-toot The last toot before the new ones" + :type '(choice (const :tag "Top/bottom depending on timeline type" nil) + (const :tag "Keep original position of point" keep-point) + (const :tag "The last toot before the new ones" last-old-toot))) + (defvar-local mastodon-tl--update-point nil "When updating a mastodon buffer this is where new toots will be inserted. If nil `(point-min)' is used instead.") +(defvar-local mastodon-tl--after-update-marker nil + "Marker defining the position of point after the update is done.") + (defvar mastodon-tl--display-media-p t "A boolean value stating whether to show media in timelines.") @@ -2756,6 +2769,24 @@ from the start if it is nil." #'mastodon-tl--update-timestamps-callback buffer nil)))))))) +(defun mastodon-tl--set-after-update-marker () + (if mastodon-tl-position-after-update + (let ((marker (make-marker))) + (set-marker marker + (cond + ((eq 'keep-point mastodon-tl-position-after-update) + (point)) + ((eq 'last-old-toot mastodon-tl-position-after-update) + (next-single-property-change + (or mastodon-tl--update-point (point-min)) + 'byline)) + (error "Unknown mastodon-tl-position-after-update value %S" + mastodon-tl-position-after-update))) + ;; Make the marker advance if text gets inserted there. + (set-marker-insertion-type marker t) + (setq mastodon-tl--after-update-marker marker)) + (setq mastodon-tl--after-update-marker nil))) + (defun mastodon-tl--update () "Update timeline with new toots." (interactive) @@ -2765,8 +2796,11 @@ from the start if it is nil." (json (mastodon-tl--updated-json endpoint id))) (if json (let ((inhibit-read-only t)) + (mastodon-tl--set-after-update-marker) (goto-char (or mastodon-tl--update-point (point-min))) - (funcall update-function json)) + (funcall update-function json) + (when mastodon-tl--after-update-marker + (goto-char mastodon-tl--after-update-marker))) (message "nothing to update")))) (defun mastodon-tl--get-link-header-from-response (headers) -- cgit v1.2.3