From 101e2c7ee74bfa1df6bb3d31a9daeca6a0a75243 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 30 Dec 2022 10:23:04 +1100 Subject: `mastodon-tl--set-after-update-marker' - add `t` to last cond branch --- lisp/mastodon-tl.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b3427fc..0a30186 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2788,8 +2788,9 @@ from the start if it is nil." (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))) + (t + (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)) -- cgit v1.2.3 From 47eaa7a194fa38bc39c45fbd5e3f86a01d78755f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 30 Dec 2022 10:23:43 +1100 Subject: docstrings --- lisp/mastodon-tl.el | 5 +++-- lisp/mastodon-toot.el | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 0a30186..9206695 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1430,7 +1430,8 @@ 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 &optional params) - "Return JSON for timeline ENDPOINT since ID." + "Return JSON for timeline ENDPOINT since ID. +PARAMS are any parameters to send with the request." (let* ((args `(("since_id" . ,(mastodon-tl--as-string id)))) (args (if params (push params args) args)) (url (mastodon-http--api endpoint))) @@ -2579,7 +2580,7 @@ For use after e.g. deleting a toot." (concat url-base "&" param))) (defun mastodon-tl--use-link-header-p () - "Return t if we are in a view that uses Link header pagination. + "Return t if we are in a view needing Link header pagination. Currently this includes favourites, bookmarks, and profile pages when showing followers or accounts followed." (let ((buf (buffer-name (current-buffer))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c18f751..3406ec4 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -844,8 +844,8 @@ Buffer-local variable `mastodon-toot-previous-window-config' holds the 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 whitespace \" \"." + "Apply `mastodon-toot--process-local' function to each mention in MENTIONS. +Remove 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)) -- cgit v1.2.3 From 202bbd7e07dd9b439bba483af08dbc21343daa1f Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 31 Dec 2022 09:48:00 +0100 Subject: Document `mastodon-tl--set-after-update-marker' --- lisp/mastodon-tl.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9206695..9f21bf9 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2779,6 +2779,9 @@ from the start if it is nil." buffer nil)))))))) (defun mastodon-tl--set-after-update-marker () + "Set `mastodon-tl--after-update-marker' to the after-update location. +This location is defined by a non-nil value of +`mastodon-tl-position-after-update'." (if mastodon-tl-position-after-update (let ((marker (make-marker))) (set-marker marker -- cgit v1.2.3 From 7354b5abfa9a29169a299e9204c9154ddbce8b76 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 9 Jan 2023 11:23:35 +1100 Subject: store params in buffer-spec, use for updating buffers - store the http parameters used to load and update the current view in `mastodon-tl--buffer-spec` - `mastodon-tl--updated-json` - fetch and use stored parameters for now, local TL, and filtered notifications rely on this tl--more-json-async: handle update-params properly updated-json /more-json-async: fall back to args if no params update docstrings and code commends regarding update-params in buffer-spec --- lisp/mastodon-tl.el | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9f21bf9..dbeacab 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1398,19 +1398,20 @@ Optionally get it for BUFFER." (or buffer (current-buffer)))))) (defun mastodon-tl--set-buffer-spec (buffer endpoint update-function - &optional link-header) + &optional link-header update-params) "Set `mastodon-tl--buffer-spec' for the current buffer. - BUFFER is buffer name, ENDPOINT is buffer's enpoint, UPDATE-FUNCTION is its update function. -LINK-HEADER is the http Link header if present." +LINK-HEADER is the http Link header if present. +UPDATE-PARAMS is any http parameters needed for the update function." (setq mastodon-tl--buffer-spec `(account ,(cons mastodon-active-user mastodon-instance-url) buffer-name ,buffer endpoint ,endpoint update-function ,update-function - link-header ,link-header))) + link-header ,link-header + update-params ,update-params))) (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." @@ -1420,10 +1421,11 @@ LINK-HEADER is the http Link header if present." (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 -PARAMS is used to send 'local=true' for local timeline." +Then run CALLBACK with arguments CBARGS. +PARAMS is used to send any parameters needed to correctly update +the current view." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) - (args (if params (push params args) args)) + (args (if params (push (car args) params) args)) (url (mastodon-http--api endpoint))) (apply 'mastodon-http--get-json-async url args callback cbargs))) @@ -1431,9 +1433,10 @@ PARAMS is used to send 'local=true' for local timeline." ;; Look into the JSON returned here by Local (defun mastodon-tl--updated-json (endpoint id &optional params) "Return JSON for timeline ENDPOINT since ID. -PARAMS are any parameters to send with the request." +PARAMS is used to send any parameters needed to correctly update +the current view." (let* ((args `(("since_id" . ,(mastodon-tl--as-string id)))) - (args (if params (push params args) args)) + (args (if params (push (car args) params) args)) (url (mastodon-http--api endpoint))) (mastodon-http--get-json url args))) @@ -2604,9 +2607,7 @@ when showing followers or accounts followed." (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--get-buffer-property 'update-params) 'mastodon-tl--more* (current-buffer) (point)))) (defun mastodon-tl--more* (response buffer point-before &optional headers) @@ -2811,8 +2812,7 @@ This location is defined by a non-nil value of (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"))) + (params (mastodon-tl--get-buffer-property 'update-params)) (json (mastodon-tl--updated-json endpoint id params))) (if json (let ((inhibit-read-only t)) @@ -2833,17 +2833,17 @@ This location is defined by a non-nil value of UPDATE-FUNCTION is used to recieve more toots. HEADERS means to also collect the response headers. Used for paginating favourites and bookmarks. -PARAMS is any parameters to send with the request, currently only -used to send 'local=true' for local timeline." +PARAMS is any parameters to send with the request." (let ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*"))) (if headers (mastodon-http--get-response-async - url params 'mastodon-tl--init* buffer endpoint update-function headers) + url params 'mastodon-tl--init* buffer endpoint update-function headers params) (mastodon-http--get-json-async - url params 'mastodon-tl--init* buffer endpoint update-function)))) + url params 'mastodon-tl--init* buffer endpoint update-function nil params)))) -(defun mastodon-tl--init* (response buffer endpoint update-function &optional headers) +(defun mastodon-tl--init* (response buffer endpoint update-function + &optional headers update-params) "Initialize BUFFER with timeline targeted by ENDPOINT. UPDATE-FUNCTION is used to recieve more toots. RESPONSE is the data returned from the server by @@ -2863,7 +2863,8 @@ JSON and http headers, without it just the JSON." (mastodon-tl--set-buffer-spec buffer endpoint update-function - link-header) + link-header + update-params) (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed @@ -2875,7 +2876,8 @@ JSON and http headers, without it just the JSON." (mastodon-tl--set-buffer-spec buffer endpoint update-function - link-header) + link-header + update-params) (setq mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps (run-at-time (time-to-seconds @@ -2899,11 +2901,8 @@ Optional arg NOTE-TYPE means only get that type of note." (mastodon-notifications--filter-types-list note-type))) (args (when note-type (mastodon-http--build-array-params-alist "exclude_types[]" exclude-types))) - ;; (query-string (when note-type - ;; (mastodon-http--build-params-string args))) - ;; add note-type exclusions to endpoint so it works in `mastodon-tl--buffer-spec' - ;; that way `mastodon-tl--more' works seamlessly too: - ;; (endpoint (if note-type (concat endpoint "?" query-string) endpoint)) + ;; NB: we now store 'update-params separately in `mastodon-tl--buffer-spec' + ;; and -http.el handles all conversion of params alists into query strings. (url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*")) (json (mastodon-http--get-json url args))) @@ -2922,7 +2921,7 @@ Optional arg NOTE-TYPE means only get that type of note." (funcall update-function json)) (mastodon-mode) (with-current-buffer buffer - (mastodon-tl--set-buffer-spec buffer endpoint update-function) + (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args) (setq mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps (run-at-time (time-to-seconds -- cgit v1.2.3 From 5d1e5edd0709a70c81a9fc846ff3292a9a270544 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 9 Jan 2023 16:06:20 +1100 Subject: remove first empty line in docstrings --- lisp/mastodon-async.el | 6 ------ lisp/mastodon-http.el | 3 --- lisp/mastodon-media.el | 8 ++------ lisp/mastodon-notifications.el | 1 - lisp/mastodon-search.el | 2 -- lisp/mastodon-tl.el | 31 ++----------------------------- lisp/mastodon-toot.el | 6 +----- lisp/mastodon.el | 4 ---- 8 files changed, 5 insertions(+), 56 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 58e7b93..a352ffc 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -131,7 +131,6 @@ (defun mastodon-async--mastodon (endpoint timeline name filter) "Make sure that the previous async process has been closed. - Then start an async stream at ENDPOINT filtering toots using FILTER. TIMELINE is a specific target, such as federated or home. @@ -157,7 +156,6 @@ NAME is the center portion of the buffer name for (defun mastodon-async--set-http-buffer (buffer http-buffer) "Initialize for BUFFER a local variable `mastodon-async--http-buffer'. - HTTP-BUFFER is the initializing value. Use this funcion if HTTP-BUFFER is not known when `mastodon-async--setup-buffer' is called." (with-current-buffer (get-buffer-create buffer) @@ -178,7 +176,6 @@ is not known when `mastodon-async--setup-buffer' is called." (defun mastodon-async--setup-http (http-buffer name) "Add local variables to HTTP-BUFFER. - NAME is used to generate the display buffer and the queue." (let ((queue-name (concat " *mastodon-async-queue-" name "-" mastodon-instance-url "*")) @@ -200,7 +197,6 @@ NAME is used to generate the display buffer and the queue." (defun mastodon-async--setup-buffer (http-buffer name endpoint) "Set up the buffer timeline like `mastodon-tl--init'. - HTTP-BUFFER the name of the http-buffer, if unknown, set to... NAME is the name of the stream for the buffer name. ENDPOINT is the endpoint for the stream and timeline." @@ -334,7 +330,6 @@ NAME is used for the queue and display buffer." (defun mastodon-async--cycle-queue (string) "Append the most recent STRING from http buffer to queue buffer. - Then determine if a full message has been recived. If so return it. Full messages are seperated by two newlines" (with-current-buffer mastodon-async--queue @@ -350,7 +345,6 @@ Full messages are seperated by two newlines" (defun mastodon-async--http-layer (proc data) "Passes PROC and DATA to ‘url-http-generic-filter’. - It then processes its output." (with-current-buffer (process-buffer proc) (let ((start (max 1 (- (point-max) 2)))) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 9ef7aec..3cc5511 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -73,7 +73,6 @@ (defun mastodon-http--url-retrieve-synchronously (url &optional silent) "Retrieve URL asynchronously. - This is a thin abstraction over the system `url-retrieve-synchronously'. Depending on which version of this is available we will call it with or without a timeout. @@ -84,7 +83,6 @@ SILENT means don't message." (defun mastodon-http--triage (response success) "Determine if RESPONSE was successful. Call SUCCESS if successful. - Message status and JSON error from RESPONSE if unsuccessful." (let ((status (with-current-buffer response (mastodon-http--status)))) @@ -136,7 +134,6 @@ Used for API form data parameters that take an array." (defun mastodon-http--post (url &optional params headers unauthenticated-p) "POST synchronously to URL, optionally with PARAMS and HEADERS. - Authorization header is included by default unless UNAUTHENTICATED-P is non-nil." (mastodon-http--authorized-request "POST" diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 4e50dbc..3fb10b0 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -144,7 +144,6 @@ fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=") (defun mastodon-media--process-image-response (status-plist marker image-options region-length url) "Callback function processing the url retrieve response for URL. - STATUS-PLIST is the usual plist of status events as per `url-retrieve'. IMAGE-OPTIONS are the precomputed options to apply to the image. MARKER is the marker to where the response should be visible. @@ -186,7 +185,6 @@ with the image." (defun mastodon-media--load-image-from-url (url media-type start region-length) "Take a URL and MEDIA-TYPE and load the image asynchronously. - MEDIA-TYPE is a symbol and either 'avatar or 'media-link. START is the position where we start loading the image. REGION-LENGTH is the range from start to propertize." @@ -199,8 +197,8 @@ REGION-LENGTH is the range from start to propertize." `(:max-height ,mastodon-media--preview-max-height)))))) (let ((buffer (current-buffer)) (marker (copy-marker start)) - ;; Keep url.el from spamming us with messages about connecting to hosts: - (url-show-status nil)) + ;; Keep url.el from spamming us with messages about connecting to hosts: + (url-show-status nil)) (condition-case nil ;; catch any errors in url-retrieve so as to not abort ;; whatever called us @@ -226,7 +224,6 @@ REGION-LENGTH is the range from start to propertize." (defun mastodon-media--select-next-media-line (end-pos) "Find coordinates of the next media to load before END-POS. - Returns the list of (`start' . `end', `media-symbol') points of that line and string found or nil no more media links were found." @@ -249,7 +246,6 @@ found." (defun mastodon-media--valid-link-p (link) "Check if LINK is valid. - Checks to make sure the missing string has not been returned." (and link (> (length link) 8) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b7fe038..a36b99e 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -244,7 +244,6 @@ Status notifications are given when author-byline action-byline id &optional base-toot) "Display the content and byline of timeline element TOOT. - BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 1aed676..24ddfb3 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -230,13 +230,11 @@ user's profile note. This is also called by (defun mastodon-search--get-id-from-status (status) "Fetch the id from a STATUS returned by a search call to the server. - We use this to fetch the complete status from the server." (alist-get 'id status)) (defun mastodon-search--fetch-full-status-from-id (id) "Fetch the full status with id ID from the server. - This allows us to access the full account etc. details and to render them properly." (let* ((url (concat mastodon-instance-url "/api/v1/statuses/" (mastodon-tl--as-string id))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9f21bf9..0d93b8d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -103,7 +103,6 @@ (defcustom mastodon-tl--enable-relative-timestamps t "Whether to show relative (to the current time) timestamps. - This will require periodic updates of a timeline buffer to keep the timestamps current as time progresses." :group 'mastodon-tl @@ -111,7 +110,6 @@ keep the timestamps current as time progresses." (defcustom mastodon-tl--enable-proportional-fonts nil "Nonnil to enable using proportional fonts when rendering HTML. - By default fixed width fonts are used." :group 'mastodon-tl :type '(boolean :tag "Enable using proportional rather than fixed \ @@ -161,7 +159,6 @@ Valid values are: (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 @@ -185,7 +182,6 @@ If nil `(point-min)' is used instead.") (define-key map [follow-link] 'mouse-face) (keymap-canonicalize map)) "The keymap for link-like things in buffer (except for shr.el generate links). - This will make the region of text act like like a link with mouse highlighting, mouse click action tabbing to next/previous link etc.") @@ -201,7 +197,6 @@ etc.") (define-key map [remap shr-browse-url] 'mastodon-url-lookup) (keymap-canonicalize map)) "The keymap to be set for shr.el generated links that are not images. - We need to override the keymap so tabbing will navigate to all types of mastodon links and not just shr.el-generated ones.") @@ -224,7 +219,6 @@ types of mastodon links and not just shr.el-generated ones.") (define-key map (kbd "") 'mastodon-tl--mpv-play-video-at-point) (keymap-canonicalize map)) "The keymap to be set for shr.el generated image links. - We need to override the keymap so tabbing will navigate to all types of mastodon links and not just shr.el-generated ones.") @@ -305,7 +299,6 @@ NAME is not part of the symbol table, '?' is returned." (defun mastodon-tl--next-tab-item () "Move to the next interesting item. - This could be the next toot, link, or image; whichever comes first. Don't move if nothing else to move to is found, i.e. near the end of the buffer. This also skips tab items in invisible text, i.e. hidden spoiler text." @@ -326,7 +319,6 @@ This also skips tab items in invisible text, i.e. hidden spoiler text." (defun mastodon-tl--previous-tab-item () "Move to the previous interesting item. - This could be the previous toot, link, or image; whichever comes first. Don't move if nothing else to move to is found, i.e. near the start of the buffer. This also skips tab items in invisible @@ -569,14 +561,12 @@ The result is added as an attachments property to author-byline." (defun mastodon-tl--field (field toot) "Return FIELD from TOOT. - Return value from boosted content if available." (or (alist-get field (alist-get 'reblog toot)) (alist-get field toot))) (defun mastodon-tl--relative-time-details (timestamp &optional current-time) "Return cons of (descriptive string . next change) for the TIMESTAMP. - Use the optional CURRENT-TIME as the current time (only used for reliable testing). @@ -631,7 +621,6 @@ TIMESTAMP is assumed to be in the past." (defun mastodon-tl--relative-time-description (timestamp &optional current-time) "Return a string with a human readable TIMESTAMP relative to the current time. - Use the optional CURRENT-TIME as the current time (only used for reliable testing). @@ -641,7 +630,6 @@ TIME-STAMP is assumed to be in the past." (defun mastodon-tl--byline (toot author-byline action-byline &optional detailed-p) "Generate byline for TOOT. - AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. ACTION-BYLINE is a function for adding an action, such as boosting, @@ -784,7 +772,6 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (defun mastodon-tl--render-text (string &optional toot) "Return a propertized text rendering the given HTML string STRING. - The contents comes from the given TOOT which is used in parsing links in the text. If TOOT is nil no parsing occurs." (when string ; handle rare empty notif server bug @@ -896,7 +883,6 @@ Return nil if no matching element" (defun mastodon-tl--extract-userhandle-from-url (url buffer-text) "Return the user hande the URL points to or nil if it is not a profile link. - BUFFER-TEXT is the text covered by the link with URL, for a user profile this should be of the form , e.g. \"@Gargon\"." (let* ((parsed-url (url-generic-parse-url url)) @@ -912,7 +898,6 @@ this should be of the form , e.g. \"@Gargon\"." (defun mastodon-tl--extract-hashtag-from-url (url instance-url) "Return the hashtag that URL points to or nil if URL is not a tag link. - INSTANCE-URL is the url of the instance for the toot that the link came from (tag links always point to a page on the instance publishing the toot)." @@ -963,7 +948,6 @@ the toot)." (defun mastodon-tl--make-link (string link-type) "Return a propertized version of STRING that will act like link. - LINK-TYPE is the type of link to produce." (let ((help-text (cond ((eq link-type 'content-warning) @@ -1020,7 +1004,6 @@ Used for a mouse-click EVENT on a link." (defun mastodon-tl--has-spoiler (toot) "Check if the given TOOT has a spoiler text. - Spoiler text should initially be shown only while the main content should be hidden." (let ((spoiler (mastodon-tl--field 'spoiler_text toot))) @@ -1033,7 +1016,6 @@ content should be hidden." (defun mastodon-tl--spoiler (toot) "Render TOOT with spoiler message. - This assumes TOOT is a toot with a spoiler message. The main body gets hidden and only the spoiler text and the content warning message are displayed. The content warning @@ -1111,7 +1093,6 @@ message is a link which unhides/hides the main body." (defun mastodon-tl--propertize-img-str-or-url (str media-url full-remote-url type help-echo &optional display face) "Propertize an media placeholder string \"[img]\" or media URL. - STR is the string to propertize, MEDIA-URL is the preview link, FULL-REMOTE-URL is the link to the full resolution image on the server, TYPE is the media type. @@ -1150,11 +1131,11 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id base-toot detailed-p) "Display the content and byline of timeline element TOOT. - BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author portion of the byline that takes one variable. By default it is -`mastodon-tl--byline-author' +`mastodon-tl--byline-author'. + ACTION-BYLINE is also an optional function for adding an action, such as boosting favouriting and following to the byline. It also takes a single function. By default it is @@ -1350,7 +1331,6 @@ in which case play first video or gif from current toot." (defun mastodon-tl--toot (toot &optional detailed-p) "Formats TOOT and insertes it into the buffer. - DETAILED-P means display more detailed info. For now this just means displaying toot client." (mastodon-tl--insert-status @@ -1439,7 +1419,6 @@ PARAMS are any parameters to send with the request." (defun mastodon-tl--property (prop &optional backward) "Get property PROP for toot at point. - Move forward (down) the timeline unless BACKWARD is non-nil." (or (get-text-property (point) prop) (save-excursion @@ -1471,7 +1450,6 @@ Move forward (down) the timeline unless BACKWARD is non-nil." (defun mastodon-tl--toot-id (json) "Find approproiate toot id in JSON. - If the toot has been boosted use the id found in the reblog portion of the toot. Otherwise, use the body of the toot. This is the same behaviour as the mastodon.social @@ -2634,7 +2612,6 @@ HEADERS is the http headers returned in the response, if any." (defun mastodon-tl--find-property-range (property start-point &optional search-backwards) "Return `nil` if no such range is found. - If PROPERTY is set at START-POINT returns a range around START-POINT otherwise before/after START-POINT. @@ -2670,7 +2647,6 @@ before (non-nil) or after (nil)" (defun mastodon-tl--find-next-or-previous-property-range (property start-point search-backwards) "Find (start . end) property range after/before START-POINT. - Does so while PROPERTY is set to a consistent value (different from the value at START-POINT if that is set). @@ -2695,7 +2671,6 @@ START-POINT otherwise after START-POINT." (defun mastodon-tl--consider-timestamp-for-updates (timestamp) "Take note that TIMESTAMP is used in buffer and ajust timers as needed. - This calculates the next time the text for TIMESTAMP will change and may adjust existing or future timer runs should that time before current plans to run the update function. @@ -2725,7 +2700,6 @@ is a no-op." (defun mastodon-tl--update-timestamps-callback (buffer previous-marker) "Update the next few timestamp displays in BUFFER. - Start searching for more timestamps from PREVIOUS-MARKER or from the start if it is nil." ;; only do things if the buffer hasn't been killed in the meantime @@ -2891,7 +2865,6 @@ JSON and http headers, without it just the JSON." (defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type) "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 note." diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 56ad4ed..99b5936 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -113,7 +113,6 @@ Used for completion in toot compose buffer." (defcustom mastodon-toot--use-company-for-completion nil "Whether to enable company for completion. - When non-nil, `company-mode' is enabled in the toot compose buffer, and mastodon completion backends are added to `company-capf'. @@ -160,7 +159,6 @@ You need to install company yourself to use this." (defvar-local mastodon-toot--visibility nil "A string indicating the visibility of the toot being composed. - Valid values are \"direct\", \"private\" (followers-only), \"unlisted\", and \"public\". @@ -279,7 +277,6 @@ NO-TOOT means we are not calling from a toot buffer." (defun mastodon-toot--action-success (marker byline-region remove) "Insert/remove the text MARKER with 'success face in byline. - BYLINE-REGION is a cons of start and end pos of the byline to be modified. Remove MARKER if REMOVE is non-nil, otherwise add it." @@ -299,7 +296,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (insert (format "(%s) " (propertize marker 'face 'success))))) (when at-byline-p - ;; leave point after the marker: + ;; leave point after the marker: (unless remove (mastodon-tl--goto-next-toot))))) @@ -855,7 +852,6 @@ Remove empty string (self) from result and joins the sequence with whitespace." (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-instance-url). diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a6ee4bc..cd7dd8e 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -61,7 +61,6 @@ (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--show-user "mastodon-profile") (autoload 'mastodon-discover "mastodon-discover") - (autoload 'mastodon-tl--block-user "mastodon-tl") (autoload 'mastodon-tl--unblock-user "mastodon-tl") (autoload 'mastodon-tl--mute-user "mastodon-tl") @@ -107,7 +106,6 @@ (defcustom mastodon-instance-url "https://mastodon.social" "Base URL for the Mastodon instance you want to be active. - For example, if your mastodon username is \"example_user@social.instance.org\", and you want this account to be active, the value of this variable should be @@ -123,7 +121,6 @@ changes to take effect." (defcustom mastodon-active-user nil "Username of the active user. - For example, if your mastodon username is \"example_user@social.instance.org\", and you want this account to be active, the value of this variable should be @@ -139,7 +136,6 @@ changes to take effect." (defcustom mastodon-toot-timestamp-format "%F %T" "Format to use for timestamps. - For valid formatting options see `format-time-string`. The default value \"%F %T\" prints ISO8601-style YYYY-mm-dd HH:MM:SS. Use. e.g. \"%c\" for your locale's date and time format." -- cgit v1.2.3 From eb8141cff000ce74a6aeb096a20cbaa9b92b8662 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 9 Jan 2023 20:51:36 +1100 Subject: factor out mastodon-tl--update-params. we use this so that things don't break when (mastodon-tl--get-buffer-property 'update-params) is called when update-params is not set, which causes an error. we might also just remove the error call in that function and return nil if a buffer prop is not set. --- lisp/mastodon-tl.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index dbeacab..72cc4a1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1390,6 +1390,11 @@ Optionally get it for BUFFER." Optionally get it for BUFFER." (mastodon-tl--get-buffer-property 'link-header buffer)) +(defun mastodon-tl--update-params (&optional buffer) + "Get the UPDATE PARAMS stored in `mastodon-tl--buffer-spec'. +Optionally get it for BUFFER." + (mastodon-tl--get-buffer-property 'update-params buffer)) + (defun mastodon-tl--get-buffer-property (property &optional buffer) "Get PROPERTY from `mastodon-tl--buffer-spec' in BUFFER or `current-buffer'." (with-current-buffer (or buffer (current-buffer)) @@ -2607,7 +2612,7 @@ when showing followers or accounts followed." (mastodon-tl--more-json-async (mastodon-tl--get-endpoint) (mastodon-tl--oldest-id) - (mastodon-tl--get-buffer-property 'update-params) + (mastodon-tl--update-params) 'mastodon-tl--more* (current-buffer) (point)))) (defun mastodon-tl--more* (response buffer point-before &optional headers) @@ -2812,7 +2817,7 @@ This location is defined by a non-nil value of (funcall update-function thread-id) ;; update other timelines: (let* ((id (mastodon-tl--newest-id)) - (params (mastodon-tl--get-buffer-property 'update-params)) + (params (mastodon-tl--update-params)) (json (mastodon-tl--updated-json endpoint id params))) (if json (let ((inhibit-read-only t)) -- cgit v1.2.3 From a37171ea14bd727493188e3c753dd60580f563ce Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 9 Jan 2023 20:59:34 +1100 Subject: tl--get-buff-prop: don't error if we find nothing. that way we can call buffer-spec fetch funs without knowing if they're set. --- lisp/mastodon-tl.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 72cc4a1..5bd5963 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1398,9 +1398,10 @@ Optionally get it for BUFFER." (defun mastodon-tl--get-buffer-property (property &optional buffer) "Get PROPERTY from `mastodon-tl--buffer-spec' in BUFFER or `current-buffer'." (with-current-buffer (or buffer (current-buffer)) - (or (plist-get mastodon-tl--buffer-spec property) - (error "Mastodon-tl--buffer-spec is not defined for buffer %s" - (or buffer (current-buffer)))))) + ;; (or + (plist-get mastodon-tl--buffer-spec property))) + ;; (error "Mastodon-tl--buffer-spec is not defined for buffer %s" + ;; (or buffer (current-buffer)))))) (defun mastodon-tl--set-buffer-spec (buffer endpoint update-function &optional link-header update-params) -- cgit v1.2.3 From 8ef99af1b32d6f85368474dbea9fffe50d12b614 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 10 Jan 2023 10:12:14 +1100 Subject: optional no-error arg for get-buffer-property used by update-params and link-header, as they are optionally set in buffer spec --- lisp/mastodon-tl.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5bd5963..1372777 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1388,20 +1388,22 @@ Optionally get it for BUFFER." (defun mastodon-tl--link-header (&optional buffer) "Get the LINK HEADER stored in `mastodon-tl--buffer-spec'. Optionally get it for BUFFER." - (mastodon-tl--get-buffer-property 'link-header buffer)) + (mastodon-tl--get-buffer-property 'link-header buffer :no-error)) (defun mastodon-tl--update-params (&optional buffer) "Get the UPDATE PARAMS stored in `mastodon-tl--buffer-spec'. Optionally get it for BUFFER." - (mastodon-tl--get-buffer-property 'update-params buffer)) + (mastodon-tl--get-buffer-property 'update-params buffer :no-error)) -(defun mastodon-tl--get-buffer-property (property &optional buffer) - "Get PROPERTY from `mastodon-tl--buffer-spec' in BUFFER or `current-buffer'." +(defun mastodon-tl--get-buffer-property (property &optional buffer no-error) + "Get PROPERTY from `mastodon-tl--buffer-spec' in BUFFER or `current-buffer'. +If NO-ERROR is non-nil, do not error when property is empty." (with-current-buffer (or buffer (current-buffer)) - ;; (or - (plist-get mastodon-tl--buffer-spec property))) - ;; (error "Mastodon-tl--buffer-spec is not defined for buffer %s" - ;; (or buffer (current-buffer)))))) + (if no-error + (plist-get mastodon-tl--buffer-spec property) + (or (plist-get mastodon-tl--buffer-spec property) + (error "Mastodon-tl--buffer-spec is not defined for buffer %s" + (or buffer (current-buffer))))))) (defun mastodon-tl--set-buffer-spec (buffer endpoint update-function &optional link-header update-params) -- cgit v1.2.3 From 3b35b51a36976d64bc3368d6bd8cce5edb350839 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 11 Jan 2023 00:23:48 +1100 Subject: customize number of posts displayed in a timeline or account view FIXES #363 --- README.org | 1 + lisp/mastodon-profile.el | 3 ++- lisp/mastodon-tl.el | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/README.org b/README.org index 49e65a9..dfbb95c 100644 --- a/README.org +++ b/README.org @@ -269,6 +269,7 @@ See =M-x customize-group RET mastodon= to view all customize options. - Timeline options: - Use proportional fonts + - Default number of posts displayed - Timestamp format - Relative timestamps - Display user avatars diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7e3262a..f96ecb5 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -621,7 +621,8 @@ FIELDS means provide a fields vector fetched by other means." NO-REBLOGS means do not display boosts in statuses. HEADERS means also fetch link headers for pagination." (let* ((id (mastodon-profile--account-field account 'id)) - (args (when no-reblogs '(("exclude_reblogs" . "t")))) + (args `(("limit" . ,mastodon-tl--timeline-posts-count))) + (args (if no-reblogs (push '("exclude_reblogs" . "t") args) args)) (endpoint (format "accounts/%s/%s" id endpoint-type)) (url (mastodon-http--api endpoint)) (acct (mastodon-profile--account-field account 'acct)) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1ec0208..a86a7e6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -157,6 +157,11 @@ Valid values are: (const :tag "Keep original position of point" keep-point) (const :tag "The last toot before the new ones" last-old-toot))) +(defcustom mastodon-tl--timeline-posts-count "20" + "Number of posts to display when loading a timeline. +Must be an integer between 20 and 40 inclusive." + :type '(string)) + (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.") @@ -395,14 +400,16 @@ Used on initializing a timeline or thread." (interactive) (message "Loading federated timeline...") (mastodon-tl--init - "federated" "timelines/public" 'mastodon-tl--timeline)) + "federated" "timelines/public" 'mastodon-tl--timeline nil + `(("limit" . ,mastodon-tl--timeline-posts-count)))) (defun mastodon-tl--get-home-timeline () "Opens home timeline." (interactive) (message "Loading home timeline...") (mastodon-tl--init - "home" "timelines/home" 'mastodon-tl--timeline)) + "home" "timelines/home" 'mastodon-tl--timeline nil + `(("limit" . ,mastodon-tl--timeline-posts-count)))) (defun mastodon-tl--get-local-timeline () "Opens local timeline." @@ -410,7 +417,8 @@ Used on initializing a timeline or thread." (message "Loading local timeline...") (mastodon-tl--init "local" "timelines/public" 'mastodon-tl--timeline - nil '(("local" . "true")))) + nil `(("local" . "true") + ("limit" . ,mastodon-tl--timeline-posts-count)))) (defun mastodon-tl--get-tag-timeline () "Prompt for tag and opens its timeline." @@ -424,7 +432,9 @@ Used on initializing a timeline or thread." (defun mastodon-tl--show-tag-timeline (tag) "Opens a new buffer showing the timeline of posts with hastag TAG." (mastodon-tl--init - (concat "tag-" tag) (concat "timelines/tag/" tag) 'mastodon-tl--timeline)) + (concat "tag-" tag) (concat "timelines/tag/" tag) + 'mastodon-tl--timeline nil + `(("limit" . ,mastodon-tl--timeline-posts-count)))) (defun mastodon-tl--message-help-echo () "Call message on 'help-echo property at point. -- cgit v1.2.3 From e7435eddc825beae3e9d68c4aba8ee08179e41f6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 11 Jan 2023 10:47:58 +1100 Subject: add funs --get-buffer-type and --has-toots-p still need to actually use these in the codebase tho --- lisp/mastodon-tl.el | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a86a7e6..d41e403 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1411,6 +1411,76 @@ UPDATE-PARAMS is any http parameters needed for the update function." link-header ,link-header update-params ,update-params))) +(defun mastodon-tl--get-buffer-type () + "Return a symbol descriptive of current mastodon buffer type. +Should work in all mastodon buffers." + (cond (mastodon-toot-mode + 'compose-toot) + ;; main timelines: + ((string= "timelines/home" (mastodon-tl--get-endpoint)) + 'home) + ((string= "timelines/public" (mastodon-tl--get-endpoint)) + 'federated) + ((string= "*mastodon-local*" (mastodon-tl--buffer-name)) + 'local) + ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) + 'tag-timeline) + ;; notifs: + ((string= "notifications" (mastodon-tl--get-endpoint)) + 'notifications) + ;; NB: check for mentions/filtering + ;; threads: + ((string-suffix-p "context" (mastodon-tl--get-endpoint)) + 'thread) + ;; profiles: + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (cond ; posts + ((string-suffix-p "statuses" (mastodon-tl--get-endpoint)) + 'profile-statuses) + ;; profile followers + ((string-suffix-p "followers" (mastodon-tl--get-endpoint)) + 'profile-followers) + ;; profile following + ((string-suffix-p "following" (mastodon-tl--get-endpoint)) + 'profile-following))) + ;; search + ((string-suffix-p "search" (mastodon-tl--get-endpoint)) + 'search) + ((string-suffix-p "trends" (mastodon-tl--get-endpoint)) + 'trending-tags) + ;; User's views: + ((string= "filters" (mastodon-tl--get-endpoint)) + 'filters) + ((string-prefix-p "lists" (mastodon-tl--get-endpoint)) + 'lists) + ((string= "suggestions" (mastodon-tl--get-endpoint)) + 'follow-suggestions) + ((string= "favourites" (mastodon-tl--get-endpoint)) + 'favourites) + ((string= "bookmarks" (mastodon-tl--get-endpoint)) + 'bookmarks) + ((string= "follow_requests" (mastodon-tl--get-endpoint)) + 'follow-requests) + ;; profile note + ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) + 'update-profile-note) + ;; instance description + ((string= "instance" (mastodon-tl--get-endpoint)) + 'instance-description))) + +(defun mastodon-tl--has-toots-p () + "Return non-nil if the current buffer contains toots. +Return value is that of `member'. +This is used to avoid running into trouble using functions that +presume we are in a timline of toots or similar elements, such as +`mastodon-tl--property'." + (let ((toot-buffers + '(home federated local tag-timeline notifications + thread profile-statuses search trending-tags bookmarks + favourites))) + ;; profile-followers profile following + (member (mastodon-tl--get-buffer-type) toot-buffers))) + (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) -- cgit v1.2.3 From 56fb980cb9e7cfc1e13e45312c964be8a0fd3e90 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 13 Jan 2023 09:31:43 +0100 Subject: case-insensitive match for --get-link-header-from-response pleroma uses "link", not "Link". FIXES #352 --- lisp/mastodon-tl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a86a7e6..7ca0ddd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2818,7 +2818,8 @@ This location is defined by a non-nil value of (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." (when headers - (split-string (alist-get "Link" headers nil nil 'equal) ", "))) + ;; pleroma uses "link", so case-insensitive match required: + (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) (defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT asynchronously. -- cgit v1.2.3 From 69dcaa6136a31553674f85fc6f1536a2167e1307 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 14 Jan 2023 07:20:14 +0100 Subject: add list timelines and scheduled statuses to --get-buffer-type --- lisp/mastodon-tl.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d41e403..732e1c0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1425,6 +1425,8 @@ Should work in all mastodon buffers." 'local) ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) 'tag-timeline) + ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint)) + 'tag-timeline) ;; notifs: ((string= "notifications" (mastodon-tl--get-endpoint)) 'notifications) @@ -1451,7 +1453,7 @@ Should work in all mastodon buffers." ;; User's views: ((string= "filters" (mastodon-tl--get-endpoint)) 'filters) - ((string-prefix-p "lists" (mastodon-tl--get-endpoint)) + ((string= "lists" (mastodon-tl--get-endpoint)) 'lists) ((string= "suggestions" (mastodon-tl--get-endpoint)) 'follow-suggestions) @@ -1461,9 +1463,11 @@ Should work in all mastodon buffers." 'bookmarks) ((string= "follow_requests" (mastodon-tl--get-endpoint)) 'follow-requests) + ((string= "scheduled_statuses" (mastodon-tl--get-endpoint)) + 'scheduled-statuses) ;; profile note ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) - 'update-profile-note) + 'update-profile-note) ;; instance description ((string= "instance" (mastodon-tl--get-endpoint)) 'instance-description))) -- cgit v1.2.3 From c1731fda740af4850109531b2fd1ebd9dee3a07d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 14 Jan 2023 09:16:02 +0100 Subject: add fun --timeline-proper-p --- lisp/mastodon-tl.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 732e1c0..a240f67 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1485,6 +1485,13 @@ presume we are in a timline of toots or similar elements, such as ;; profile-followers profile following (member (mastodon-tl--get-buffer-type) toot-buffers))) +(defun mastodon-tl--timeline-proper-p () + "Return non-nil if the current buffer is a 'proper' timeline. +A proper timeline excludes notifications, threads, and other toot +buffers that aren't strictly mastodon timelines." + (let ((timeline-buffers '(home federated local tag-timeline profile-statuses))) + (member (mastodon-tl--get-buffer-type) timeline-buffers))) + (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) -- cgit v1.2.3 From 3506668a6ab9449816c46f827f249ebd2a5d8ac9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:18:55 +0100 Subject: fix set buffer-spec for instance-description --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a240f67..31ef328 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2240,9 +2240,6 @@ INSTANCE is an instance domain name." (let ((buf (get-buffer-create "*mastodon-instance*"))) (with-current-buffer buf (switch-to-buffer-other-window buf) - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) (let ((inhibit-read-only t)) (erase-buffer) (special-mode) @@ -2260,6 +2257,9 @@ INSTANCE is an instance domain name." (assoc 'stats response)))) (mastodon-tl--print-json-keys response) (mastodon-mode) + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) (goto-char (point-min))))))))) (defun mastodon-tl--format-key (el pad) -- cgit v1.2.3 From b1a3fd043383b4c19ca3bae21d965365c565be15 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:19:39 +0100 Subject: make sure get-buffer-type really works in all views --- lisp/mastodon-tl.el | 68 +++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 31ef328..36511ef 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1365,15 +1365,15 @@ this just means displaying toot client." Optionally get it for BUFFER." (mastodon-tl--get-buffer-property 'update-function buffer)) -(defun mastodon-tl--get-endpoint (&optional buffer) +(defun mastodon-tl--get-endpoint (&optional buffer no-error) "Get the ENDPOINT stored in `mastodon-tl--buffer-spec'. Optionally set it for BUFFER." - (mastodon-tl--get-buffer-property 'endpoint buffer)) + (mastodon-tl--get-buffer-property 'endpoint buffer no-error)) -(defun mastodon-tl--buffer-name (&optional buffer) +(defun mastodon-tl--buffer-name (&optional buffer no-error) "Get the BUFFER-NAME stored in `mastodon-tl--buffer-spec'. Optionally get it for BUFFER." - (mastodon-tl--get-buffer-property 'buffer-name buffer)) + (mastodon-tl--get-buffer-property 'buffer-name buffer no-error)) (defun mastodon-tl--link-header (&optional buffer) "Get the LINK HEADER stored in `mastodon-tl--buffer-spec'. @@ -1417,59 +1417,61 @@ Should work in all mastodon buffers." (cond (mastodon-toot-mode 'compose-toot) ;; main timelines: - ((string= "timelines/home" (mastodon-tl--get-endpoint)) + ((string= "timelines/home" (mastodon-tl--get-endpoint nil :no-error)) 'home) - ((string= "timelines/public" (mastodon-tl--get-endpoint)) - 'federated) - ((string= "*mastodon-local*" (mastodon-tl--buffer-name)) + ((string= "*mastodon-local*" (mastodon-tl--buffer-name nil :no-error)) 'local) - ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint)) - 'tag-timeline) - ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint)) + ((string= "timelines/public" (mastodon-tl--get-endpoint nil :no-error)) + 'federated) + ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint nil :no-error)) 'tag-timeline) + ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint nil :no-error)) + 'list-timeline) ;; notifs: - ((string= "notifications" (mastodon-tl--get-endpoint)) + ((string-suffix-p "mentions*" (mastodon-tl--buffer-name nil :no-error)) + 'mentions) + ((string= "notifications" (mastodon-tl--get-endpoint nil :no-error)) 'notifications) - ;; NB: check for mentions/filtering ;; threads: - ((string-suffix-p "context" (mastodon-tl--get-endpoint)) + ((string-suffix-p "context" (mastodon-tl--get-endpoint nil :no-error)) 'thread) ;; profiles: - ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (cond ; posts - ((string-suffix-p "statuses" (mastodon-tl--get-endpoint)) + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint nil :no-error)) + (cond + ;; profile note: + ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name nil :no-error)) + 'update-profile-note) + ;; posts + ((string-suffix-p "statuses" (mastodon-tl--get-endpoint nil :no-error)) 'profile-statuses) ;; profile followers - ((string-suffix-p "followers" (mastodon-tl--get-endpoint)) + ((string-suffix-p "followers" (mastodon-tl--get-endpoint nil :no-error)) 'profile-followers) ;; profile following - ((string-suffix-p "following" (mastodon-tl--get-endpoint)) + ((string-suffix-p "following" (mastodon-tl--get-endpoint nil :no-error)) 'profile-following))) ;; search - ((string-suffix-p "search" (mastodon-tl--get-endpoint)) + ((string-suffix-p "search" (mastodon-tl--get-endpoint nil :no-error)) 'search) - ((string-suffix-p "trends" (mastodon-tl--get-endpoint)) + ((string-suffix-p "trends" (mastodon-tl--get-endpoint nil :no-error)) 'trending-tags) ;; User's views: - ((string= "filters" (mastodon-tl--get-endpoint)) + ((string= "filters" (mastodon-tl--get-endpoint nil :no-error)) 'filters) - ((string= "lists" (mastodon-tl--get-endpoint)) - 'lists) - ((string= "suggestions" (mastodon-tl--get-endpoint)) + ((string= "lists" (mastodon-tl--get-endpoint nil :no-error)) + 'lists-view) + ((string= "suggestions" (mastodon-tl--get-endpoint nil :no-error)) 'follow-suggestions) - ((string= "favourites" (mastodon-tl--get-endpoint)) + ((string= "favourites" (mastodon-tl--get-endpoint nil :no-error)) 'favourites) - ((string= "bookmarks" (mastodon-tl--get-endpoint)) + ((string= "bookmarks" (mastodon-tl--get-endpoint nil :no-error)) 'bookmarks) - ((string= "follow_requests" (mastodon-tl--get-endpoint)) + ((string= "follow_requests" (mastodon-tl--get-endpoint nil :no-error)) 'follow-requests) - ((string= "scheduled_statuses" (mastodon-tl--get-endpoint)) + ((string= "scheduled_statuses" (mastodon-tl--get-endpoint nil :no-error)) 'scheduled-statuses) - ;; profile note - ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name)) - 'update-profile-note) ;; instance description - ((string= "instance" (mastodon-tl--get-endpoint)) + ((string= "instance" (mastodon-tl--get-endpoint nil :no-error)) 'instance-description))) (defun mastodon-tl--has-toots-p () -- cgit v1.2.3 From f72a20bf7b95910febb7bd7c7786f2ec3bba9368 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:23:18 +0100 Subject: factor endpoint/buffer-name fun vars get-buffer-type --- lisp/mastodon-tl.el | 120 ++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 59 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b7054f5..2d06887 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1414,65 +1414,67 @@ UPDATE-PARAMS is any http parameters needed for the update function." (defun mastodon-tl--get-buffer-type () "Return a symbol descriptive of current mastodon buffer type. Should work in all mastodon buffers." - (cond (mastodon-toot-mode - 'compose-toot) - ;; main timelines: - ((string= "timelines/home" (mastodon-tl--get-endpoint nil :no-error)) - 'home) - ((string= "*mastodon-local*" (mastodon-tl--buffer-name nil :no-error)) - 'local) - ((string= "timelines/public" (mastodon-tl--get-endpoint nil :no-error)) - 'federated) - ((string-prefix-p "timelines/tag/" (mastodon-tl--get-endpoint nil :no-error)) - 'tag-timeline) - ((string-prefix-p "timelines/list/" (mastodon-tl--get-endpoint nil :no-error)) - 'list-timeline) - ;; notifs: - ((string-suffix-p "mentions*" (mastodon-tl--buffer-name nil :no-error)) - 'mentions) - ((string= "notifications" (mastodon-tl--get-endpoint nil :no-error)) - 'notifications) - ;; threads: - ((string-suffix-p "context" (mastodon-tl--get-endpoint nil :no-error)) - 'thread) - ;; profiles: - ((string-prefix-p "accounts" (mastodon-tl--get-endpoint nil :no-error)) - (cond - ;; profile note: - ((string-suffix-p "update-profile*" (mastodon-tl--buffer-name nil :no-error)) - 'update-profile-note) - ;; posts - ((string-suffix-p "statuses" (mastodon-tl--get-endpoint nil :no-error)) - 'profile-statuses) - ;; profile followers - ((string-suffix-p "followers" (mastodon-tl--get-endpoint nil :no-error)) - 'profile-followers) - ;; profile following - ((string-suffix-p "following" (mastodon-tl--get-endpoint nil :no-error)) - 'profile-following))) - ;; search - ((string-suffix-p "search" (mastodon-tl--get-endpoint nil :no-error)) - 'search) - ((string-suffix-p "trends" (mastodon-tl--get-endpoint nil :no-error)) - 'trending-tags) - ;; User's views: - ((string= "filters" (mastodon-tl--get-endpoint nil :no-error)) - 'filters) - ((string= "lists" (mastodon-tl--get-endpoint nil :no-error)) - 'lists-view) - ((string= "suggestions" (mastodon-tl--get-endpoint nil :no-error)) - 'follow-suggestions) - ((string= "favourites" (mastodon-tl--get-endpoint nil :no-error)) - 'favourites) - ((string= "bookmarks" (mastodon-tl--get-endpoint nil :no-error)) - 'bookmarks) - ((string= "follow_requests" (mastodon-tl--get-endpoint nil :no-error)) - 'follow-requests) - ((string= "scheduled_statuses" (mastodon-tl--get-endpoint nil :no-error)) - 'scheduled-statuses) - ;; instance description - ((string= "instance" (mastodon-tl--get-endpoint nil :no-error)) - 'instance-description))) + (let ((endpoint-fun (mastodon-tl--get-endpoint nil :no-error)) + (buffer-name-fun (mastodon-tl--buffer-name nil :no-error))) + (cond (mastodon-toot-mode + 'compose-toot) + ;; main timelines: + ((string= "timelines/home" endpoint-fun) + 'home) + ((string= "*mastodon-local*" buffer-name-fun) + 'local) + ((string= "timelines/public" endpoint-fun) + 'federated) + ((string-prefix-p "timelines/tag/" endpoint-fun) + 'tag-timeline) + ((string-prefix-p "timelines/list/" endpoint-fun) + 'list-timeline) + ;; notifs: + ((string-suffix-p "mentions*" buffer-name-fun) + 'mentions) + ((string= "notifications" endpoint-fun) + 'notifications) + ;; threads: + ((string-suffix-p "context" endpoint-fun) + 'thread) + ;; profiles: + ((string-prefix-p "accounts" endpoint-fun) + (cond + ;; profile note: + ((string-suffix-p "update-profile*" buffer-name-fun) + 'update-profile-note) + ;; posts + ((string-suffix-p "statuses" endpoint-fun) + 'profile-statuses) + ;; profile followers + ((string-suffix-p "followers" endpoint-fun) + 'profile-followers) + ;; profile following + ((string-suffix-p "following" endpoint-fun) + 'profile-following))) + ;; search + ((string-suffix-p "search" endpoint-fun) + 'search) + ((string-suffix-p "trends" endpoint-fun) + 'trending-tags) + ;; User's views: + ((string= "filters" endpoint-fun) + 'filters) + ((string= "lists" endpoint-fun) + 'lists-view) + ((string= "suggestions" endpoint-fun) + 'follow-suggestions) + ((string= "favourites" endpoint-fun) + 'favourites) + ((string= "bookmarks" endpoint-fun) + 'bookmarks) + ((string= "follow_requests" endpoint-fun) + 'follow-requests) + ((string= "scheduled_statuses" endpoint-fun) + 'scheduled-statuses) + ;; instance description + ((string= "instance" endpoint-fun) + 'instance-description)))) (defun mastodon-tl--has-toots-p () "Return non-nil if the current buffer contains toots. -- cgit v1.2.3 From ded518df455d7c653d6a1743886f9c9986a585eb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:30:58 +0100 Subject: add list-timeline to timeline-proper-p --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2d06887..3df2a19 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1493,7 +1493,7 @@ presume we are in a timline of toots or similar elements, such as "Return non-nil if the current buffer is a 'proper' timeline. A proper timeline excludes notifications, threads, and other toot buffers that aren't strictly mastodon timelines." - (let ((timeline-buffers '(home federated local tag-timeline profile-statuses))) + (let ((timeline-buffers '(home federated local tag-timeline list-timeline profile-statuses))) (member (mastodon-tl--get-buffer-type) timeline-buffers))) (defun mastodon-tl--more-json (endpoint id) -- cgit v1.2.3 From c366effc9b602f7d5c5e0fdf37233c83f5028e08 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 08:51:11 +0100 Subject: factor instance response, so own instance isn't within do-if-toot this means we can view own instance without point being near a toot at all, as it should be. --- lisp/mastodon-tl.el | 122 +++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 55 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3df2a19..96aaf4b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2210,61 +2210,73 @@ USER means to show the instance details for the logged in user. BRIEF means to show fewer details. INSTANCE is an instance domain name." (interactive) - (mastodon-tl--do-if-toot - (let* ((profile-p (get-text-property (point) 'profile-json)) - (toot (if profile-p - (mastodon-tl--property 'profile-json) ; profile may have 0 toots - (mastodon-tl--property 'toot-json))) - (reblog (alist-get 'reblog toot)) - (account (or (alist-get 'account reblog) - (alist-get 'account toot))) - (url (if profile-p - (alist-get 'url toot) ; profile - (alist-get 'url account))) - (username (if profile-p - (alist-get 'username toot) ;; profile - (alist-get 'username account))) - (instance (if instance - (concat "https://" instance) - ;; pleroma URL is https://instance.com/users/username - (if (string-suffix-p "users/" (url-basepath url)) - (string-remove-suffix "/users/" - (url-basepath url)) - ;; mastodon: - (string-remove-suffix (concat "/@" username) - url)))) - (response (mastodon-http--get-json - (if user - (mastodon-http--api "instance") - (concat instance "/api/v1/instance")) - nil ; params - nil ; silent - :vector))) - (when response - (let ((buf (get-buffer-create "*mastodon-instance*"))) - (with-current-buffer buf - (switch-to-buffer-other-window buf) - (let ((inhibit-read-only t)) - (erase-buffer) - (special-mode) - (when brief - (setq response - (list (assoc 'uri response) - (assoc 'title response) - (assoc 'short_description response) - (assoc 'email response) - (cons 'contact_account - (list - (assoc 'username - (assoc 'contact_account response)))) - (assoc 'rules response) - (assoc 'stats response)))) - (mastodon-tl--print-json-keys response) - (mastodon-mode) - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) - (goto-char (point-min))))))))) + (if user + (let ((response (mastodon-http--get-json + (mastodon-http--api "instance") + nil ; params + nil ; silent + :vector))) + (mastodon-tl--instance-response-fun response brief)) + (mastodon-tl--do-if-toot + (let* ((profile-p (get-text-property (point) 'profile-json)) + (toot (if profile-p + (mastodon-tl--property 'profile-json) ; profile may have 0 toots + (mastodon-tl--property 'toot-json))) + (reblog (alist-get 'reblog toot)) + (account (or (alist-get 'account reblog) + (alist-get 'account toot))) + (url (if profile-p + (alist-get 'url toot) ; profile + (alist-get 'url account))) + (username (if profile-p + (alist-get 'username toot) ;; profile + (alist-get 'username account))) + (instance (if instance + (concat "https://" instance) + ;; pleroma URL is https://instance.com/users/username + (if (string-suffix-p "users/" (url-basepath url)) + (string-remove-suffix "/users/" + (url-basepath url)) + ;; mastodon: + (string-remove-suffix (concat "/@" username) + url)))) + (response (mastodon-http--get-json + (if user + (mastodon-http--api "instance") + (concat instance "/api/v1/instance")) + nil ; params + nil ; silent + :vector))) + (mastodon-tl--instance-response-fun response brief))))) + +(defun mastodon-tl--instance-response-fun (response brief) + "Display instance description RESPONSE in a new buffer. +BRIEF means to show fewer details." + (when response + (let ((buf (get-buffer-create "*mastodon-instance*"))) + (with-current-buffer buf + (switch-to-buffer-other-window buf) + (let ((inhibit-read-only t)) + (erase-buffer) + (special-mode) + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) + (mastodon-tl--print-json-keys response) + (mastodon-mode) + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) + (goto-char (point-min))))))) (defun mastodon-tl--format-key (el pad) "Format a key of element EL, a cons, with PAD padding." -- cgit v1.2.3 From 035c07af4ad93ad1ed3e30d1dc8bb293f375837a Mon Sep 17 00:00:00 2001 From: Moha Date: Thu, 29 Dec 2022 12:47:00 +0100 Subject: Add option to hide replies Additionally adds a prefix to load timelines with no replies Signed-off-by: Moha --- lisp/mastodon-tl.el | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 96aaf4b..99eda44 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -162,6 +162,11 @@ Valid values are: Must be an integer between 20 and 40 inclusive." :type '(string)) +(defcustom mastodon-tl--hide-replies nil + "Whether to hide replies from the timelines." + :group 'mastodon-tl + :type '(boolean :tag "Whether to hide replies from the timelines.")) + (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.") @@ -1339,8 +1344,13 @@ in which case play first video or gif from current toot." (message "no moving image here?")) (message "no moving image here?")))) +(defun mastodon-tl--is-reply (toot) + "Check if the TOOT is a reply to another one (and not boosted)." + (and (null (mastodon-tl--field 'in_reply_to_id toot)) + (not (mastodon-tl--field 'rebloged toot)))) + (defun mastodon-tl--toot (toot &optional detailed-p) - "Formats TOOT and insertes it into the buffer. + "Formats TOOT and inserts it into the buffer. DETAILED-P means display more detailed info. For now this just means displaying toot client." (mastodon-tl--insert-status @@ -1356,8 +1366,12 @@ this just means displaying toot client." detailed-p)) (defun mastodon-tl--timeline (toots) - "Display each toot in TOOTS." - (mapc 'mastodon-tl--toot toots) + "Display each toot in TOOTS. + + This function removes replies if user required." + (mapc 'mastodon-tl--toot (if (mastodon-tl--hide-replies-p current-prefix-arg) + (cl-remove-if-not #'mastodon-tl--is-reply toots) + toots)) (goto-char (point-min))) (defun mastodon-tl--get-update-function (&optional buffer) @@ -1496,6 +1510,20 @@ buffers that aren't strictly mastodon timelines." (let ((timeline-buffers '(home federated local tag-timeline list-timeline profile-statuses))) (member (mastodon-tl--get-buffer-type) timeline-buffers))) +(defun mastodon-tl--hide-replies-p (&optional prefix) + "Return non-nil if replies should be hidden in the timeline. +We hide replies if user explictly set the +`mastodon-tl--hide-replies' or used PREFIX combination to open a +timeline." + (and + ;; Only hide replies if we are in a proper timeline + (mastodon-tl--timeline-proper-p) + (or + ;; User configured to hide replies + mastodon-tl--hide-replies + ;; Timeline called with C-u prefix + (equal '(4) prefix)))) + (defun mastodon-tl--more-json (endpoint id) "Return JSON for timeline ENDPOINT before ID." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) -- cgit v1.2.3 From 842252fbf07e4589a7372a1bbd8e8ca823bb2569 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 15 Jan 2023 17:20:58 +0100 Subject: handle hiding replies when loading more toots into a tl we add a boolean 'hide-replies' element to the tl--buffer-spec plist. then, in --timeline, we check that boolean and hide replies if so. we add new arg to init in order to hand on and store the prefix arg as a boolean. --- lisp/mastodon-tl.el | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 99eda44..1528dc6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -406,7 +406,8 @@ Used on initializing a timeline or thread." (message "Loading federated timeline...") (mastodon-tl--init "federated" "timelines/public" 'mastodon-tl--timeline nil - `(("limit" . ,mastodon-tl--timeline-posts-count)))) + `(("limit" . ,mastodon-tl--timeline-posts-count)) + (when current-prefix-arg t))) (defun mastodon-tl--get-home-timeline () "Opens home timeline." @@ -414,7 +415,8 @@ Used on initializing a timeline or thread." (message "Loading home timeline...") (mastodon-tl--init "home" "timelines/home" 'mastodon-tl--timeline nil - `(("limit" . ,mastodon-tl--timeline-posts-count)))) + `(("limit" . ,mastodon-tl--timeline-posts-count)) + (when current-prefix-arg t))) (defun mastodon-tl--get-local-timeline () "Opens local timeline." @@ -423,7 +425,8 @@ Used on initializing a timeline or thread." (mastodon-tl--init "local" "timelines/public" 'mastodon-tl--timeline nil `(("local" . "true") - ("limit" . ,mastodon-tl--timeline-posts-count)))) + ("limit" . ,mastodon-tl--timeline-posts-count)) + (when current-prefix-arg t))) (defun mastodon-tl--get-tag-timeline () "Prompt for tag and opens its timeline." @@ -1367,11 +1370,14 @@ this just means displaying toot client." (defun mastodon-tl--timeline (toots) "Display each toot in TOOTS. - - This function removes replies if user required." - (mapc 'mastodon-tl--toot (if (mastodon-tl--hide-replies-p current-prefix-arg) - (cl-remove-if-not #'mastodon-tl--is-reply toots) - toots)) +This function removes replies if user required." + (mapc 'mastodon-tl--toot + (if (or ; we were called via --more*: + (mastodon-tl--get-buffer-property 'hide-replies nil :no-error) + ;; loading a tl with a prefix arg: + (mastodon-tl--hide-replies-p current-prefix-arg)) + (cl-remove-if-not #'mastodon-tl--is-reply toots) + toots)) (goto-char (point-min))) (defun mastodon-tl--get-update-function (&optional buffer) @@ -1410,7 +1416,8 @@ If NO-ERROR is non-nil, do not error when property is empty." (or buffer (current-buffer))))))) (defun mastodon-tl--set-buffer-spec (buffer endpoint update-function - &optional link-header update-params) + &optional link-header update-params + hide-replies) "Set `mastodon-tl--buffer-spec' for the current buffer. BUFFER is buffer name, ENDPOINT is buffer's enpoint, UPDATE-FUNCTION is its update function. @@ -1423,7 +1430,8 @@ UPDATE-PARAMS is any http parameters needed for the update function." endpoint ,endpoint update-function ,update-function link-header ,link-header - update-params ,update-params))) + update-params ,update-params + hide-replies ,hide-replies))) (defun mastodon-tl--get-buffer-type () "Return a symbol descriptive of current mastodon buffer type. @@ -2946,7 +2954,8 @@ This location is defined by a non-nil value of ;; pleroma uses "link", so case-insensitive match required: (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) -(defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params) +(defun mastodon-tl--init (buffer-name endpoint update-function + &optional headers params hide-replies) "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 @@ -2955,13 +2964,15 @@ PARAMS is any parameters to send with the request." (let ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*"))) (if headers - (mastodon-http--get-response-async - url params 'mastodon-tl--init* buffer endpoint update-function headers params) - (mastodon-http--get-json-async - url params 'mastodon-tl--init* buffer endpoint update-function nil params)))) + (mastodon-http--get-response-async url params + 'mastodon-tl--init* buffer endpoint update-function + headers params hide-replies) + (mastodon-http--get-json-async url params + 'mastodon-tl--init* buffer endpoint update-function nil + params hide-replies)))) (defun mastodon-tl--init* (response buffer endpoint update-function - &optional headers update-params) + &optional headers update-params hide-replies) "Initialize BUFFER with timeline targeted by ENDPOINT. UPDATE-FUNCTION is used to recieve more toots. RESPONSE is the data returned from the server by @@ -2982,7 +2993,8 @@ JSON and http headers, without it just the JSON." endpoint update-function link-header - update-params) + update-params + hide-replies) (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed @@ -2995,7 +3007,8 @@ JSON and http headers, without it just the JSON." endpoint update-function link-header - update-params) + update-params + hide-replies) (setq mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps (run-at-time (time-to-seconds -- cgit v1.2.3 From 78eb53aacb42480a2b387b76ca90946b114985d3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 16 Jan 2023 07:59:30 +0100 Subject: buffer-spec for toot-edits history and add check to get-buffer-type --- lisp/mastodon-tl.el | 4 +++- lisp/mastodon-toot.el | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 96aaf4b..e01d3a7 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1474,7 +1474,9 @@ Should work in all mastodon buffers." 'scheduled-statuses) ;; instance description ((string= "instance" endpoint-fun) - 'instance-description)))) + 'instance-description) + ((string= "*mastodon-toot-edits*" buffer-name-fun) + 'toot-edits)))) (defun mastodon-tl--has-toots-p () "Return non-nil if the current buffer contains toots. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 177cfdc..2241805 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -815,7 +815,8 @@ instance to edit a toot." (defun mastodon-toot--view-toot-edits () "View editing history of the toot at point in a popup buffer." (interactive) - (let ((history (mastodon-tl--property 'edit-history))) + (let ((id (mastodon-tl--property 'base-toot-id)) + (history (mastodon-tl--property 'edit-history))) (with-current-buffer (get-buffer-create "*mastodon-toot-edits*") (let ((inhibit-read-only t)) (special-mode) @@ -836,7 +837,10 @@ instance to edit a toot." (format "Edits to toot by %s:" (alist-get 'username (alist-get 'account (car history)))) - 'face font-lock-comment-face)))))) + 'face font-lock-comment-face)) + (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) + (format "statuses/%s/history" id) + nil))))) (defun mastodon-toot--insert-toot-iter (it) "Insert iteration IT of toot." -- cgit v1.2.3 From 3080367aff71487cab83cabf52c62d22e0a42167 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 16 Jan 2023 08:34:53 +0100 Subject: add single-status check to get-buffer-type --- lisp/mastodon-tl.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e01d3a7..9234b77 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1437,6 +1437,8 @@ Should work in all mastodon buffers." ;; threads: ((string-suffix-p "context" endpoint-fun) 'thread) + ((string-prefix-p "statuses" endpoint-fun) + 'single-status) ;; profiles: ((string-prefix-p "accounts" endpoint-fun) (cond -- cgit v1.2.3 From 247a2e71eed80ed3d09d1e3eba90b306c6aeb347 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 16 Jan 2023 08:53:26 +0100 Subject: tl--get-users-followings - set limit to 80 --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9234b77..dd17988 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1883,7 +1883,7 @@ a: add account to this list, r: remove account from this list" "Return the list of followers of the logged in account." (let* ((id (mastodon-auth--get-account-id)) (url (mastodon-http--api (format "accounts/%s/following" id)))) - (mastodon-http--get-json url))) + (mastodon-http--get-json url '(("limit" . "80"))))) ; max 80 accounts (defun mastodon-tl--add-account-to-list-at-point () "Prompt for account and add to list at point." -- cgit v1.2.3 From 098f8b1e73e10801c55d4c470906bca6edd75251 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 16 Jan 2023 10:55:06 +0100 Subject: differentiate edit toot from new toot --- lisp/mastodon-tl.el | 5 ++++- lisp/mastodon-toot.el | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index dd17988..931fa0b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1417,7 +1417,10 @@ Should work in all mastodon buffers." (let ((endpoint-fun (mastodon-tl--get-endpoint nil :no-error)) (buffer-name-fun (mastodon-tl--buffer-name nil :no-error))) (cond (mastodon-toot-mode - 'compose-toot) + ;; composing/editing: + (if (string= "*edit toot*" (buffer-name)) + 'edit-toot + 'new-toot)) ;; main timelines: ((string= "timelines/home" endpoint-fun) 'home) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 2241805..0d4f9e2 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -793,9 +793,9 @@ instance to edit a toot." (toot-language (alist-get 'language toot)) (reply-id (alist-get 'in_reply_to_id toot))) (when (y-or-n-p "Edit this toot? ") - (mastodon-toot--compose-buffer) + (mastodon-toot--compose-buffer nil reply-id nil content :edit) (goto-char (point-max)) - (insert content) + ;; (insert content) ;; adopt reply-to-id, visibility, CW, and language: (mastodon-toot--set-toot-properties reply-id toot-visibility source-cw toot-language) @@ -1543,15 +1543,17 @@ Added to `after-change-functions'." ;; NB: now that we have toot drafts, to ensure offline composing remains ;; possible, avoid any direct requests here: (defun mastodon-toot--compose-buffer (&optional reply-to-user - reply-to-id reply-json initial-text) + reply-to-id reply-json initial-text + edit) "Create a new buffer to capture text for a new toot. If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the `mastodon-toot--reply-to-id' var. REPLY-JSON is the full JSON of the toot being replied to. INITIAL-TEXT is used by `mastodon-toot-insert-draft-toot' to add a draft into the buffer." - (let* ((buffer-exists (get-buffer "*new toot*")) - (buffer (or buffer-exists (get-buffer-create "*new toot*"))) + (let* ((buffer-name (if edit "*edit toot*" "*new toot*")) + (buffer-exists (get-buffer buffer-name)) + (buffer (or buffer-exists (get-buffer-create buffer-name))) (inhibit-read-only t) (reply-text (alist-get 'content reply-json)) (previous-window-config (list (current-window-configuration) -- cgit v1.2.3 From 5faed06cc47238ffea43145204a90a2bd13b6bf2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 27 Jan 2023 18:47:20 +0100 Subject: tl--more*: handle calling on last toot in thread view. FIXES #384 for now we funcall tl--thread not on JSON, but on thread parent ID. this will load whole thread, which may be significantly larger than current thread branch view. maybe need more subtlety, later. --- lisp/mastodon-tl.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8c20b77..5133cad 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2758,7 +2758,12 @@ HEADERS is the http headers returned in the response, if any." (headers (if headers (cdr response) nil)) (link-header (mastodon-tl--get-link-header-from-response headers))) (goto-char (point-max)) - (funcall (mastodon-tl--get-update-function) json) + (if (eq (mastodon-tl--get-buffer-type) 'thread) + ;; if thread view, call --thread with parent ID + (progn (goto-char (point-min)) + (mastodon-tl--goto-next-toot) + (funcall (mastodon-tl--get-update-function))) + (funcall (mastodon-tl--get-update-function) json)) (goto-char point-before) ;; update buffer spec to new link-header: ;; (other values should just remain as they were) -- cgit v1.2.3 From 4c276b5757dfef3e8e061811ec9d59ed36d6d8d9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 28 Jan 2023 09:17:48 +0100 Subject: ignore --hide-replies on profile-statuses view --- lisp/mastodon-tl.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5133cad..7fe1c02 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1372,12 +1372,15 @@ this just means displaying toot client." "Display each toot in TOOTS. This function removes replies if user required." (mapc 'mastodon-tl--toot - (if (or ; we were called via --more*: - (mastodon-tl--get-buffer-property 'hide-replies nil :no-error) - ;; loading a tl with a prefix arg: - (mastodon-tl--hide-replies-p current-prefix-arg)) - (cl-remove-if-not #'mastodon-tl--is-reply toots) - toots)) + ;; hack to *not* filter replies on profiles: + (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) + toots + (if (or ; we were called via --more*: + (mastodon-tl--get-buffer-property 'hide-replies nil :no-error) + ;; loading a tl with a prefix arg: + (mastodon-tl--hide-replies-p current-prefix-arg)) + (cl-remove-if-not #'mastodon-tl--is-reply toots) + toots))) (goto-char (point-min))) (defun mastodon-tl--get-update-function (&optional buffer) -- cgit v1.2.3 From 883a13c272092d66389df0da635869056bfb88e4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 28 Jan 2023 09:51:26 +0100 Subject: add account of toot at point to any list. FIXES #380 --- lisp/mastodon-tl.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7fe1c02..9864819 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1938,9 +1938,12 @@ a: add account to this list, r: remove account from this list" If ID is provided, use that list. If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (interactive) - (let* ((list-name (if id + (let* ((list-prompt (if handle + (format "Add %s to list: " handle) + "Add account to list: ")) + (list-name (if id (get-text-property (point) 'list-name) - (completing-read "Add account to list: " + (completing-read list-prompt (mastodon-tl--get-lists-names) nil t))) (list-id (or id (mastodon-tl--get-list-id list-name))) (followings (mastodon-tl--get-users-followings)) @@ -1958,6 +1961,15 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." response (message "%s added to list %s!" account list-name)))) +(defun mastodon-tl--add-toot-account-at-point-to-list () + "Prompt for a list, and add the account of the toot at point to it." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (account (mastodon-tl--field 'account toot)) + (account-id (mastodon-tl--field 'id account)) + (handle (mastodon-tl--field 'acct account))) + (mastodon-tl--add-account-to-list nil account-id handle))) + (defun mastodon-tl--remove-account-from-list-at-point () "Prompt for account and remove from list at point." (interactive) -- cgit v1.2.3 From 72dd0524bf5de090af3f1b1b28cd8a9be44a335e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 28 Jan 2023 09:59:57 +0100 Subject: view whole thread cmd. FIXES #378. --- lisp/mastodon-tl.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9864819..04c109f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1630,6 +1630,18 @@ ID is that of the toot to view." (let ((inhibit-read-only t)) (mastodon-tl--toot toot :detailed-p)))))) +(defun mastodon-tl--view-whole-thread () + "From a thread view, view entire thread. +If you load a thread from a toot, only the branches containing +are displayed by default. Call this if you subsequently want to +view all branches of a thread." + (interactive) + (if (not (eq (mastodon-tl--get-buffer-type) 'thread)) + (error "You need to be viewing a thread to call this.") + (goto-char (point-min)) + (let ((id (mastodon-tl--property 'base-toot-id))) + (mastodon-tl--thread id)))) + (defun mastodon-tl--thread (&optional id) "Open thread buffer for toot at point or with ID." ;; NB: this is called by `mastodon-url-lookup', which means it must work -- cgit v1.2.3 From 9992f16c77f596e5596c3bc437f118aa5c6a11e3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 28 Jan 2023 12:13:54 +0100 Subject: hide-replies doctsring - document prefix arg --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 04c109f..867318b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -163,7 +163,9 @@ Must be an integer between 20 and 40 inclusive." :type '(string)) (defcustom mastodon-tl--hide-replies nil - "Whether to hide replies from the timelines." + "Whether to hide replies from the timelines. +Note that you can hide replies on a one-off basis by loading a +timeline with a simple prefix argument, `C-u'." :group 'mastodon-tl :type '(boolean :tag "Whether to hide replies from the timelines.")) -- cgit v1.2.3 From 3f98af1a063da1aa863530b266a69fc1361a7b88 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 28 Jan 2023 13:43:08 +0100 Subject: docstrings/flychecks --- lisp/mastodon-profile.el | 2 +- lisp/mastodon-tl.el | 14 +++++++++----- lisp/mastodon-toot.el | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index ac9feba..b15b4bb 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -363,7 +363,7 @@ Ask for confirmation if length > 500 characters." (mastodon-profile--user-profile-send-updated-do url note)))) (defun mastodon-profile--user-profile-send-updated-do (url note) - "Send PATCH request with the updated profile note." + "Send PATCH request with the updated profile NOTE to URL." (let ((response (mastodon-http--patch url `(("note" . ,note))))) (mastodon-http--triage response (lambda () (message "Profile note updated!"))))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 867318b..3c6c702 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1392,12 +1392,14 @@ Optionally get it for BUFFER." (defun mastodon-tl--get-endpoint (&optional buffer no-error) "Get the ENDPOINT stored in `mastodon-tl--buffer-spec'. -Optionally set it for BUFFER." +Optionally set it for BUFFER. +NO-ERROR means to fail silently." (mastodon-tl--get-buffer-property 'endpoint buffer no-error)) (defun mastodon-tl--buffer-name (&optional buffer no-error) "Get the BUFFER-NAME stored in `mastodon-tl--buffer-spec'. -Optionally get it for BUFFER." +Optionally get it for BUFFER. +NO-ERROR means to fail silently." (mastodon-tl--get-buffer-property 'buffer-name buffer no-error)) (defun mastodon-tl--link-header (&optional buffer) @@ -1427,7 +1429,8 @@ If NO-ERROR is non-nil, do not error when property is empty." BUFFER is buffer name, ENDPOINT is buffer's enpoint, UPDATE-FUNCTION is its update function. LINK-HEADER is the http Link header if present. -UPDATE-PARAMS is any http parameters needed for the update function." +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." (setq mastodon-tl--buffer-spec `(account ,(cons mastodon-active-user mastodon-instance-url) @@ -1639,7 +1642,7 @@ are displayed by default. Call this if you subsequently want to view all branches of a thread." (interactive) (if (not (eq (mastodon-tl--get-buffer-type) 'thread)) - (error "You need to be viewing a thread to call this.") + (error "You need to be viewing a thread to call this") (goto-char (point-min)) (let ((id (mastodon-tl--property 'base-toot-id))) (mastodon-tl--thread id)))) @@ -3001,7 +3004,8 @@ This location is defined by a non-nil value of UPDATE-FUNCTION is used to recieve more toots. HEADERS means to also collect the response headers. Used for paginating favourites and bookmarks. -PARAMS is any parameters to send with the request." +PARAMS is any parameters to send with the request. +HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer." (let ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*"))) (if headers diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index e233fba..35fe457 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -359,7 +359,7 @@ TYPE is a symbol, either 'favourite or 'boost." (error "You can't %s favourites" action-string)) ((and (equal "private" visibility) (equal type 'boost)) - (error "You can't boost private toots.")) + (error "You can't boost private toots")) (t (mastodon-toot--action action @@ -1586,7 +1586,8 @@ If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the `mastodon-toot--reply-to-id' var. REPLY-JSON is the full JSON of the toot being replied to. INITIAL-TEXT is used by `mastodon-toot-insert-draft-toot' to add -a draft into the buffer." +a draft into the buffer. +EDIT means we are editing an existing toot, not composing a new one." (let* ((buffer-name (if edit "*edit toot*" "*new toot*")) (buffer-exists (get-buffer buffer-name)) (buffer (or buffer-exists (get-buffer-create buffer-name))) -- cgit v1.2.3 From 696ee69f9877f92abd5221d2314e45f1ea953d8e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 13 Feb 2023 15:57:33 +0100 Subject: tl--list-followed-tags: view tag timeline of chosen tag --- lisp/mastodon-tl.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3c6c702..57d827b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -430,12 +430,13 @@ Used on initializing a timeline or thread." ("limit" . ,mastodon-tl--timeline-posts-count)) (when current-prefix-arg t))) -(defun mastodon-tl--get-tag-timeline () - "Prompt for tag and opens its timeline." +(defun mastodon-tl--get-tag-timeline (&optional tag) + "Prompt for tag and opens its timeline. +Optionally load TAG timeline directly." (interactive) (let* ((word (or (word-at-point) "")) - (input (read-string (format "Load timeline for tag (%s): " word))) - (tag (if (string-empty-p input) word input))) + (input (or tag (read-string (format "Load timeline for tag (%s): " word)))) + (tag (or tag (if (string-empty-p input) word input)))) (message "Loading timeline for #%s..." tag) (mastodon-tl--show-tag-timeline tag))) @@ -2696,7 +2697,7 @@ If TAG provided, follow it." (defun mastodon-tl--unfollow-tag (&optional tag) "Prompt for a followed tag, and unfollow it. -If TAG if provided, unfollow it." +If TAG is provided, unfollow it." (interactive) (let* ((followed-tags-json (unless tag (mastodon-tl--followed-tags))) (tags (unless tag (mapcar (lambda (x) @@ -2711,15 +2712,14 @@ If TAG if provided, unfollow it." (message "tag #%s unfollowed!" tag))))) (defun mastodon-tl--list-followed-tags () - "List tags followed. If user choses one, display its JSON." + "List followed tags. View timeline of tag user choses." (interactive) (let* ((followed-tags-json (mastodon-tl--followed-tags)) (tags (mapcar (lambda (x) (alist-get 'name x)) followed-tags-json)) (tag (completing-read "Tag: " tags))) - (message (prin1-to-string - (mastodon-tl--get-tag-json tag))))) + (mastodon-tl--get-tag-timeline tag))) ;; TODO: add this to new posts in some cases, e.g. in thread view. (defun mastodon-tl--reload-timeline-or-profile () -- cgit v1.2.3 From 990bd88c56105f6524150fb04552148539688f14 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 18:58:24 +0100 Subject: tl--buffer-type-eq/profile-buffer-p for all buffer checks, hopefully --- lisp/mastodon-tl.el | 76 +++++++++++++++++++++++++++------------------------ lisp/mastodon-toot.el | 7 ++--- 2 files changed, 44 insertions(+), 39 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 57d827b..c3d2672 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1474,8 +1474,12 @@ Should work in all mastodon buffers." ((string-prefix-p "statuses" endpoint-fun) 'single-status) ;; profiles: - ((string-prefix-p "accounts" endpoint-fun) + ((mastodon-tl--profile-buffer-p) (cond + ;; own profile: + ((equal (mastodon-tl--buffer-name) + (concat "*mastodon-" (mastodon-auth--get-account-name) "-statuses*")) + 'own-profile) ;; profile note: ((string-suffix-p "update-profile*" buffer-name-fun) 'update-profile-note) @@ -1488,6 +1492,8 @@ Should work in all mastodon buffers." ;; profile following ((string-suffix-p "following" endpoint-fun) 'profile-following))) + ((string= "preferences" endpoint-fun) + 'preferences) ;; search ((string-suffix-p "search" endpoint-fun) 'search) @@ -1497,7 +1503,7 @@ Should work in all mastodon buffers." ((string= "filters" endpoint-fun) 'filters) ((string= "lists" endpoint-fun) - 'lists-view) + 'lists) ((string= "suggestions" endpoint-fun) 'follow-suggestions) ((string= "favourites" endpoint-fun) @@ -1514,11 +1520,20 @@ Should work in all mastodon buffers." ((string= "*mastodon-toot-edits*" buffer-name-fun) 'toot-edits)))) +(defun mastodon-tl--buffer-type-eq (type) + "Return t if current buffer type is equal to symbol TYPE." + (eq (mastodon-tl--get-buffer-type) type)) + +(defun mastodon-tl--profile-buffer-p () + "Return t if current buffer is a profile buffer of any kind. +This includes the update profile note buffer, but not the preferences one." + (string-prefix-p "accounts" (mastodon-tl--get-endpoint nil :no-error))) + (defun mastodon-tl--has-toots-p () "Return non-nil if the current buffer contains toots. Return value is that of `member'. This is used to avoid running into trouble using functions that -presume we are in a timline of toots or similar elements, such as +presume we are in a timeline of toots or similar elements, such as `mastodon-tl--property'." (let ((toot-buffers '(home federated local tag-timeline notifications @@ -1819,8 +1834,7 @@ If ID is provided, use that list." (let* ((json (mastodon-http--process-json)) (name-new (alist-get 'title json))) (message "list %s edited to %s!" name-old name-new))) - (when (equal (buffer-name (current-buffer)) - "*mastodon-lists*") + (when (mastodon-tl--buffer-type-eq 'lists) (mastodon-tl--view-lists)))))) (defun mastodon-tl--view-timeline-list-at-point () @@ -2022,8 +2036,7 @@ If ID is provided, use that list." "Call `mastodon-http--triage' on RESPONSE and display MESSAGE." (mastodon-http--triage response (lambda () - (when (equal (buffer-name (current-buffer)) - "*mastodon-lists*") + (when (mastodon-tl--buffer-type-eq 'lists) (mastodon-tl--view-lists)) message))) @@ -2169,8 +2182,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (lambda () (message "Filter created for %s!" word) ;; reload if we are in filters view: - (when (string= (mastodon-tl--get-endpoint) - "filters") + (when (mastodon-tl--buffer-type-eq 'filters) (mastodon-tl--view-filters)))))) (defun mastodon-tl--view-filters () @@ -2257,7 +2269,7 @@ RESPONSE is the JSON returned by the server." (defmacro mastodon-tl--do-if-toot (&rest body) "Execute BODY if we have a toot or user at point." (declare (debug t)) - `(if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + `(if (and (not (mastodon-tl--profile-buffer-p)) (not (mastodon-tl--property 'toot-json))) (message "Looks like there's no toot or user at point?") ,@body)) @@ -2568,19 +2580,19 @@ LANGS is the accumulated array param alist if we re-run recursively." "Get the list of user-handles for ACTION from the current toot." (mastodon-tl--do-if-toot (let ((user-handles - (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") + (cond ((or (mastodon-tl--buffer-type-eq 'follow-suggestions) ;; follow suggests / search / foll requests compat: - (string-prefix-p "*mastodon-search" (buffer-name)) - (equal (buffer-name) "*mastodon-follow-requests*") + (mastodon-tl--buffer-type-eq 'search) + (mastodon-tl--buffer-type-eq 'follow-requests) ;; profile view follows/followers compat: ;; but not for profile statuses: ;; fetch 'toot-json: - (and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) - (not (string-suffix-p "statuses" (mastodon-tl--get-endpoint))))) + (mastodon-tl--buffer-type-eq 'profile-followers) + (mastodon-tl--buffer-type-eq 'profile-following)) (list (alist-get 'acct (get-text-property (point) 'toot-json)))) ;; profile view, no toots, point on profile note, ie. 'profile-json: ;; needed for e.g. gup.pe groups which show no toots publically: - ((and (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + ((and (mastodon-tl--profile-buffer-p) (get-text-property (point) 'profile-json)) (list (alist-get 'acct (get-text-property (point) 'profile-json)))) ;; avoid tl--property here because it calls next-toot @@ -2626,7 +2638,7 @@ LANGS is an array parameters alist of languages to filer user's posts by." (mastodon-profile--search-account-by-handle user-handle) ;; if profile view, use 'profile-json as status: - (if (string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (if (mastodon-tl--profile-buffer-p) (mastodon-profile--lookup-account-in-status user-handle (get-text-property (point) 'profile-json)) ;; if muting/blocking, we select from handles in current status @@ -2725,16 +2737,15 @@ If TAG is provided, unfollow it." (defun mastodon-tl--reload-timeline-or-profile () "Reload the current timeline or profile page. For use after e.g. deleting a toot." - (cond ((equal (mastodon-tl--get-endpoint) "timelines/home") + (cond ((mastodon-tl--buffer-type-eq 'home) (mastodon-tl--get-home-timeline)) - ((equal (mastodon-tl--get-endpoint) "timelines/public") + ((mastodon-tl--buffer-type-eq 'federated) (mastodon-tl--get-federated-timeline)) - ((equal (mastodon-tl--buffer-name) "*mastodon-local*") + ((mastodon-tl--buffer-type-eq 'local) (mastodon-tl--get-local-timeline)) - ((equal (mastodon-tl--get-endpoint) "notifications") + ((mastodon-tl--buffer-type-eq 'notifications) (mastodon-notifications-get)) - ((equal (mastodon-tl--buffer-name) - (concat "*mastodon-" (mastodon-auth--get-account-name) "-statuses*")) + ((mastodon-tl--buffer-type-eq 'own-profile) (mastodon-profile--my-profile)) ((save-match-data (string-match @@ -2754,12 +2765,10 @@ For use after e.g. deleting a toot." "Return t if we are in a view needing Link header pagination. Currently this includes favourites, bookmarks, and profile pages when showing followers or accounts followed." - (let ((buf (buffer-name (current-buffer))) - (endpoint (mastodon-tl--get-endpoint))) - (or (member buf '("*mastodon-favourites*" "*mastodon-bookmarks*")) - (and (string-prefix-p "accounts" endpoint) - (or (string-suffix-p "followers" endpoint) - (string-suffix-p "following" endpoint)))))) + (or (mastodon-tl--buffer-type-eq 'favourites) + (mastodon-tl--buffer-type-eq 'bookmarks) + (mastodon-tl--buffer-type-eq 'profile-followers) + (mastodon-tl--buffer-type-eq 'profile-following))) (defun mastodon-tl--more () "Append older toots to timeline, asynchronously." @@ -2977,7 +2986,7 @@ This location is defined by a non-nil value of (update-function (mastodon-tl--get-update-function)) (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)) + (if (mastodon-tl--buffer-type-eq 'thread) (funcall update-function thread-id) ;; update other timelines: (let* ((id (mastodon-tl--newest-id)) @@ -3063,8 +3072,7 @@ JSON and http headers, without it just the JSON." #'mastodon-tl--update-timestamps-callback (current-buffer) nil))) - (unless (string-prefix-p "accounts" endpoint) - ;; for everything save profiles + (unless (mastodon-tl--profile-buffer-p) (mastodon-tl--goto-first-item))))))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type) @@ -3106,9 +3114,7 @@ Optional arg NOTE-TYPE means only get that type of note." #'mastodon-tl--update-timestamps-callback (current-buffer) nil))) - (when ;(and (not (equal json '[])) - ;; for everything save profiles: - (not (string-prefix-p "accounts" endpoint)) + (unless (mastodon-tl--profile-buffer-p) (mastodon-tl--goto-first-item))) buffer)) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 7b9163a..250aefd 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -77,7 +77,6 @@ (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-profile--fetch-server-account-settings-maybe "mastodon-profile") (autoload 'mastodon-http--build-array-params-alist "mastodon-http") -(autoload 'mastodon-tl--get-endpoint "mastodon-tl") (autoload 'mastodon-http--put "mastodon-http") (autoload 'mastodon-tl--symbol "mastodon-tl") (autoload 'mastodon-tl--view-scheduled-toots "mastodon-tl") @@ -356,10 +355,10 @@ TYPE is a symbol, either 'favourite or 'boost." ;; & nothing wrong with faving/boosting own toots from notifs: ;; this boosts/faves the base toot, not the notif status ((and (equal "reblog" toot-type) - (not (string= (mastodon-tl--get-endpoint) "notifications"))) + (not (mastodon-tl--buffer-type-eq 'notifications))) (error "You can't %s boosts" action-string)) ((and (equal "favourite" toot-type) - (not (string= (mastodon-tl--get-endpoint) "notifications"))) + (not (mastodon-tl--buffer-type-eq 'notifications))) (error "You can't %s favourites" action-string)) ((and (equal "private" visibility) (equal type 'boost)) @@ -1581,7 +1580,7 @@ Added to `after-change-functions'." (defun mastodon-toot--compose-buffer-p () "Return t if compose buffer is current." - (equal (buffer-name (current-buffer)) "*new 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 b3692e0b9fac794208550b13ec5ea02ab0bd2907 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 20:33:31 +0100 Subject: docstring --- lisp/mastodon-tl.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index c3d2672..4ccfd20 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1444,7 +1444,10 @@ HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer." (defun mastodon-tl--get-buffer-type () "Return a symbol descriptive of current mastodon buffer type. -Should work in all mastodon buffers." +Should work in all mastodon buffers. +Note that for many buffers, this requires `mastodon-tl--buffer-spec' +to be set. It is set for almost all buffers, but you still have to +call this function after it is set or use something else." (let ((endpoint-fun (mastodon-tl--get-endpoint nil :no-error)) (buffer-name-fun (mastodon-tl--buffer-name nil :no-error))) (cond (mastodon-toot-mode -- cgit v1.2.3 From 3823bfa94c43d9d26190e5c25ebb159933b7cc2b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:03:07 +0100 Subject: get-link-header: test for "link" header specifically this prevents breakage if a profile's follwers/following is hidden. --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 57d827b..87bac66 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2994,8 +2994,8 @@ This location is defined by a non-nil value of (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." - (when headers - ;; pleroma uses "link", so case-insensitive match required: + ;; pleroma uses "link", so case-insensitive match required: + (when (alist-get "Link" headers nil nil 'cl-equalp) (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) (defun mastodon-tl--init (buffer-name endpoint update-function -- cgit v1.2.3 From 03eb2c807c7a07718b2c811038477eff014032b7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:07:17 +0100 Subject: handle no "next" link header, roughly --- lisp/mastodon-tl.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 87bac66..4323c66 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2767,16 +2767,21 @@ when showing followers or accounts followed." (message "Loading older toots...") (if (mastodon-tl--use-link-header-p) ;; link-header: can't build a URL with --more-json-async, endpoint/id: - (let* ((next (car (mastodon-tl--link-header))) - ;;(prev (cadr (mastodon-tl--link-header))) - (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--update-params) - 'mastodon-tl--more* (current-buffer) (point)))) + ;; ensure we have a "next" type here, otherwise the CAR will be the + ;; "prev type!" + (let (link-header (mastodon-tl--link-header)) + (if (> 2 (length link-header)) + (error "No next page") + (let* ((next (car link-header)) + ;;(prev (cadr (mastodon-tl--link-header))) + (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--update-params) + 'mastodon-tl--more* (current-buffer) (point)))))) (defun mastodon-tl--more* (response buffer point-before &optional headers) "Append older toots to timeline, asynchronously. -- cgit v1.2.3 From 09d6011da215fced6b8f49f8cf12ee9226b58d8d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:35:27 +0100 Subject: refactor tl--get-link-header --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4323c66..257a6f2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3000,8 +3000,8 @@ This location is defined by a non-nil value of (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." ;; pleroma uses "link", so case-insensitive match required: - (when (alist-get "Link" headers nil nil 'cl-equalp) - (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) + (when-let ((link-headers (alist-get "Link" headers nil nil 'cl-equalp))) + (split-string link-headers ", "))) (defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params hide-replies) -- cgit v1.2.3 From c35f7d63bb06dd8f53a092a8b186361b327460e6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:07:17 +0100 Subject: handle no "next" link header, roughly comment typo --- lisp/mastodon-tl.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 87bac66..817c85d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2767,16 +2767,21 @@ when showing followers or accounts followed." (message "Loading older toots...") (if (mastodon-tl--use-link-header-p) ;; link-header: can't build a URL with --more-json-async, endpoint/id: - (let* ((next (car (mastodon-tl--link-header))) - ;;(prev (cadr (mastodon-tl--link-header))) - (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--update-params) - 'mastodon-tl--more* (current-buffer) (point)))) + ;; ensure we have a "next" type here, otherwise the CAR will be the + ;; "prev" type! + (let (link-header (mastodon-tl--link-header)) + (if (> 2 (length link-header)) + (error "No next page") + (let* ((next (car link-header)) + ;;(prev (cadr (mastodon-tl--link-header))) + (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--update-params) + 'mastodon-tl--more* (current-buffer) (point)))))) (defun mastodon-tl--more* (response buffer point-before &optional headers) "Append older toots to timeline, asynchronously. -- cgit v1.2.3 From 8c2ed534a61b036b580a5932dc4e83979a6bcdba Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:35:27 +0100 Subject: refactor tl--get-link-header --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 817c85d..2f27a94 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3000,8 +3000,8 @@ This location is defined by a non-nil value of (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." ;; pleroma uses "link", so case-insensitive match required: - (when (alist-get "Link" headers nil nil 'cl-equalp) - (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) + (when-let ((link-headers (alist-get "Link" headers nil nil 'cl-equalp))) + (split-string link-headers ", "))) (defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params hide-replies) -- cgit v1.2.3 From 45e00b20b120784ad1c857a4fb71f994d17ef6c7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:07:17 +0100 Subject: handle no "next" link header, roughly comment typo fix --more re link-header --- lisp/mastodon-tl.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 87bac66..170cec1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2767,16 +2767,21 @@ when showing followers or accounts followed." (message "Loading older toots...") (if (mastodon-tl--use-link-header-p) ;; link-header: can't build a URL with --more-json-async, endpoint/id: - (let* ((next (car (mastodon-tl--link-header))) - ;;(prev (cadr (mastodon-tl--link-header))) - (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--update-params) - 'mastodon-tl--more* (current-buffer) (point)))) + ;; ensure we have a "next" type here, otherwise the CAR will be the + ;; "prev" type! + (let ((link-header (mastodon-tl--link-header))) + (if (> 2 (length link-header)) + (error "No next page") + (let* ((next (car link-header)) + ;;(prev (cadr (mastodon-tl--link-header))) + (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--update-params) + 'mastodon-tl--more* (current-buffer) (point)))))) (defun mastodon-tl--more* (response buffer point-before &optional headers) "Append older toots to timeline, asynchronously. -- cgit v1.2.3 From a75f120f0c2f61a6f0e1b9318f9a18134b831de2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 18 Feb 2023 22:35:27 +0100 Subject: refactor tl--get-link-header --- lisp/mastodon-tl.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 170cec1..2225757 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3000,8 +3000,8 @@ This location is defined by a non-nil value of (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." ;; pleroma uses "link", so case-insensitive match required: - (when (alist-get "Link" headers nil nil 'cl-equalp) - (split-string (alist-get "Link" headers nil nil 'cl-equalp) ", "))) + (when-let ((link-headers (alist-get "Link" headers nil nil 'cl-equalp))) + (split-string link-headers ", "))) (defun mastodon-tl--init (buffer-name endpoint update-function &optional headers params hide-replies) -- cgit v1.2.3 From a47d4be15d93b99c0dd621a9b3a916be14a4cc39 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 19 Feb 2023 21:44:50 +0100 Subject: more cases to use buffer-type-eq --- lisp/mastodon-profile.el | 19 +++++++++---------- lisp/mastodon-tl.el | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b15b4bb..b0b3e0e 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -169,15 +169,14 @@ NO-REBLOGS means do not display boosts in statuses." (defun mastodon-profile--account-view-cycle () "Cycle through profile view: toots, followers, and following." (interactive) - (let ((endpoint (plist-get mastodon-tl--buffer-spec 'endpoint))) - (cond ((string-suffix-p "statuses" endpoint) - (mastodon-profile--open-followers)) - ((string-suffix-p "followers" endpoint) - (mastodon-profile--open-following)) - ((string-suffix-p "following" endpoint) - (mastodon-profile--open-statuses-no-reblogs)) - (t - (mastodon-profile--make-author-buffer mastodon-profile--account))))) + (cond ((mastodon-tl--buffer-type-eq 'profile-statuses) + (mastodon-profile--open-followers)) + ((mastodon-tl--buffer-type-eq 'profile-followers) + (mastodon-profile--open-following)) + ((mastodon-tl--buffer-type-eq 'profile-following) + (mastodon-profile--open-statuses-no-reblogs)) + (t + (mastodon-profile--make-author-buffer mastodon-profile--account)))) (defun mastodon-profile--open-statuses-no-reblogs () "Open a profile buffer showing statuses without reblogs." @@ -761,7 +760,7 @@ IMG_TYPE is the JSON key from the account data." "Query for USER-HANDLE from current status and show that user's profile." (interactive (list - (if (and (not (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) ;profile view + (if (and (not (mastodon-tl--profile-buffer-p)) (not (get-text-property (point) 'toot-json))) (message "Looks like there's no toot or user at point?") (let ((user-handles (mastodon-profile--extract-users-handles diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 96b8311..2a20e73 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1733,7 +1733,7 @@ Note that you can only (un)mute threads you have posted in." "Mute a thread. If UNMUTE, unmute it." (let ((endpoint (mastodon-tl--get-endpoint))) - (if (string-suffix-p "context" endpoint) ; thread view + (if (mastodon-tl--buffer-type-eq 'thread) (let* ((id (save-match-data (string-match "statuses/\\(?2:[[:digit:]]+\\)/context" -- cgit v1.2.3 From 4f9a7be4926dbf3f33a717fcbed12de78c22b331 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 19 Feb 2023 21:53:48 +0100 Subject: autoloads, flychecks --- lisp/mastodon-profile.el | 4 ++++ lisp/mastodon-tl.el | 1 + lisp/mastodon-toot.el | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index b0b3e0e..aa4a12e 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -78,6 +78,9 @@ (autoload 'mastodon-tl--set-buffer-spec "mastodon-tl") (autoload 'mastodon-tl--symbol "mastodon-tl") (autoload 'mastodon-auth--get-account-id "mastodon-auth") +(autoload 'mastodon-tl--profile-buffer-p "mastodon tl") +(autoload 'mastodon-tl--buffer-type-eq "mastodon tl") +(autoload 'mastodon-toot--count-toot-chars "mastodon-toot") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -86,6 +89,7 @@ (defvar mastodon-toot--max-toot-chars) (defvar mastodon-toot--visibility) (defvar mastodon-toot--content-nsfw) +(defvar mastodon-tl--timeline-posts-count) (defvar-local mastodon-profile--account nil "The data for the account being described in the current profile buffer.") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2a20e73..ba6b1df 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -87,6 +87,7 @@ (autoload 'mastodon-toot--iso-to-human "mastodon-toot") (defvar mastodon-toot--visibility) +(defvar mastodon-toot-mode) (defvar mastodon-active-user) (when (require 'mpv nil :no-error) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 250aefd..64cdca1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -41,7 +41,6 @@ (require 'cl-lib) (require 'persist) - (require 'mastodon-iso) (defvar mastodon-instance-url) @@ -83,6 +82,9 @@ (autoload 'mastodon-tl--cancel-scheduled-toot "mastodon-toot") (autoload 'org-read-date "org") (autoload 'iso8601-parse "iso8601") +(autoload 'mastodon-tl--buffer-type-eq "mastodon-tl") +(autoload 'mastodon-profile--show-user "mastodon-profile") +(autoload 'mastodon-tl--set-buffer-spec "mastodon-tl") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -310,7 +312,7 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." ;; if point is inside the byline, back up first so ;; we don't move to the following toot: (beginning-of-line) - (previous-line) + (forward-line -1) (mastodon-tl--goto-next-toot))))) (defun mastodon-toot--action (action callback) -- cgit v1.2.3