From cd44f7807ffea4ecb86f07bfd160f9416908eb5d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 27 Mar 2023 12:22:11 +0200 Subject: remove all ;; Package-Requires: declarations save for main file main file is set in .dir-locals.el now --- lisp/mastodon-toot.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 65fc357..dfc02ee 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -6,7 +6,6 @@ ;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 -;; Package-Requires: ((emacs "27.1") (persist "0.4")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3 From d1ffaca6e21b988255d1b980a9de6bb1d976e1af Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 27 Mar 2023 15:14:48 +0200 Subject: work on reloading a view after sending an edited toot. FIX #421. - fix up reload-timeline-or-profile - additions to --send for edited toots position of point is only rough, chosen from buffer point prior to reload, but buffers change on reload (things added if timeline, things removed if delete toot or clear notif. we may need to find a much better way. --- lisp/mastodon-tl.el | 47 +++++++++++++++++++++++++++++------------------ lisp/mastodon-toot.el | 34 +++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 33 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3885220..c0c7e5e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2075,25 +2075,36 @@ the current view." (mastodon-http--get-json url args))) ;; TODO: add this to new posts in some cases, e.g. in thread view. -(defun mastodon-tl--reload-timeline-or-profile () +(defun mastodon-tl--reload-timeline-or-profile (&optional pos) "Reload the current timeline or profile page. -For use after e.g. deleting a toot." - (cond ((mastodon-tl--buffer-type-eq 'home) - (mastodon-tl--get-home-timeline)) - ((mastodon-tl--buffer-type-eq 'federated) - (mastodon-tl--get-federated-timeline)) - ((mastodon-tl--buffer-type-eq 'local) - (mastodon-tl--get-local-timeline)) - ((mastodon-tl--buffer-type-eq 'notifications) - (mastodon-notifications-get nil nil :force)) - ((mastodon-tl--buffer-type-eq 'own-profile) - (mastodon-profile--my-profile)) - ((save-match-data - (string-match - "statuses/\\(?2:[[:digit:]]+\\)/context" - (mastodon-tl--get-endpoint)) - (mastodon-tl--thread - (match-string 2 (mastodon-tl--get-endpoint))))))) +For use after e.g. deleting a toot. +POS is a number, where point will be placed." + (let ((type (mastodon-tl--get-buffer-type))) + (cond ((eq type 'home) + (mastodon-tl--get-home-timeline)) + ((eq type 'federated) + (mastodon-tl--get-federated-timeline)) + ((eq type 'local) + (mastodon-tl--get-local-timeline)) + ((eq type 'mentions) + (mastodon-notifications--get-mentions)) + ((eq type 'notifications) + (mastodon-notifications-get nil nil :force)) + ((eq type 'profile-statuses-no-boosts) + (mastodon-profile--open-statuses-no-reblogs)) + ((eq type 'profile-statuses) + (mastodon-profile--my-profile)) + ((eq type 'thread) + (save-match-data + (let ((endpoint (mastodon-tl--get-endpoint))) + (string-match + "statuses/\\(?2:[[:digit:]]+\\)/context" + endpoint) + (mastodon-tl--thread + (match-string 2 endpoint)))))) + ;; TODO: sends point to POS, which was where point was in buffer before reload. This is very rough; we may have removed an item (deleted a toot, cleared a notif), so the buffer will be smaller, point will end up past where we were, etc. + (when pos + (goto-char pos)))) (defun mastodon-tl--build-link-header-url (str) "Return a URL from STR, an http Link header." diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index dfc02ee..81185e8 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -773,11 +773,12 @@ instance to edit a toot." (let* ((toot (mastodon-toot--remove-docs)) (scheduled mastodon-toot--scheduled-for) (scheduled-id mastodon-toot--scheduled-id) + (edit-id mastodon-toot--edit-toot-id) (endpoint - (if mastodon-toot--edit-toot-id + (if edit-id ;; we are sending an edit: (mastodon-http--api (format "statuses/%s" - mastodon-toot--edit-toot-id)) + edit-id)) (mastodon-http--api "statuses"))) (spoiler (when (and (not (mastodon-toot--empty-p)) mastodon-toot--content-warning) @@ -819,22 +820,25 @@ instance to edit a toot." ((mastodon-toot--empty-p) (message "Empty toot. Cowardly refusing to post this.")) (t - (let ((response (if mastodon-toot--edit-toot-id + (let ((response (if edit-id ;; we are sending an edit: (mastodon-http--put endpoint args) (mastodon-http--post endpoint args)))) - (mastodon-http--triage response - (lambda () - (mastodon-toot--kill) - (if scheduled - (message "Toot scheduled!") - (message "Toot toot!")) - ;; cancel scheduled toot if we were editing it: - (when scheduled-id - (mastodon-views--cancel-scheduled-toot - scheduled-id :no-confirm)) - (mastodon-toot--restore-previous-window-config - prev-window-config)))))))) + (mastodon-http--triage + response + (lambda () + (mastodon-toot--kill) + (if scheduled + (message "Toot scheduled!") + (message "Toot toot!")) + ;; cancel scheduled toot if we were editing it: + (when scheduled-id + (mastodon-views--cancel-scheduled-toot + scheduled-id :no-confirm)) + (mastodon-toot--restore-previous-window-config prev-window-config) + (when edit-id + (let ((pos (marker-position (cadr prev-window-config)))) + (mastodon-tl--reload-timeline-or-profile pos)))))))))) ;; EDITING TOOTS: -- cgit v1.2.3 From 1980903f2dc179a15aecaceabd3c23a1d550d238 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 27 Mar 2023 20:56:07 +0200 Subject: send POS arg to reload-tl on delete toot --- lisp/mastodon-toot.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 81185e8..9aee54e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -568,7 +568,8 @@ NO-REDRAFT means delete toot only." (url (mastodon-http--api (format "statuses/%s" id))) (toot-cw (alist-get 'spoiler_text toot)) (toot-visibility (alist-get 'visibility toot)) - (reply-id (alist-get 'in_reply_to_id toot))) + (reply-id (alist-get 'in_reply_to_id toot)) + (pos (point))) (if (not (mastodon-toot--own-toot-p toot)) (message "You can only delete (and redraft) your own toots.") (when (y-or-n-p (if no-redraft @@ -581,7 +582,7 @@ NO-REDRAFT means delete toot only." (if no-redraft (progn (when mastodon-tl--buffer-spec - (mastodon-tl--reload-timeline-or-profile)) + (mastodon-tl--reload-timeline-or-profile pos)) (message "Toot deleted!")) (mastodon-toot--redraft response reply-id -- cgit v1.2.3 From aa982db0c5bc6e9e02a79ada9089cc78199789b9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 1 Apr 2023 13:27:53 +0200 Subject: add edit toot to compose-buffer-p --- lisp/mastodon-toot.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9aee54e..a1e6ed3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1609,7 +1609,8 @@ Added to `after-change-functions'." (defun mastodon-toot--compose-buffer-p () "Return t if compose buffer is current." - (mastodon-tl--buffer-type-eq 'new-toot)) + (or (mastodon-tl--buffer-type-eq 'edit-toot) + (mastodon-tl--buffer-type-eq 'new-toot))) ;; NB: now that we have toot drafts, to ensure offline composing remains ;; possible, avoid any direct requests here: -- cgit v1.2.3 From 9497fbd4b4f20b8423e80f2c785951942a141cf7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 5 Apr 2023 09:58:02 +0200 Subject: rejig polls for pleroma compat --- lisp/mastodon-toot.el | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a1e6ed3..c2c391d 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1175,22 +1175,25 @@ which is used to attach it to a toot when posting." mastodon-toot--media-attachments)) (list "None"))) -(defun mastodon-toot--fetch-max-poll-options () - "Return the maximum number of poll options." - (mastodon-toot--fetch-poll-field 'max_options)) - -(defun mastodon-toot--fetch-max-poll-option-chars () - "Return the maximum number of characters a poll option may have." - (or (mastodon-toot--fetch-poll-field 'max_characters_per_option) - 50)) ; masto default - -(defun mastodon-toot--fetch-poll-field (field) - "Return FIELD from the poll settings from the user's instance." - (let* ((instance (mastodon-http--get-json (mastodon-http--api "instance")))) - (alist-get field - (alist-get 'polls - (alist-get 'configuration instance) - instance)))) +(defun mastodon-toot--fetch-max-poll-options (instance) + "Return the maximum number of poll options from INSTANCE, which is json." + (mastodon-toot--fetch-poll-field 'max_options instance)) + +(defun mastodon-toot--fetch-max-poll-option-chars (instance) + "Return the maximum number of characters a poll option may have. +INSTANCE is JSON." + (if (alist-get 'pleroma instance) + (mastodon-toot--fetch-poll-field 'max_option_chars instance) + (or (mastodon-toot--fetch-poll-field 'max_characters_per_option instance) + 50))) ; masto default + +(defun mastodon-toot--fetch-poll-field (field instance) + "Return FIELD from the poll settings from INSTANCE, which is json." + (let* ((polls (if (alist-get 'pleroma instance) + (alist-get 'poll_limits instance) + (alist-get 'polls + (alist-get 'configuration instance))))) + (alist-get field polls))) (defun mastodon-toot--read-poll-options-count (max) "Read the user's choice of the number of options the poll should have. @@ -1205,15 +1208,17 @@ MAX is the maximum number set by their instance." "Prompt for new poll options and return as a list." (interactive) ;; re length, API docs show a poll 9 options. - (let* ((max-options (mastodon-toot--fetch-max-poll-options)) + (let* ((instance (mastodon-http--get-json (mastodon-http--api "instance"))) + (max-options (mastodon-toot--fetch-max-poll-options instance)) (count (mastodon-toot--read-poll-options-count max-options)) - (length (mastodon-toot--fetch-max-poll-option-chars)) + (length (mastodon-toot--fetch-max-poll-option-chars instance)) (multiple-p (y-or-n-p "Multiple choice? ")) (options (mastodon-toot--read-poll-options count length)) (hide-totals (y-or-n-p "Hide votes until poll ends? ")) - (expiry (mastodon-toot--get-poll-expiry))) + (expiry (mastodon-toot--read-poll-expiry))) (setq mastodon-toot-poll - `(:options ,options :length ,length :multi ,multiple-p :hide ,hide-totals :expiry ,expiry)) + `(:options ,options :length ,length :multi ,multiple-p + :hide ,hide-totals :expiry ,expiry)) (message "poll created!"))) (defun mastodon-toot--read-poll-options (count length) @@ -1222,7 +1227,7 @@ LENGTH is the maximum character length allowed for a poll option." (cl-loop for x from 1 to count collect (read-string (format "Poll option [%s/%s] [max %s chars]: " x count length)))) -(defun mastodon-toot--get-poll-expiry () +(defun mastodon-toot--read-poll-expiry () "Prompt for a poll expiry time." ;; API requires this in seconds (let* ((options (mastodon-toot--poll-expiry-options-alist)) -- cgit v1.2.3