branch: elpa/jabber
commit bd9634ee31d02219caa05cad21baa647c7eafb57
Author: Thanos Apollo <[email protected]>
Commit: Thanos Apollo <[email protected]>

    buffer: Route feature lookups through registry
---
 lisp/jabber-alert.el            |  6 ++++--
 lisp/jabber-chatstates.el       |  5 ++---
 lisp/jabber-reactions.el        |  9 ++++-----
 tests/jabber-test-chatstates.el | 36 ++++++++++++++++++------------------
 tests/jabber-test-reactions.el  | 28 ++++++++++++++--------------
 5 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/lisp/jabber-alert.el b/lisp/jabber-alert.el
index 71a399349f..f40d352ad0 100644
--- a/lisp/jabber-alert.el
+++ b/lisp/jabber-alert.el
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'jabber-buffer-registry)
 (require 'jabber-presence-display)
 (require 'jabber-util)
 (require 'jabber-xml)
@@ -241,7 +242,6 @@ files."
 ;; Global reference declarations
 
 (declare-function jabber-chat-get-buffer "jabber-chat.el" (chat-with &optional 
jc))
-(declare-function jabber-chat-find-buffer "jabber-chat.el" (chat-with))
 (declare-function jabber-chat-send "jabber-chat.el"
                   (jc body &optional extra-elements))
 (defvar jabber-xml-data)                ; jabber.el
@@ -434,7 +434,9 @@ OLDSTATUS, NEWSTATUS and STATUSTEXT match the parent 
function's signature.
 
 This function is not called directly, but can be used as the value for
 `jabber-alert-presence-message-function'."
-  (when (jabber-chat-find-buffer (jabber-xml-get-attribute jabber-xml-data 
'from))
+  (when (jabber-buffer-registry-find
+         'chat
+         (jabber-jid-user (jabber-xml-get-attribute jabber-xml-data 'from)))
     (jabber-presence-default-message who oldstatus newstatus statustext)))
 
 (defun jabber-presence-wave (who _oldstatus _newstatus _statustext 
proposed-alert)
diff --git a/lisp/jabber-chatstates.el b/lisp/jabber-chatstates.el
index ccbd340534..d54654a641 100644
--- a/lisp/jabber-chatstates.el
+++ b/lisp/jabber-chatstates.el
@@ -30,6 +30,7 @@
 
 (require 'cl-lib)
 (require 'subr-x)
+(require 'jabber-buffer-registry)
 (require 'jabber-util)
 (require 'ewoc)
 (require 'jabber-core)
@@ -44,8 +45,6 @@
 (defvar jabber-chat-ewoc)               ; jabber-chatbuffer.el
 (defvar jabber-chatting-with)           ; jabber-chat.el
 
-(declare-function jabber-muc-find-buffer "jabber-muc" (group))
-
 (defgroup jabber-chatstates nil
   "Chat state notifications."
   :group 'jabber)
@@ -189,7 +188,7 @@ It can be sent and cancelled several times.")
   "Apply incoming MUC chat STATE from FROM on JC."
   (when-let* ((group (jabber-jid-user from))
               (nick (jabber-jid-resource from))
-              (buffer (jabber-muc-find-buffer group)))
+              (buffer (jabber-buffer-registry-find 'muc group)))
     (with-current-buffer buffer
       (unless (jabber-chatstates--muc-self-nick-p group nick jc)
         (setq jabber-chatstates--muc-composers
diff --git a/lisp/jabber-reactions.el b/lisp/jabber-reactions.el
index 62fdaf9130..990057f3de 100644
--- a/lisp/jabber-reactions.el
+++ b/lisp/jabber-reactions.el
@@ -29,6 +29,7 @@
 (require 'cl-lib)
 (require 'ewoc)
 (require 'subr-x)
+(require 'jabber-buffer-registry)
 (require 'jabber-chatbuffer)
 (require 'jabber-db)
 (require 'jabber-disco)
@@ -69,8 +70,6 @@ are not filtered against it."
 (defvar jabber-point-insert)
 
 (declare-function jabber-chat--unwrap-carbon "jabber-chat" (jc xml-data))
-(declare-function jabber-chat-find-buffer "jabber-chat" (chat-with))
-(declare-function jabber-muc-find-buffer "jabber-muc" (group))
 
 ;;; Pure helpers
 
@@ -285,9 +284,9 @@ as XEP-0428 fallback for reactions does not count as a real 
body."
 (defun jabber-reactions--buffer-for-stanza (from type)
   "Return the displayed chat buffer for incoming FROM and message TYPE."
   (when from
-    (if (string= type "groupchat")
-        (jabber-muc-find-buffer (jabber-jid-user from))
-      (jabber-chat-find-buffer (jabber-jid-user from)))))
+    (jabber-buffer-registry-find
+     (if (string= type "groupchat") 'muc 'chat)
+     (jabber-jid-user from))))
 
 (defun jabber-reactions--storage-peer (jc message type)
   "Return the DB peer for reaction-bearing MESSAGE on JC with TYPE."
diff --git a/tests/jabber-test-chatstates.el b/tests/jabber-test-chatstates.el
index ecb1f63691..5e35af36e1 100644
--- a/tests/jabber-test-chatstates.el
+++ b/tests/jabber-test-chatstates.el
@@ -404,8 +404,8 @@ nil after the first message, breaking subsequent composing 
detection."
       (setq-local jabber-chatstates--ewoc-node old-node)
       (ewoc-enter-last jabber-chat-ewoc '(:muc-message "alice: hello"))
       (let ((muc-buffer (current-buffer)))
-        (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                   (lambda (_group) muc-buffer))
+        (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                   (lambda (_kind _group) muc-buffer))
                   ((symbol-function 'jabber-muc-nickname) #'ignore))
           (jabber-handle-incoming-message-chatstates
            'fake-jc
@@ -441,8 +441,8 @@ nil after the first message, breaking subsequent composing 
detection."
         (seen-group nil))
     (with-temp-buffer
       (let ((muc-buffer (current-buffer)))
-        (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                   (lambda (group)
+        (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                   (lambda (_kind group)
                      (setq seen-group group)
                      muc-buffer))
                   ((symbol-function 'jabber-muc-nickname) #'ignore)
@@ -467,8 +467,8 @@ nil after the first message, breaking subsequent composing 
detection."
       (setq-local jabber-chatstates--muc-composers '("alice"))
       (setq-local jabber-chatstates--ewoc-node node)
       (let ((muc-buffer (current-buffer)))
-        (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                   (lambda (_group) muc-buffer))
+        (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                   (lambda (_kind _group) muc-buffer))
                   ((symbol-function 'jabber-muc-nickname) #'ignore))
           (jabber-handle-incoming-message-chatstates
            'fake-jc
@@ -483,8 +483,8 @@ nil after the first message, breaking subsequent composing 
detection."
   (with-temp-buffer
     (let ((muc-buffer (current-buffer))
           (jabber-chat-ewoc (ewoc-create #'ignore)))
-      (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                 (lambda (_group) muc-buffer))
+      (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _group) muc-buffer))
                 ((symbol-function 'jabber-muc-nickname) #'ignore))
         (jabber-handle-incoming-message-chatstates
          'fake-jc
@@ -506,8 +506,8 @@ nil after the first message, breaking subsequent composing 
detection."
   (with-temp-buffer
     (let ((muc-buffer (current-buffer))
           (jabber-chat-ewoc (ewoc-create #'ignore)))
-      (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                 (lambda (_group) muc-buffer))
+      (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _group) muc-buffer))
                 ((symbol-function 'jabber-muc-nickname) #'ignore))
         (jabber-handle-incoming-message-chatstates
          'fake-jc
@@ -526,8 +526,8 @@ nil after the first message, breaking subsequent composing 
detection."
   (with-temp-buffer
     (let ((muc-buffer (current-buffer))
           (jabber-chat-ewoc (ewoc-create #'ignore)))
-      (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                 (lambda (_group) muc-buffer))
+      (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _group) muc-buffer))
                 ((symbol-function 'jabber-muc-nickname) #'ignore))
         (jabber-handle-incoming-message-chatstates
          'fake-jc
@@ -546,8 +546,8 @@ nil after the first message, breaking subsequent composing 
detection."
   (let ((find-called nil)
         (entered nil))
     (with-temp-buffer
-      (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                 (lambda (_group)
+      (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _group)
                    (setq find-called t)
                    (current-buffer)))
                 ((symbol-function 'jabber-muc-nickname)
@@ -574,8 +574,8 @@ nil after the first message, breaking subsequent composing 
detection."
       (setq-local jabber-chatstates--ewoc-node old-node)
       (ewoc-enter-last jabber-chat-ewoc '(:muc-message "alice: hello"))
       (let ((muc-buffer (current-buffer)))
-        (cl-letf (((symbol-function 'jabber-muc-find-buffer)
-                   (lambda (_group) muc-buffer))
+        (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                   (lambda (_kind _group) muc-buffer))
                   ((symbol-function 'jabber-muc-nickname)
                    (lambda (_group _jc) "alice")))
           (jabber-handle-incoming-message-chatstates
@@ -601,8 +601,8 @@ nil after the first message, breaking subsequent composing 
detection."
                    (lambda (from jc)
                      (setq direct-called (list from jc))
                      (buffer-name chat-buffer)))
-                  ((symbol-function 'jabber-muc-find-buffer)
-                   (lambda (_group)
+                  ((symbol-function 'jabber-buffer-registry-find)
+                   (lambda (_kind _group)
                      (setq muc-called t)
                      nil))
                   ((symbol-function 'jabber-chat-ewoc-enter)
diff --git a/tests/jabber-test-reactions.el b/tests/jabber-test-reactions.el
index 9a5f6319f4..dd6922fcfa 100644
--- a/tests/jabber-test-reactions.el
+++ b/tests/jabber-test-reactions.el
@@ -320,8 +320,8 @@
                                                  ,inner)))))
       (cl-letf (((symbol-function 'jabber-chat--unwrap-carbon)
                  (lambda (_jc _xml-data) (cons inner nil)))
-                ((symbol-function 'jabber-chat-find-buffer)
-                 (lambda (_chat-with) (current-buffer)))
+                ((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _peer) (current-buffer)))
                 ((symbol-function 'jabber-db-replace-reactions) #'ignore)
                 ((symbol-function 'jabber-chat-ewoc-find-by-id)
                  (lambda (_stanza-id) node))
@@ -349,8 +349,8 @@
                                              ,inner)))))
       (cl-letf (((symbol-function 'jabber-chat--unwrap-carbon)
                  (lambda (_jc _xml-data) (cons inner carbon-buffer)))
-                ((symbol-function 'jabber-chat-find-buffer)
-                 (lambda (_chat-with) nil))
+                ((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _peer) nil))
                 ((symbol-function 'jabber-db-replace-reactions) #'ignore)
                 ((symbol-function 'jabber-chat-ewoc-find-by-id)
                  (lambda (_stanza-id) node))
@@ -375,8 +375,8 @@
                                       (id . "target-1"))
                                      (reaction nil "🎉"))))
            (persisted nil))
-      (cl-letf (((symbol-function 'jabber-chat-find-buffer)
-                 (lambda (_chat-with) (current-buffer)))
+      (cl-letf (((symbol-function 'jabber-buffer-registry-find)
+                 (lambda (_kind _peer) (current-buffer)))
                 ((symbol-function 'jabber-db-replace-reactions)
                  (lambda (&rest _)
                    (setq persisted t)))
@@ -406,8 +406,8 @@
                                 (stamp . "2025-01-15T10:30:00Z"))))))
      (cl-letf (((symbol-function 'jabber-connection-bare-jid)
                 (lambda (_jc) "[email protected]"))
-               ((symbol-function 'jabber-chat-find-buffer)
-                (lambda (_chat-with) nil)))
+               ((symbol-function 'jabber-buffer-registry-find)
+                (lambda (_kind _peer) nil)))
        (jabber-reactions--handle-message 'fake-jc xml))
      (let* ((entry (car (jabber-db-backlog
                          "[email protected]" "[email protected]")))
@@ -437,8 +437,8 @@
                                   (stamp . ,stamp))))))
      (cl-letf (((symbol-function 'jabber-connection-bare-jid)
                 (lambda (_jc) "[email protected]"))
-               ((symbol-function 'jabber-chat-find-buffer)
-                (lambda (_chat-with) nil)))
+               ((symbol-function 'jabber-buffer-registry-find)
+                (lambda (_kind _peer) nil)))
        (jabber-reactions--handle-message
         'fake-jc (reaction-message "2025-01-15T10:30:00Z" "👍"))
        (jabber-reactions--handle-message
@@ -474,8 +474,8 @@
                                    (stamp . "2025-01-15T10:30:00Z"))))))
        (cl-letf (((symbol-function 'jabber-connection-bare-jid)
                   (lambda (_jc) "[email protected]"))
-                 ((symbol-function 'jabber-chat-find-buffer)
-                  (lambda (_chat-with) (current-buffer)))
+                 ((symbol-function 'jabber-buffer-registry-find)
+                  (lambda (_kind _peer) (current-buffer)))
                  ((symbol-function 'jabber-chat-ewoc-find-by-id)
                   (lambda (_stanza-id) node))
                  ((symbol-function 'jabber-chat-ewoc-invalidate) #'ignore))
@@ -498,8 +498,8 @@
                                      (reaction nil ,reaction)))))
      (cl-letf (((symbol-function 'jabber-connection-bare-jid)
                 (lambda (_jc) "[email protected]"))
-               ((symbol-function 'jabber-chat-find-buffer)
-                (lambda (_chat-with) nil))
+               ((symbol-function 'jabber-buffer-registry-find)
+                (lambda (_kind _peer) nil))
                ((symbol-function 'float-time)
                 (lambda (&optional _time) 1234.0)))
        (jabber-reactions--handle-message 'fake-jc (reaction-message "👍"))

Reply via email to