aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-10-14 10:39:26 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-10-14 10:39:26 +0200
commitdc6f827bcbf06e1f942318eeec4e58334beea3c0 (patch)
treedbfc87e8db2140c828cb27b664cdfdced6e693a0
parentf23ce015cf787b1b91d6fe57fad7940a641382ed (diff)
refactor search, handle no results
-rw-r--r--lisp/mastodon-search.el50
1 files changed, 32 insertions, 18 deletions
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index a2a47bc..41e4f23 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -186,30 +186,44 @@ is used for pagination."
(alist-get 'statuses response))))
(with-mastodon-buffer buffer #'mastodon-mode nil
(mastodon-search-mode)
- ;; user results:
(mastodon-search--format-heading (upcase type))
- (when (equal type "accounts")
- (mastodon-search--insert-users-propertized accts :note)
- (mastodon-tl--set-buffer-spec buffer "search"
- 'mastodon-views--insert-users-propertized-note
- nil params))
- ;; hashtag results:
- (when (equal type "hashtags")
- (mastodon-search--print-tags tags)
- (mastodon-tl--set-buffer-spec buffer "search"
- 'mastodon-search--print-tags
- nil params))
- ;; status results:
- (when (equal type "statuses")
- (mapc #'mastodon-tl--toot statuses)
- (mastodon-tl--set-buffer-spec buffer "search"
- 'mastodon-tl--timeline
- nil params))
+ ;; user results:
+ (cond ((equal type "accounts")
+ (mastodon-search--render-response accts type buffer params
+ 'mastodon-views--insert-users-propertized-note
+ 'mastodon-views--insert-users-propertized-note))
+ ((equal type "hashtags")
+ (mastodon-search--render-response tags type buffer params
+ 'mastodon-search--print-tags
+ 'mastodon-search--print-tags))
+ ((equal type "statuses")
+ (mastodon-search--render-response statuses type buffer params
+ #'mastodon-tl--timeline
+ #'mastodon-tl--timeline)))
(goto-char (point-min))
(message
(substitute-command-keys
"\\[mastodon-search--query-cycle] to cycle result types.")))))
+(defun mastodon-search-insert-no-results (&optional thing)
+ "Insert a no results message for object THING."
+ (let ((thing (or thing "nothing")))
+ (insert
+ (propertize (format "Looks like search returned no %s." thing)
+ 'face 'font-lock-comment-face))))
+
+(defun mastodon-search--render-response (data type buffer params
+ insert-fun update-fun)
+ "Call INSERT-FUN on DATA of result TYPE if non-nil.
+BUFFER, PARAMS, and UPDATE-FUN are for `mastodon-tl--buffer-spec'."
+ (if (not data)
+ (mastodon-search-insert-no-results type)
+ (funcall insert-fun data))
+ ;; (mapc #'mastodon-tl--toot data))
+ (mastodon-tl--set-buffer-spec buffer "search"
+ update-fun
+ nil params))
+
(defun mastodon-search--buf-type ()
"Return search buffer type, a member of `mastodon-search-types'."
;; called in `mastodon-tl--get-buffer-type'