aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-17 12:10:42 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-17 12:10:42 +0100
commit325644ad5a155d35e89fd9516b578993481807e5 (patch)
tree42efd7ad2d251c00bf12cea913e279f5e74658cc
parent5e71d81fe698badab960df2f6b46b89c4b6744d7 (diff)
parent0996c7eabfd89e6bb5fa3c9f2558c9d6ac23a44b (diff)
Merge branch 'mentions-view' into develop
-rw-r--r--lisp/mastodon-http.el5
-rw-r--r--lisp/mastodon-notifications.el38
-rw-r--r--lisp/mastodon-tl.el15
-rw-r--r--lisp/mastodon-toot.el16
-rw-r--r--lisp/mastodon.el1
5 files changed, 51 insertions, 24 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 66707b7..a127427 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -121,6 +121,11 @@ Unless UNAUTHENTICATED-P is non-nil."
args
"&"))
+(defun mastodon-http--build-array-args-alist (param-str array)
+ "Return parameters alist using PARAM-STR and ARRAY param values."
+ (cl-loop for x in array
+ collect (cons param-str x)))
+
(defun mastodon-http--post (url args headers &optional unauthenticated-p)
"POST synchronously to URL with ARGS and HEADERS.
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index f05e670..27b01c1 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -52,25 +52,26 @@
(autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl")
(defvar mastodon-tl--buffer-spec)
(defvar mastodon-tl--display-media-p)
+(defvar mastodon-mode-map)
(defvar mastodon-notifications--types-alist
- '(("mention" . mastodon-notifications--mention)
- ("follow" . mastodon-notifications--follow)
+ '(("follow" . mastodon-notifications--follow)
("favourite" . mastodon-notifications--favourite)
("reblog" . mastodon-notifications--reblog)
+ ("mention" . mastodon-notifications--mention)
+ ("poll" . mastodon-notifications--poll)
("follow_request" . mastodon-notifications--follow-request)
- ("status" . mastodon-notifications--status)
- ("poll" . mastodon-notifications--poll))
+ ("status" . mastodon-notifications--status))
"Alist of notification types and their corresponding function.")
(defvar mastodon-notifications--response-alist
- '(("Mentioned" . "you")
- ("Followed" . "you")
+ '(("Followed" . "you")
("Favourited" . "your status from")
("Boosted" . "your status from")
+ ("Mentioned" . "you")
+ ("Posted a poll" . "that has now ended")
("Requested to follow" . "you")
- ("Posted" . "a post")
- ("Posted a poll" . "that has now ended"))
+ ("Posted" . "a post"))
"Alist of subjects for notification types.")
(defvar mastodon-notifications--map
@@ -139,7 +140,7 @@ Can be called in notifications view or in follow-requests view."
"Reject a follow request.
Can be called in notifications view or in follow-requests view."
(interactive)
- (mastodon-notifications--follow-request-process t))
+ (mastodon-notifications--follow-request-process :reject))
(defun mastodon-notifications--mention (note)
"Format for a `mention' NOTE."
@@ -267,16 +268,29 @@ of the toot responded to."
(mapc #'mastodon-notifications--by-type json)
(goto-char (point-min))))
-(defun mastodon-notifications--get ()
- "Display NOTIFICATIONS in buffer."
+(defun mastodon-notifications--get (&optional type)
+ "Display NOTIFICATIONS in buffer.
+Optionally only print notifications of type TYPE, a string."
(interactive)
(message "Loading your notifications...")
(mastodon-tl--init-sync
"notifications"
"notifications"
- 'mastodon-notifications--timeline)
+ 'mastodon-notifications--timeline
+ type)
(use-local-map mastodon-notifications--map))
+(defun mastodon-notifications--get-mentions ()
+ "Display mention notifications in buffer."
+ (interactive)
+ (mastodon-notifications--get "mention"))
+
+(defun mastodon-notifications--filter-types-list (type)
+ "Return a list of notification types with TYPE (and \"status\") removed."
+ (let ((types (remove "status"
+ (mapcar #'car mastodon-notifications--types-alist))))
+ (remove type types)))
+
(defun mastodon-notifications--clear-all ()
"Clear all notifications."
(interactive)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index f0ef000..0db517c 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -70,6 +70,8 @@
(autoload 'mastodon-profile--get-preferences-pref "mastodon-profile")
(autoload 'mastodon-http--get-response-async "mastodon-http")
(autoload 'mastodon-url-lookup "mastodon")
+(autoload 'mastodon-http--build-array-args-alist "mastodon-http")
+
(when (require 'mpv nil :no-error)
(declare-function mpv-start "mpv"))
(defvar mastodon-instance-url)
@@ -2103,12 +2105,21 @@ headers."
;; for everything save profiles
(mastodon-tl--goto-first-item)))))
-(defun mastodon-tl--init-sync (buffer-name endpoint update-function)
+(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."
- (let* ((url (mastodon-http--api endpoint))
+ (let* ((exclude-types (when note-type
+ (mastodon-notifications--filter-types-list note-type)))
+ (args (when note-type (mastodon-http--build-array-args-alist
+ "exclude_types[]" exclude-types)))
+ (query-string (when note-type
+ (mastodon-http--build-query-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))
+ (url (mastodon-http--api endpoint))
(buffer (concat "*mastodon-" buffer-name "*"))
(json (mastodon-http--get-json url)))
(with-output-to-temp-buffer buffer
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 3c4c7aa..705eebc 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -79,6 +79,7 @@
(autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile")
(autoload 'mastodon-tl--render-text "mastodon-tl")
(autoload 'mastodon-profile-fetch-server-account-settings-maybe "mastodon-profile")
+(autoload 'mastodon-http--build-array-args-alist "mastodon-http")
;; for mastodon-toot--translate-toot-text
(autoload 'mastodon-tl--content "mastodon-tl")
@@ -615,7 +616,8 @@ to `emojify-user-emojis', and the emoji data is updated."
(defun mastodon-toot--build-poll-params ()
"Return an alist of parameters for POSTing a poll status."
(append
- (mastodon-toot--make-poll-options-params
+ (mastodon-http--build-array-args-alist
+ "poll[options][]"
(plist-get mastodon-toot-poll :options))
`(("poll[expires_in]" . ,(plist-get mastodon-toot-poll :expiry)))
`(("poll[multiple]" . ,(symbol-name (plist-get mastodon-toot-poll :multi))))
@@ -638,9 +640,9 @@ If media items have been attached and uploaded with
(symbol-name t)))
("spoiler_text" . ,spoiler)))
(args-media (when mastodon-toot--media-attachments
- (mapcar (lambda (id)
- (cons "media_ids[]" id))
- mastodon-toot--media-attachment-ids)))
+ (mastodon-http--build-array-args-alist
+ "media_ids[]"
+ mastodon-toot--media-attachment-ids)))
(args-poll (when mastodon-toot-poll
(mastodon-toot--build-poll-params)))
;; media || polls:
@@ -960,12 +962,6 @@ which is used to attach it to a toot when posting."
mastodon-toot--media-attachments))
(list "None")))
-(defun mastodon-toot--make-poll-options-params (options)
- "Return an parameter query alist from poll OPTIONS."
- (let ((key "poll[options][]"))
- (cl-loop for o in options
- collect `(,key . ,o))))
-
(defun mastodon-toot--fetch-max-poll-options ()
"Return the maximum number of poll options."
(mastodon-toot--fetch-poll-field 'max_options))
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 1aec556..707ce82 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -193,6 +193,7 @@ Use. e.g. \"%c\" for your locale's date and time format."
(define-key map (kbd "K") #'mastodon-profile--view-bookmarks)
(define-key map (kbd "I") #'mastodon-tl--view-filters)
(define-key map (kbd "G") #'mastodon-tl--get-follow-suggestions)
+ (define-key map (kbd "@") #'mastodon-notifications--get-mentions)
(when (require 'lingva nil :no-error)
(define-key map (kbd "s") #'mastodon-toot--translate-toot-text))
map)