From 1e4a661df8b3e07847e9d368f41fa775bf3442a7 Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Mon, 28 Nov 2022 15:33:37 +0100 Subject: Remove double white-space in the reply mode When you start a reply (to a local user or federated), there's one extra white-space after the list of mentioned users: `@user1@host.local @user2@host.federated__` (the underscores represent white-spaces). This PR removes the extra space. --- lisp/mastodon-toot.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 121a590..c19f8e3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -808,10 +808,10 @@ eg. \"user\" -> \"user@local.social \" (when local.social is the domain of the mastodon-instance-url). eg. \"yourusername\" -> \"\" eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." - (cond ((string-match-p "@" acct) (concat "@" acct " ")) ; federated acct + (cond ((string-match-p "@" acct) (concat "@" acct)) ; federated acct ((string= (mastodon-auth--user-acct) acct) "") ; your acct (t (concat "@" acct "@" ; local acct - (cadr (split-string mastodon-instance-url "/" t)) " ")))) + (cadr (split-string mastodon-instance-url "/" t)))))) (defun mastodon-toot--mentions (status) "Extract mentions from STATUS and process them into a string." @@ -821,11 +821,11 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." (if boosted (alist-get 'mentions (alist-get 'reblog status)) (alist-get 'mentions status)))) - (mapconcat (lambda(x) (mastodon-toot--process-local + (string-trim (mapconcat (lambda(x) (mastodon-toot--process-local (alist-get 'acct x))) ;; reverse does not work on vectors in 24.5 (reverse (append mentions nil)) - ""))) + " ")))) (defun mastodon-toot--get-bounds (regex) "Get bounds of tag or handle before point using REGEX." -- cgit v1.2.3 From 5dddfbe7ca90cfb0026dfadc24f98703f0e6c661 Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Thu, 1 Dec 2022 10:54:10 +0100 Subject: Move mentions concatenation into a function for a reply. --- lisp/mastodon-toot.el | 47 +++++++++++++++++++++++---------------------- test/mastodon-toot-tests.el | 33 +++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 29 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c19f8e3..c1d3ffa 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -800,11 +800,19 @@ Buffer-local variable `mastodon-toot-previous-window-config' holds the config." (set-window-configuration (car config)) (goto-char (cadr config))) +(defun mastodon-toot--mentions-to-string (mentions) + "Applies mastodon-toot--process-local function to each mention, +removes empty string (self) from result and joins the sequence with \" \"." + (mapconcat (lambda(mention) mention) + (remove "" (mapcar (lambda(x) (mastodon-toot--process-local x)) + mentions)) + " ")) + (defun mastodon-toot--process-local (acct) "Add domain to local ACCT and replace the curent user name with \"\". Mastodon requires the full user@domain, even in the case of local accts. -eg. \"user\" -> \"user@local.social \" (when local.social is the domain of the +eg. \"user\" -> \"user@local.social\" (when local.social is the domain of the mastodon-instance-url). eg. \"yourusername\" -> \"\" eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." @@ -814,19 +822,17 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." (cadr (split-string mastodon-instance-url "/" t)))))) (defun mastodon-toot--mentions (status) - "Extract mentions from STATUS and process them into a string." + "Extract mentions (not the reply-to author or booster) from STATUS and process them into a string." (interactive) (let* ((boosted (mastodon-tl--field 'reblog status)) (mentions (if boosted - (alist-get 'mentions (alist-get 'reblog status)) - (alist-get 'mentions status)))) - (string-trim (mapconcat (lambda(x) (mastodon-toot--process-local - (alist-get 'acct x))) - ;; reverse does not work on vectors in 24.5 - (reverse (append mentions nil)) - " ")))) - + (alist-get 'mentions (alist-get 'reblog status)) + (alist-get 'mentions status)))) + ;; reverse does not work on vectors in 24.5 + (mapcar (lambda(x) (alist-get 'acct x)) + (reverse mentions)))) + (defun mastodon-toot--get-bounds (regex) "Get bounds of tag or handle before point using REGEX." ;; needed because # and @ are not part of any existing thing at point @@ -917,26 +923,21 @@ text of the toot being replied to in the compose buffer." (mastodon-toot (when user (if booster (if (and (not (equal user booster)) - (not (string-match booster mentions))) + (not (member booster mentions))) ;; different booster, user and mentions: - (concat (mastodon-toot--process-local user) - ;; "@" booster " " - (mastodon-toot--process-local booster) - mentions) + (mastodon-toot--mentions-to-string (append (list user booster) mentions nil)) ;; booster is either user or in mentions: - (if (not (string-match user mentions)) + (if (not (member user mentions)) ;; user not already in mentions: - (concat (mastodon-toot--process-local user) - mentions) + (mastodon-toot--mentions-to-string (append (list user) mentions nil)) ;; user already in mentions: - mentions)) + (mastodon-toot--mentions-to-string (copy-sequence mentions)))) ;; ELSE no booster: - (if (not (string-match user mentions)) + (if (not (member user mentions)) ;; user not in mentions: - (concat (mastodon-toot--process-local user) - mentions) + (mastodon-toot--mentions-to-string (append (list user) mentions nil)) ;; user in mentions already: - mentions))) + (mastodon-toot--mentions-to-string (copy-sequence mentions))))) id (or base-toot toot)))) diff --git a/test/mastodon-toot-tests.el b/test/mastodon-toot-tests.el index 5d4ef03..69333c0 100644 --- a/test/mastodon-toot-tests.el +++ b/test/mastodon-toot-tests.el @@ -56,21 +56,33 @@ Transfer-Encoding: chunked") (username . "local") (url . "") (acct . "local"))]))) - (defconst mastodon-toot-no-mention '((mentions . []))) +(defconst mastodon-toot--multi-mention-extracted + '("local" "federated@federated.social" "federated@federated.cafe")) + (ert-deftest mastodon-toot--multi-mentions () "Should build a correct mention string from the test toot data. Even the local name \"local\" gets a domain name added." (let ((mastodon-auth--acct-alist '(("https://local.social". "null"))) (mastodon-instance-url "https://local.social")) - (should (string= + (should (equal (mastodon-toot--mentions mastodon-toot--multi-mention) + '("local" "federated@federated.social" "federated@federated.cafe"))))) + +(ert-deftest mastodon-toot--multi-mentions-to-string () + "Should build a correct mention string from the test toot data. + +Even the local name \"local\" gets a domain name added." + (let ((mastodon-auth--acct-alist '(("https://local.social". "null"))) + (mastodon-instance-url "https://local.social")) + (should (string= + (mastodon-toot--mentions-to-string mastodon-toot--multi-mention-extracted) "@local@local.social @federated@federated.social @federated@federated.cafe")))) -(ert-deftest mastodon-toot--multi-mentions-with-name () +(ert-deftest mastodon-toot--multi-mentions-with-name-to-string () "Should build a correct mention string omitting self. Here \"local\" is the user themselves and gets omitted from the @@ -79,15 +91,24 @@ mention string." '(("https://local.social". "local"))) (mastodon-instance-url "https://local.social")) (should (string= - (mastodon-toot--mentions mastodon-toot--multi-mention) + (mastodon-toot--mentions-to-string mastodon-toot--multi-mention-extracted) "@federated@federated.social @federated@federated.cafe")))) +(ert-deftest mastodon-toot--no-mention-to-string () + "Should return and empty string." + (let ((mastodon-auth--acct-alist + '(("https://local.social". "local"))) + (mastodon-instance-url "https://local.social")) + (should (string= + (mastodon-toot--mentions-to-string nil) + "")))) + (ert-deftest mastodon-toot--no-mention () - "Should construct an empty mention string without mentions." + "Should construct an empty mention list without mentions." (let ((mastodon-auth--acct-alist '(("https://local.social". "null"))) (mastodon-instance-url "https://local.social")) - (should (string= (mastodon-toot--mentions mastodon-toot-no-mention) "")))) + (should (equal (mastodon-toot--mentions mastodon-toot-no-mention) nil)))) ;; TODO: test y-or-no-p with mastodon-toot--cancel (ert-deftest mastodon-toot--kill () -- cgit v1.2.3 From 548b10fdfa19df91419b8c4f4b5812f189f7294d Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Thu, 1 Dec 2022 21:21:41 +0100 Subject: Update docstrings to match the current state. --- lisp/mastodon-toot.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c1d3ffa..feac7b5 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -802,7 +802,7 @@ Buffer-local variable `mastodon-toot-previous-window-config' holds the config." (defun mastodon-toot--mentions-to-string (mentions) "Applies mastodon-toot--process-local function to each mention, -removes empty string (self) from result and joins the sequence with \" \"." +removes empty string (self) from result and joins the sequence with whitespace \" \"." (mapconcat (lambda(mention) mention) (remove "" (mapcar (lambda(x) (mastodon-toot--process-local x)) mentions)) @@ -811,18 +811,21 @@ removes empty string (self) from result and joins the sequence with \" \"." (defun mastodon-toot--process-local (acct) "Add domain to local ACCT and replace the curent user name with \"\". -Mastodon requires the full user@domain, even in the case of local accts. -eg. \"user\" -> \"user@local.social\" (when local.social is the domain of the +Mastodon requires the full @user@domain, even in the case of local accts. +eg. \"user\" -> \"@user@local.social\" (when local.social is the domain of the mastodon-instance-url). eg. \"yourusername\" -> \"\" -eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." +eg. \"feduser@fed.social\" -> \"@feduser@fed.social\"." (cond ((string-match-p "@" acct) (concat "@" acct)) ; federated acct ((string= (mastodon-auth--user-acct) acct) "") ; your acct (t (concat "@" acct "@" ; local acct (cadr (split-string mastodon-instance-url "/" t)))))) (defun mastodon-toot--mentions (status) - "Extract mentions (not the reply-to author or booster) from STATUS and process them into a string." + "Extract mentions (not the reply-to author or booster) from STATUS. +The mentioned users look like this: +Local user (including the logged in): `username`. +Federated user: `username@host.co`." (interactive) (let* ((boosted (mastodon-tl--field 'reblog status)) (mentions -- cgit v1.2.3 From 8db62b46a141dc862cee6e90afc935964a55b9d4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Dec 2022 11:58:35 +0100 Subject: update comment re completion fetching --- lisp/mastodon-toot.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8d8bfc2..a394b00 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -881,10 +881,8 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." "Search for a completion prefix from buffer positions START to END. Return a list of candidates. If TAGS, we search for tags, else we search for handles." - ;; FIXME: can we save the first two-letter search then only filter the - ;; resulting list? - ;; (or mastodon-toot-completions - ;; would work if we could null that var upon completion success + ;; we can't save the first two-letter search then only filter the + ;; resulting list, as max results returned is 40. (setq mastodon-toot-completions (if tags (let ((tags-list (mastodon-search--search-tags-query -- cgit v1.2.3 From fabe373dedeae535726434527870e65496044e58 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Thu, 8 Dec 2022 09:13:16 -0500 Subject: Use mastodon-toot--count-toot-chars when validating toot length * lisp/mastodon-toot.el (mastodon-toot--send): Use mastodon-toot--count-toot-chars instead of length. --- 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 a394b00..c87b3bb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -738,7 +738,7 @@ instance to edit a toot." (length mastodon-toot--media-attachment-ids))))) (message "Something is wrong with your uploads. Wait for them to complete or try again.")) ((and mastodon-toot--max-toot-chars - (> (length toot) mastodon-toot--max-toot-chars)) + (> (mastodon-toot--count-toot-chars toot) mastodon-toot--max-toot-chars)) (message "Looks like your toot is longer than that maximum allowed length.")) ((mastodon-toot--empty-p) (message "Empty toot. Cowardly refusing to post this.")) -- cgit v1.2.3 From f238a32c5bbe3131efb7c53a6f89f9f217eac4e0 Mon Sep 17 00:00:00 2001 From: Skylar Hill Date: Thu, 8 Dec 2022 22:55:05 -0600 Subject: mastodon-tl--spoiler: Add error handling to /preferences api query mastodon.el currently breaks when trying to load a spoilered toot if the /preferences endpoint returns something unexpected, preventing mastodon-tl--buffer-spec from being set and not automatically enabling the major mode. This is particularly a problem on GoToSocial, which does not currently have the endpoint implemented and instead returns a 404 HTML page, causing a JSON parsing error. This PR adds a simple check which causes the API check in mastodon-tl--spoiler to return null if it errors, thus triggering the default behavior of hiding CW'd toots until opened. --- lisp/mastodon-tl.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e732420..41368e8 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1044,8 +1044,12 @@ message is a link which unhides/hides the main body." 'invisible ;; check server setting to expand all spoilers: (unless (eq t - (mastodon-profile--get-preferences-pref - 'reading:expand:spoilers)) + ;; If something goes wrong reading prefs, + ;; just return nil so CWs show by default. + (condition-case nil + (mastodon-profile--get-preferences-pref + 'reading:expand:spoilers) + (error nil))) t) 'mastodon-content-warning-body t)))) -- cgit v1.2.3 From 06b63f49793a187512c1819e8918e3933d8ea213 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 18 Dec 2022 10:22:02 +1100 Subject: message auth URL when copying to kill ring --- lisp/mastodon-auth.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 263ece2..4c508a4 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -137,6 +137,7 @@ When ASK is absent return nil." (let ((url (mastodon-auth--get-browser-login-url)) authorization-code) (kill-new url) + (message url) (setq authorization-code (mastodon-auth--show-notice mastodon-auth--explanation "*mastodon-notice*" -- cgit v1.2.3 From e494fb8d507311de8452db3e6f111b1e32cc3c4d Mon Sep 17 00:00:00 2001 From: Bas Alberts Date: Thu, 22 Dec 2022 11:01:24 -0500 Subject: fix for custom emoji path traversal --- lisp/mastodon-toot.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c87b3bb..06c49a3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -610,13 +610,19 @@ To use the downloaded emoji, run `mastodon-toot--enable-custom-emoji'." (unless (file-directory-p mastodon-custom-emoji-dir) (make-directory mastodon-custom-emoji-dir nil)) ; no add parent (mapc (lambda (x) - (url-copy-file (alist-get 'url x) - (concat - mastodon-custom-emoji-dir - (alist-get 'shortcode x) - "." - (file-name-extension (alist-get 'url x))) - t)) + (let ((url (alist-get 'url x)) + (shortcode (alist-get 'shortcode x))) + ;; skip anything that contains unexpected characters + (when (and url shortcode + (string-match-p "^[a-zA-Z0-9-_]*$" shortcode) + (string-match-p "^[a-zA-Z]*$" (file-name-extension url))) + (url-copy-file url + (concat + mastodon-custom-emoji-dir + shortcode + "." + (file-name-extension url)) + t)))) custom-emoji) (message "Custom emoji for %s downloaded to %s" mastodon-instance-url -- cgit v1.2.3 From 0114d8a43161ed8bf90e988d9125af4ae6e61165 Mon Sep 17 00:00:00 2001 From: Bas Alberts Date: Thu, 22 Dec 2022 22:43:23 -0500 Subject: further harden custom emoji regex filtering Prevent empty string shortcodes from creating dotfiles inside the custom emoji download dir to prevent e.g. ".envrc" and other such contextual dotfiles from being created in the legitimate download location. --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 06c49a3..d1e8cbe 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -614,8 +614,8 @@ To use the downloaded emoji, run `mastodon-toot--enable-custom-emoji'." (shortcode (alist-get 'shortcode x))) ;; skip anything that contains unexpected characters (when (and url shortcode - (string-match-p "^[a-zA-Z0-9-_]*$" shortcode) - (string-match-p "^[a-zA-Z]*$" (file-name-extension url))) + (string-match-p "^[a-zA-Z0-9-_]+$" shortcode) + (string-match-p "^[a-zA-Z]+$" (file-name-extension url))) (url-copy-file url (concat mastodon-custom-emoji-dir -- cgit v1.2.3 From ffb83a2edb908a20b666ae42855f51217a7fb0c1 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 23 Dec 2022 16:23:19 +0100 Subject: Do not pass URL directly to message. This breaks if it contains any % characters. --- lisp/mastodon-auth.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 4c508a4..3de2901 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -137,7 +137,7 @@ When ASK is absent return nil." (let ((url (mastodon-auth--get-browser-login-url)) authorization-code) (kill-new url) - (message url) + (message "%s" url) (setq authorization-code (mastodon-auth--show-notice mastodon-auth--explanation "*mastodon-notice*" -- cgit v1.2.3 From 017f9a8a8986b0cd5bca5d58f398f310048dab09 Mon Sep 17 00:00:00 2001 From: Toke Høiland-Jørgensen Date: Fri, 16 Dec 2022 16:54:06 +0100 Subject: Only add scheduled_at parameter to toot params when non-nil MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Pleroma server software can't handle the scheduled_at parameter being set to anything other than a valid datetime, even an empty value. To work around this, change mastodon-toot--send to only add the parameter to the list of args if its non-nil. Signed-off-by: Toke Høiland-Jørgensen --- lisp/mastodon-toot.el | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index eab0dfd..c18f751 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -703,6 +703,8 @@ instance to edit a toot." (interactive) (let* ((edit-p (if mastodon-toot--edit-toot-id t nil)) (toot (mastodon-toot--remove-docs)) + (scheduled mastodon-toot--scheduled-for) + (scheduled-id mastodon-toot--scheduled-id) (endpoint (if edit-p ;; we are sending an edit: @@ -713,14 +715,16 @@ instance to edit a toot." mastodon-toot--content-warning) (read-string "Warning: " mastodon-toot--content-warning-from-reply-or-redraft))) - (args-no-media `(("status" . ,toot) - ("in_reply_to_id" . ,mastodon-toot--reply-to-id) - ("visibility" . ,mastodon-toot--visibility) - ("sensitive" . ,(when mastodon-toot--content-nsfw - (symbol-name t))) - ("spoiler_text" . ,spoiler) - ("language" . ,mastodon-toot--language) - ("scheduled_at" . ,mastodon-toot--scheduled-for))) + (args-no-media (append `(("status" . ,toot) + ("in_reply_to_id" . ,mastodon-toot--reply-to-id) + ("visibility" . ,mastodon-toot--visibility) + ("sensitive" . ,(when mastodon-toot--content-nsfw + (symbol-name t))) + ("spoiler_text" . ,spoiler) + ("language" . ,mastodon-toot--language)) + ; Pleroma instances can't handle null-valued + ; scheduled_at args, so only add if non-nil + (when scheduled `(("scheduled_at" . ,scheduled))))) (args-media (when mastodon-toot--media-attachments (mastodon-http--build-array-params-alist "media_ids[]" @@ -733,9 +737,7 @@ instance to edit a toot." (if mastodon-toot-poll (append args-no-media args-poll) args-no-media))) - (prev-window-config mastodon-toot-previous-window-config) - (scheduled mastodon-toot--scheduled-for) - (scheduled-id mastodon-toot--scheduled-id)) + (prev-window-config mastodon-toot-previous-window-config)) (cond ((and mastodon-toot--media-attachments ;; make sure we have media args ;; and the same num of ids as attachments -- cgit v1.2.3 From 0eeb429d3531a3c11cc9ea3c3aef258b7c671edb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 28 Dec 2022 15:19:13 +1100 Subject: adapt messaging for following of locked accounts --- lisp/mastodon-tl.el | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 41368e8..570baf8 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2280,6 +2280,15 @@ 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 @@ -2467,20 +2476,23 @@ ARGS is an alist of any parameters to send with the request." (mastodon-http--triage response (lambda () - (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))))))) + (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)))))))) ;; FOLLOW TAGS -- cgit v1.2.3 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 From 9d9e6d7f632d8292c60c995681d632caffaf430f 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 actually fix Local pagination with tl--more* etc --- lisp/mastodon-tl.el | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 570baf8..afa665b 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." @@ -1404,10 +1405,12 @@ LINK-HEADER is the http Link header if present." (url (mastodon-http--api endpoint))) (mastodon-http--get-json url args))) -(defun mastodon-tl--more-json-async (endpoint id callback &rest cbargs) +(defun mastodon-tl--more-json-async (endpoint id &optional params callback &rest cbargs) "Return JSON for timeline ENDPOINT before ID. -Then run CALLBACK with arguments CBARGS." +Then run CALLBACK with arguments CBARGS +PARAMS is used to send 'local=true' for local timeline." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) + (args (if params (push params args) args)) (url (mastodon-http--api endpoint))) (apply 'mastodon-http--get-json-async url args callback cbargs))) @@ -2552,7 +2555,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--buffer-name) "*mastodon-local*") (mastodon-tl--get-local-timeline)) ((equal (mastodon-tl--get-endpoint) "notifications") (mastodon-notifications-get)) @@ -2595,8 +2598,13 @@ when showing followers or accounts followed." (url (mastodon-tl--build-link-header-url next))) (mastodon-http--get-response-async url nil 'mastodon-tl--more* (current-buffer) (point) :headers)) - (mastodon-tl--more-json-async (mastodon-tl--get-endpoint) (mastodon-tl--oldest-id) - 'mastodon-tl--more* (current-buffer) (point)))) + (mastodon-tl--more-json-async + (mastodon-tl--get-endpoint) + (mastodon-tl--oldest-id) + ;; local has same endpoint as federated: + (when (string= (mastodon-tl--buffer-name) "*mastodon-local*") + '("local" . "true")) + 'mastodon-tl--more* (current-buffer) (point)))) (defun mastodon-tl--more* (response buffer point-before &optional headers) "Append older toots to timeline, asynchronously. @@ -2785,18 +2793,20 @@ 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 -favourites and bookmarks." +favourites and bookmarks. +PARAMS is any parameters to send with the request, currently only +used to send 'local=true' for local timeline." (let ((url (mastodon-http--api endpoint)) (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 2d32115bb206f91001df89baeab8371afbeecb14 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 afa665b..93b5451 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2283,15 +2283,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 @@ -2479,23 +2470,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 560a885d98cdb0d2822fef6d72a9bc69ef69a365 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 93b5451..bb68508 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2802,43 +2802,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 352cba8d86580ac4f525f64f3643fbb70d6583f1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 29 Dec 2022 15:10:27 +1100 Subject: fix update local tl, tl--update, like tl--more --- lisp/mastodon-tl.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 44d31bf..bf334bd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1429,9 +1429,10 @@ PARAMS is used to send 'local=true' for local timeline." ;; TODO ;; Look into the JSON returned here by Local -(defun mastodon-tl--updated-json (endpoint id) +(defun mastodon-tl--updated-json (endpoint id &optional params) "Return JSON for timeline ENDPOINT since ID." (let* ((args `(("since_id" . ,(mastodon-tl--as-string id)))) + (args (if params (push params args) args)) (url (mastodon-http--api endpoint))) (mastodon-http--get-json url args))) @@ -2800,7 +2801,9 @@ from the start if it is nil." (let* ((endpoint (mastodon-tl--get-endpoint)) (update-function (mastodon-tl--get-update-function)) (id (mastodon-tl--newest-id)) - (json (mastodon-tl--updated-json endpoint id))) + (params (when (string= (mastodon-tl--buffer-name) "*mastodon-local*") + '("local" . "true"))) + (json (mastodon-tl--updated-json endpoint id params))) (if json (let ((inhibit-read-only t)) (mastodon-tl--set-after-update-marker) -- cgit v1.2.3 From 8a633d9ab01e9c8cb47e9edf54d52f44e26c57f9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 29 Dec 2022 15:47:33 +1100 Subject: hack tl--update so it works with update fun tl--thread --- lisp/mastodon-tl.el | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index bf334bd..86aaf67 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1535,7 +1535,7 @@ ID is that of the toot to view." (mastodon-mode) (mastodon-tl--set-buffer-spec buffer endpoint - nil) + #'mastodon-tl--thread) (let ((inhibit-read-only t)) (mastodon-tl--timeline (alist-get 'ancestors context)) (goto-char (point-max)) @@ -2800,18 +2800,23 @@ from the start if it is nil." (interactive) (let* ((endpoint (mastodon-tl--get-endpoint)) (update-function (mastodon-tl--get-update-function)) - (id (mastodon-tl--newest-id)) - (params (when (string= (mastodon-tl--buffer-name) "*mastodon-local*") - '("local" . "true"))) - (json (mastodon-tl--updated-json endpoint id params))) - (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) + (thread-id (mastodon-tl--property 'toot-id))) + ;; update a thread, without calling `mastodon-tl--updated-json': + (if (string-suffix-p "context" (mastodon-tl--get-endpoint)) + (funcall update-function thread-id) + ;; update other timelines: + (let* ((id (mastodon-tl--newest-id)) + (params (when (string= (mastodon-tl--buffer-name) "*mastodon-local*") + '("local" . "true"))) + (json (mastodon-tl--updated-json endpoint id params))) + (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)) (when mastodon-tl--after-update-marker (goto-char mastodon-tl--after-update-marker))) - (message "nothing to update")))) + (message "nothing to update"))))) (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." -- cgit v1.2.3 From e7521f255c62debd1077ef77bfa0dd6ca4348cfa Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 29 Dec 2022 16:30:39 +0100 Subject: Fix mastodon-tl-position-after-update --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 86aaf67..b3427fc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2813,9 +2813,9 @@ from the start if it is nil." (let ((inhibit-read-only t)) (mastodon-tl--set-after-update-marker) (goto-char (or mastodon-tl--update-point (point-min))) - (funcall update-function json)) - (when mastodon-tl--after-update-marker - (goto-char mastodon-tl--after-update-marker))) + (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