From 3c30922d3c987ae628ad8e6853664c0cc3db2dfd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 15:02:53 +0200 Subject: implement trending tags --- lisp/mastodon-search.el | 57 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 10e12c3..1af49c1 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -45,6 +45,7 @@ (defvar mastodon-tl--link-keymap) (defvar mastodon-http--timeout) (defvar mastodon-toot--enable-completion-for-mentions) +(defvar mastodon-tl--buffer-spec) ;; functions for company completion of mentions in mastodon-toot @@ -76,6 +77,35 @@ QUERY is the string to search." (tags (alist-get 'hashtags response))) (mapcar #'mastodon-search--get-hashtag-info tags))) + +;; trending tags + +(defun mastodon-search-trending-tags () + "Display a list of tags trending on your instance." + (interactive) + (let* ((url (mastodon-http--api "trends")) + (response (mastodon-http--get-json url)) + (tags (mapcar #'mastodon-search--get-hashtag-info + response)) + (buffer (get-buffer-create "*mastodon-trending*"))) + (with-current-buffer buffer + (switch-to-buffer (current-buffer)) + (mastodon-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,(format "api/v1/trends") + update-function + (lambda (toot) (message "Trends.")))) + ;; hashtag results: + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " TRENDING HASHTAGS\n" + " ------------\n\n") + 'success)) + (mastodon-search--print-tags-list tags))))) + ;; functions for mastodon search (defun mastodon-search--search-query (query) @@ -121,16 +151,7 @@ QUERY is the string to search." " HASHTAGS\n" " ------------\n\n") 'success)) - (mapc (lambda (el) - (insert " : #" - (propertize (car el) - 'mouse-face 'highlight - 'mastodon-tag (car el) - 'mastodon-tab-stop 'hashtag - 'help-echo (concat "Browse tag #" (car el)) - 'keymap mastodon-tl--link-keymap) - " : \n\n")) - tags-list) + (mastodon-search--print-tags-list tags-list) ;; status results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -170,6 +191,22 @@ user's profile note. This is also called by 'toot-json acct)))) ; so named for compat w other processing functions json)) +(defun mastodon-search--print-tags-list (tags) + "Insert a propertized list of TAGS." + (mapc (lambda (el) + (insert + " : " + (propertize (concat "#" + (car el)) + 'face '(:box t) + 'mouse-face 'highlight + 'mastodon-tag (car el) + 'mastodon-tab-stop 'hashtag + 'help-echo (concat "Browse tag #" (car el)) + 'keymap mastodon-tl--link-keymap) + " : \n\n")) + tags)) + (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." (list (if (not (equal "" (alist-get 'display_name account))) -- cgit v1.2.3 From 36d7ff1a7f3484f19c876f56848443c96dbd04ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 15:04:42 +0200 Subject: readme --- README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.org b/README.org index a2b047a..ffd66e6 100644 --- a/README.org +++ b/README.org @@ -207,6 +207,8 @@ You can download and use your instance's custom emoji *** Other commands and account settings: - =mastodon-tl-view-instance-description=: View information about the instance that the author of the toot at point is on. +- =mastodon-tl-view-own-instance=: View information about your own instance. +- =mastodon-search-trending-tags=: View a list of trending hashtags on your instance. - =mastodon-profile-update-display-name=: Update the display name for your account. - =mastodon-profile-set-default-toot-visibility=: Set the default visibility for your toots. -- cgit v1.2.3 From 907a28bca6c1e281183f24dd1f5c618fdbb85065 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Sep 2022 15:10:47 +0200 Subject: add optional instance arg to -view-instance-description --- lisp/mastodon-tl.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b59be8b..8e3ab30 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1379,10 +1379,11 @@ BRIEF means show fewer details." (interactive) (mastodon-tl-view-instance-description nil :brief)) -(defun mastodon-tl-view-instance-description (&optional user brief) +(defun mastodon-tl-view-instance-description (&optional user brief instance) "View the details of the instance the current post's author is on. USER means to show the instance details for the logged in user. -BRIEF means to show fewer details." +BRIEF means to show fewer details. +INSTANCE is an instance domain name." (interactive) (mastodon-tl--do-if-toot (let* ((toot (mastodon-tl--property 'toot-json)) @@ -1393,8 +1394,9 @@ BRIEF means to show fewer details." (username (alist-get 'username account)) (instance (concat "https://" - (string-remove-prefix (concat username "@") - acct))) + (or instance + (string-remove-prefix (concat username "@") + acct)))) (response (mastodon-http--get-json (if user (mastodon-http--api "instance") -- cgit v1.2.3