emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/mastodon a472f873a3 09/18: add widget to notifs view.


From: ELPA Syncer
Subject: [nongnu] elpa/mastodon a472f873a3 09/18: add widget to notifs view.
Date: Mon, 2 Dec 2024 16:00:34 -0500 (EST)

branch: elpa/mastodon
commit a472f873a3ed499146f66eb54adf85ca73068b17
Author: marty hiatt <martianhiatus@disroot.org>
Commit: marty hiatt <martianhiatus@disroot.org>

    add widget to notifs view.
---
 lisp/mastodon-notifications.el | 27 +++++++++++++++++++--------
 lisp/mastodon-tl.el            |  5 +++--
 lisp/mastodon-widget.el        | 10 ++++++----
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 93a3d66204..c302db0e22 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -75,11 +75,12 @@
 (defvar mastodon-profile-note-in-foll-reqs-max-length)
 (defvar mastodon-group-notifications)
 (defvar mastodon-notifications-grouped-names-count)
+
 (defvar mastodon-notifications--types
-  '("favourite" "reblog" "mention" "poll"
-    "follow_request" "follow" "status" "update"
-    "severed_relationships" "moderation_warning")
-  "A list of notification types according to their name on the server.")
+  '("all" "favourite" "reblog" "mention" "poll"
+    "follow_request" "follow" "status" "update")
+  ;; "severed_relationships" "moderation_warning")
+  "A list of notification types according to their name on the server, plus 
\"all\".")
 
 (defvar mastodon-notifications--filter-types-alist
   '(("all"                    . mastodon-notifications--get)
@@ -489,18 +490,28 @@ NO-GROUP means don't render grouped notifications."
          ;; `mastodon-tl--media-attachment', not here
          (mastodon-media--inline-images start-pos (point)))))))
 
-(defun mastodon-notifications--timeline (json)
+(defun mastodon-notifications--timeline (json &optional type)
   "Format JSON in Emacs buffer."
   (if (seq-empty-p json)
       (user-error "Looks like you have no (more) notifications for now")
+    (mastodon-widget--create
+     "Filter" mastodon-notifications--types
+     (or type "all")
+     (lambda (widget &rest _ignore)
+       (let ((value (widget-value widget)))
+         (mastodon-notifications--get-type value)))
+     :newline)
+    (insert "\n")
     (mastodon-notifications--render json (not mastodon-group-notifications))
     (goto-char (point-min))))
 
-(defun mastodon-notifications--get-type ()
+(defun mastodon-notifications--get-type (&optional type)
   "Read a notification type and load its timeline."
   (interactive)
-  (let ((choice (completing-read "View notifications: "
-                                 mastodon-notifications--filter-types-alist)))
+  (let ((choice (or type
+                    (completing-read
+                     "View notifications: "
+                     mastodon-notifications--filter-types-alist))))
     (funcall (alist-get
               choice mastodon-notifications--filter-types-alist
               nil nil #'equal))))
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 9f6ae5b828..9718684145 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -3399,10 +3399,10 @@ ENDPOINT-VERSION is a string, format Vx, e.g. V2."
        link-header params nil
        ;; awful hack to fix multiple reloads:
        (alist-get "max_id" params nil nil #'string=))
-      (mastodon-tl--do-init json update-function)
+      (mastodon-tl--do-init json update-function nil nil note-type)
       buffer)))
 
-(defun mastodon-tl--do-init (json update-fun &optional domain no-byline)
+(defun mastodon-tl--do-init (json update-fun &optional domain no-byline type)
   "Utility function for `mastodon-tl--init*' and `mastodon-tl--init-sync'.
 JSON is the data to call UPDATE-FUN on.
 When DOMAIN, force inclusion of user's domain in their handle.
@@ -3410,6 +3410,7 @@ NO-BYLINE means just insert toot body, used for 
announcements."
   (remove-overlays) ; video overlays
   (cond (domain ;; maybe our update-fun doesn't always have 3 args...:
          (funcall update-fun json nil domain))
+        (type (funcall update-fun json type)) ;; notif types
         (no-byline (funcall update-fun json nil nil no-byline))
         (t (funcall update-fun json)))
   (setq
diff --git a/lisp/mastodon-widget.el b/lisp/mastodon-widget.el
index a5766722cb..e9376d8a2e 100644
--- a/lisp/mastodon-widget.el
+++ b/lisp/mastodon-widget.el
@@ -54,16 +54,18 @@ Note that such modes will need to require wid-edit.")
            collect `(choice-item :value ,x :format "%[%v%] "
                                  :keymap ,mastodon-widget-keymap)))
 
-(defun mastodon-widget--format (str &optional padding)
+(defun mastodon-widget--format (str &optional padding newline)
   "Return a widget format string for STR, its name.
 PADDING is an integer, for how much right-side padding to add."
   (concat "%[" (propertize str
                            'face 'mastodon-widget-face
                            'mastodon-tab-stop t)
           "%]: %v"
-          (make-string padding ? )))
+          (make-string padding ? )
+          (if newline "\n" "")))
 
-(defun mastodon-widget--create (kind type value notify-fun)
+(defun mastodon-widget--create (kind type value notify-fun
+                                     &optional newline)
   "Return a widget of KIND, with TYPE elements, and default VALUE.
 KIND is a string, either Listing, Sort, Items, or Inbox, and will
 be used for the widget's tag.
@@ -89,7 +91,7 @@ NOTIFY-FUN is the widget's notify function."
        :value value
        :args (mastodon-widget--return-item-widgets type-list)
        :help-echo (format "Select a %s kind" kind)
-       :format (mastodon-widget--format kind padding)
+       :format (mastodon-widget--format kind padding newline)
        :notify notify-fun
        ;; eg format of notify-fun:
        ;; (lambda (widget &rest ignore)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]