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

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

[elpa] externals/ement 075dcbd114 1/3: Change: (ement-room-set-notificat


From: ELPA Syncer
Subject: [elpa] externals/ement 075dcbd114 1/3: Change: (ement-room-set-notification-state) Rename function, args
Date: Thu, 6 Oct 2022 20:57:35 -0400 (EDT)

branch: externals/ement
commit 075dcbd114787b8ef099d1f8fe5d1ca80d9c1df7
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Change: (ement-room-set-notification-state) Rename function, args
---
 README.org    |  2 +-
 ement-lib.el  | 33 ++++++++++++++++++---------------
 ement-room.el |  4 ++--
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/README.org b/README.org
index 4f60f5a71e..1bf9fc9285 100644
--- a/README.org
+++ b/README.org
@@ -291,7 +291,7 @@ Note that, while ~matrix-client~ remains usable, and 
probably will for some time
 
 *Additions*
 + Option ~ement-room-unread-only-counts-notifications~, now enabled by 
default, causes rooms' unread status to be determined only by their 
notification counts (which are set by the server and depend on rooms' 
notification settings).
-+ Command ~ement-room-set-notifications~ sets a room's notification rules 
(imitating Element's user-friendly presets).
++ Command ~ement-room-set-notification-state~ sets a room's notification state 
(imitating Element's user-friendly presets).
 
 *Changes*
 + When a room's read receipt is updated, the room's buffer is also marked as 
unmodified.  (In concert with the new option, this makes rooms' unread status 
more intuitive.)
diff --git a/ement-lib.el b/ement-lib.el
index 10474bc7af..0b0981bb41 100644
--- a/ement-lib.el
+++ b/ement-lib.el
@@ -427,9 +427,9 @@ If DELETE (interactively, with prefix), delete it."
 ;; slightly different.  This implementation will follow Element's initially, 
because the
 ;; spec is not simple, and imitating Element's requests will make it easier.
 
-(defun ement-room-set-notifications (rule room session)
-  "Set notification RULE for ROOM on SESSION.
-RULE may be nil to set the rules to default, `all',
+(defun ement-room-set-notification-state (state room session)
+  "Set notification STATE for ROOM on SESSION.
+STATE may be nil to set the rules to default, `all',
 `mentions-and-keywords', or `none'."
   ;; This merely attempts to reproduce the behavior of Element's simple 
notification
   ;; options.  It does not attempt to offer all of the features defined in the 
spec.  And,
@@ -444,25 +444,28 @@ RULE may be nil to set the rules to default, `all',
   ;;
   ;; TODO: Match rules to these user-friendly notification states for 
presentation.  See
   ;; 
<https://github.com/matrix-org/matrix-react-sdk/blob/8c67984f50f985aa481df24778078030efa39001/src/RoomNotifs.ts>.
+
+  ;; TODO: Support `all-loud' ("all_messages_loud").
   (interactive
    (pcase-let* ((`(,room ,session) (or (when (bound-and-true-p ement-room)
                                          (list ement-room ement-session))
                                        (ement-complete-room)))
                 (prompt (format "Set notification rules for %s: " 
(ement--format-room room)))
-                (available-rules (ement-alist "Default" nil
-                                              "All messages" 'all
-                                              "Mentions and keywords" 
'mentions-and-keywords
-                                              "None" 'none))
-                (selected-rule (completing-read prompt (mapcar #'car 
available-rules) nil t))
-                (rule (alist-get selected-rule available-rules nil nil 
#'equal)))
-     (list rule room session)))
+                (available-states (ement-alist "Default" nil
+                                               "All messages" 'all
+                                               "Mentions and keywords" 
'mentions-and-keywords
+                                               "None" 'none))
+                (selected-rule (completing-read prompt (mapcar #'car 
available-states) nil t))
+                (state (alist-get selected-rule available-states nil nil 
#'equal)))
+     (list state room session)))
   (cl-labels ((set-rule (kind rule queue message-fn)
                         (pcase-let* (((cl-struct ement-room (id room-id)) room)
                                      (rule-id (url-hexify-string room-id))
                                      (endpoint (format 
"pushrules/global/%s/%s" kind rule-id))
                                      (method (if rule 'put 'delete))
                                      (then (if rule
-                                               ;; Setting rules requires 
PUTting the rules, then making a second request to enable them.
+                                               ;; Setting rules requires 
PUTting the rules, then making a second
+                                               ;; request to enable them.
                                                (lambda (_data)
                                                  (ement-api session (concat 
endpoint "/enabled") :queue queue :version "r0"
                                                    :method 'put :data 
(json-encode (ement-alist 'enabled t))
@@ -484,7 +487,7 @@ RULE may be nil to set the rules to default, `all',
                                                 (ement-api-error plz-error))))
                                         (_ ;; Unexpected error: re-signal.
                                          (ement-api-error plz-error)))))))))
-    (pcase-let* ((available-rules
+    (pcase-let* ((available-states
                   (ement-alist
                    nil (ement-alist
                         "override" nil
@@ -507,7 +510,7 @@ RULE may be nil to set the rules to default, `all',
                                                            'key "room_id"
                                                            'pattern 
(ement-room-id room))))
                           "room" nil)))
-                 (kinds-and-rules (alist-get rule available-rules nil nil 
#'equal)))
+                 (kinds-and-rules (alist-get state available-states nil nil 
#'equal)))
       (cl-loop with queue = (make-plz-queue :limit 1)
                with total = (1- (length kinds-and-rules))
                for count from 0
@@ -515,8 +518,8 @@ RULE may be nil to set the rules to default, `all',
                                     (lambda (_data)
                                       (message "Set notification rules for 
room: %s" (ement--format-room room)))
                                   #'ignore)
-               for (kind . rule) in kinds-and-rules
-               do (set-rule kind rule queue message-fn)))))
+               for (kind . state) in kinds-and-rules
+               do (set-rule kind state queue message-fn)))))
 
 ;;;;; Public functions
 
diff --git a/ement-room.el b/ement-room.el
index a19df8dc02..65fbfd2a35 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -152,7 +152,7 @@ Used to, e.g. call `ement-room-compose-org'.")
     (define-key map (kbd "r m") #'ement-list-members)
     (define-key map (kbd "r t") #'ement-room-set-topic)
     (define-key map (kbd "r f") #'ement-room-set-message-format)
-    (define-key map (kbd "r n") #'ement-room-set-notifications)
+    (define-key map (kbd "r n") #'ement-room-set-notification-state)
     (define-key map (kbd "r T") #'ement-tag-room)
 
     ;; Room membership
@@ -4149,7 +4149,7 @@ For use in `completion-at-point-functions'."
               ("r m" "List members" ement-list-members)
               ("r t" "Set topic" ement-room-set-topic)
               ("r f" "Set message format" ement-room-set-message-format)
-              ("r n" "Set notification rules" ement-room-set-notifications)
+              ("r n" "Set notification state" 
ement-room-set-notification-state)
               ("r T" "Tag/untag room" ement-tag-room
                :description (lambda ()
                               (format "Tag/untag room (%s/%s)"



reply via email to

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