aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2023-09-06 19:40:11 -0700
committerF. Jason Park2023-09-17 16:17:59 -0700
commita0ed463babaa6301dfe2fecc27e2a6c92eb0d90c (patch)
tree6fbd6a8cd2bb99b40ee7d505c9fb856c9abbd0c2
parent69a154616e11149df80d22a9279818e1d3fda317 (diff)
downloademacs-a0ed463babaa6301dfe2fecc27e2a6c92eb0d90c.tar.gz
emacs-a0ed463babaa6301dfe2fecc27e2a6c92eb0d90c.zip
Spoof channel users in erc-button--phantom-users-mode
* lisp/erc/erc-backend.el (erc--cmem-from-nick-function): Update forward declaration. (erc-server-PRIVMSG): Use new name for `erc--user-from-nick-function', now `erc--cmem-from-nick-function'. * lisp/erc/erc-button.el (erc-button--phantom-users, erc-button--phantom-cmems): Rename former to latter. (erc-button--fallback-user-function, erc-button--fallback-cmem-function): Rename former to latter. (erc--phantom-channel-user, erc--phantom-server-user): New superficial `cl-struct' definitions "subclassing" `erc-channel-user' and `erc-server-user'. Note that these symbols lack an `erc-button' prefix. (erc-button--add-phantom-speaker): Look for channel member instead of server user, creating one if necessary. Return a made-up `erc-channel-user' along with a fake `erc-server-user'. (erc-button--get-phantom-user, erc-button--get-phantom-cmem): Rename former to latter. (erc-button--phantom-users-mode, erc-button--phantom-users-enable, erc-button--phantom-users-disable): Use updated "cmem" names for function-valued interface variables and their implementing functions. Remove obsolete comment. (erc-button-add-nickname-buttons): Attempt to query fallback function for channel member instead of server user. * lisp/erc/erc.el (erc--user-from-nick-function, erc--cmem-from-nick-function): Rename former to latter. (erc--examine-nick, erc--cmem-get-existing): Rename former to latter. (Bug#60933)
-rw-r--r--lisp/erc/erc-backend.el4
-rw-r--r--lisp/erc/erc-button.el64
-rw-r--r--lisp/erc/erc.el17
3 files changed, 46 insertions, 39 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 9e121ec1e92..fb10ee31c78 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -104,7 +104,7 @@
104(defvar erc--called-as-input-p) 104(defvar erc--called-as-input-p)
105(defvar erc--display-context) 105(defvar erc--display-context)
106(defvar erc--target) 106(defvar erc--target)
107(defvar erc--user-from-nick-function) 107(defvar erc--cmem-from-nick-function)
108(defvar erc-channel-list) 108(defvar erc-channel-list)
109(defvar erc-channel-users) 109(defvar erc-channel-users)
110(defvar erc-default-nicks) 110(defvar erc-default-nicks)
@@ -1944,7 +1944,7 @@ add things to `%s' instead."
1944 ;; at this point. 1944 ;; at this point.
1945 (erc-update-channel-member (if privp nick tgt) nick nick 1945 (erc-update-channel-member (if privp nick tgt) nick nick
1946 privp nil nil nil nil nil host login nil nil t) 1946 privp nil nil nil nil nil host login nil nil t)
1947 (let ((cdata (funcall erc--user-from-nick-function 1947 (let ((cdata (funcall erc--cmem-from-nick-function
1948 (erc-downcase nick) sndr parsed))) 1948 (erc-downcase nick) sndr parsed)))
1949 (setq fnick (funcall erc-format-nick-function 1949 (setq fnick (funcall erc-format-nick-function
1950 (car cdata) (cdr cdata)))))) 1950 (car cdata) (cdr cdata))))))
diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el
index 8c1188e64a2..596f896d9c5 100644
--- a/lisp/erc/erc-button.el
+++ b/lisp/erc/erc-button.el
@@ -380,32 +380,37 @@ buttonizing ought to proceed and nil otherwise. While running,
380all faces defined in `erc-button' are bound temporarily and can 380all faces defined in `erc-button' are bound temporarily and can
381be updated at will.") 381be updated at will.")
382 382
383(defvar-local erc-button--phantom-users nil) 383(defvar-local erc-button--phantom-cmems nil)
384 384
385(defvar erc-button--fallback-user-function #'ignore 385(defvar erc-button--fallback-cmem-function #'ignore
386 "Function to determine `erc-server-user' if not found in the usual places. 386 "Function to determine channel member if not found in the usual places.
387Called with DOWNCASED-NICK, NICK, and NICK-BOUNDS when 387Called with DOWNCASED-NICK, NICK, and NICK-BOUNDS when
388`erc-button-add-nickname-buttons' cannot find a user object for 388`erc-button-add-nickname-buttons' cannot find a user object for
389DOWNCASED-NICK in `erc-channel-users' or `erc-server-users'.") 389DOWNCASED-NICK in `erc-channel-users' or `erc-server-users'.")
390 390
391;; Historical or fictitious users. As long as these two structs
392;; remain superficial "subclasses" with the same slots and defaults,
393;; they can live here instead of in erc-common.el.
394(cl-defstruct (erc--phantom-channel-user (:include erc-channel-user)))
395(cl-defstruct (erc--phantom-server-user (:include erc-server-user)))
396
391(defun erc-button--add-phantom-speaker (downcased nuh _parsed) 397(defun erc-button--add-phantom-speaker (downcased nuh _parsed)
392 "Stash fictitious `erc-server-user' while processing \"PRIVMSG\".
393Expect DOWNCASED to be the downcased nickname, NUH to be a triple
394of (NICK LOGIN HOST), and parsed to be an `erc-response' object."
395 (pcase-let* ((`(,nick ,login ,host) nuh) 398 (pcase-let* ((`(,nick ,login ,host) nuh)
396 (user (or (gethash downcased erc-button--phantom-users) 399 (cmem (gethash downcased erc-button--phantom-cmems))
397 (make-erc-server-user 400 (user (or (car cmem)
401 (make-erc--phantom-server-user
398 :nickname nick 402 :nickname nick
399 :host (and (not (string-empty-p host)) host) 403 :host (and (not (string-empty-p host)) host)
400 :login (and (not (string-empty-p login)) login))))) 404 :login (and (not (string-empty-p login)) login))))
401 (list (puthash downcased user erc-button--phantom-users)))) 405 (cuser (or (cdr cmem)
406 (make-erc--phantom-channel-user
407 :last-message-time (current-time)))))
408 (puthash downcased (cons user cuser) erc-button--phantom-cmems)
409 (cons user cuser)))
402 410
403(defun erc-button--get-phantom-user (down _word _bounds) 411(defun erc-button--get-phantom-cmem (down _word _bounds)
404 (gethash down erc-button--phantom-users)) 412 (gethash down erc-button--phantom-cmems))
405 413
406;; In the future, we'll most likely create temporary
407;; `erc-channel-users' tables during BATCH chathistory playback, thus
408;; obviating the need for this mode entirely.
409(define-minor-mode erc-button--phantom-users-mode 414(define-minor-mode erc-button--phantom-users-mode
410 "Minor mode to recognize unknown speakers. 415 "Minor mode to recognize unknown speakers.
411Expect to be used by module setup code for creating placeholder 416Expect to be used by module setup code for creating placeholder
@@ -415,22 +420,22 @@ appeared in a prior \"353\" message and are thus a known member
415of the channel. However, don't bother creating an actual 420of the channel. However, don't bother creating an actual
416`erc-channel-user' object because their status prefix is unknown. 421`erc-channel-user' object because their status prefix is unknown.
417Instead, just spoof an `erc-server-user' and stash it during 422Instead, just spoof an `erc-server-user' and stash it during
418\"PRIVMSG\" handling via `erc--user-from-nick-function' and 423\"PRIVMSG\" handling via `erc--cmem-from-nick-function' and
419retrieve it during buttonizing via 424retrieve it during buttonizing via
420`erc-button--fallback-user-function'." 425`erc-button--fallback-user-function'."
421 :interactive nil 426 :interactive nil
422 (if erc-button--phantom-users-mode 427 (if erc-button--phantom-users-mode
423 (progn 428 (progn
424 (add-function :after-until (local 'erc--user-from-nick-function) 429 (add-function :after-until (local 'erc--cmem-from-nick-function)
425 #'erc-button--add-phantom-speaker '((depth . -50))) 430 #'erc-button--add-phantom-speaker '((depth . 30)))
426 (add-function :after-until (local 'erc-button--fallback-user-function) 431 (add-function :after-until (local 'erc-button--fallback-cmem-function)
427 #'erc-button--get-phantom-user '((depth . 50))) 432 #'erc-button--get-phantom-cmem '((depth . 50)))
428 (setq erc-button--phantom-users (make-hash-table :test #'equal))) 433 (setq erc-button--phantom-cmems (make-hash-table :test #'equal)))
429 (remove-function (local 'erc--user-from-nick-function) 434 (remove-function (local 'erc--cmem-from-nick-function)
430 #'erc-button--add-phantom-speaker) 435 #'erc-button--add-phantom-speaker)
431 (remove-function (local 'erc-button--fallback-user-function) 436 (remove-function (local 'erc-button--fallback-cmem-function)
432 #'erc-button--get-phantom-user) 437 #'erc-button--get-phantom-cmem)
433 (kill-local-variable 'erc-nicks--phantom-users))) 438 (kill-local-variable 'erc-button--phantom-cmems)))
434 439
435(defun erc-button-add-nickname-buttons (entry) 440(defun erc-button-add-nickname-buttons (entry)
436 "Search through the buffer for nicknames, and add buttons." 441 "Search through the buffer for nicknames, and add buttons."
@@ -451,11 +456,12 @@ retrieve it during buttonizing via
451 (down (erc-downcase word))) 456 (down (erc-downcase word)))
452 (let* ((erc-button-mouse-face erc-button-mouse-face) 457 (let* ((erc-button-mouse-face erc-button-mouse-face)
453 (erc-button-nickname-face erc-button-nickname-face) 458 (erc-button-nickname-face erc-button-nickname-face)
454 (cuser (and erc-channel-users (gethash down erc-channel-users))) 459 (cuser (and erc-channel-users
460 (or (gethash down erc-channel-users)
461 (funcall erc-button--fallback-cmem-function
462 down word bounds))))
455 (user (or (and cuser (car cuser)) 463 (user (or (and cuser (car cuser))
456 (and erc-server-users (gethash down erc-server-users)) 464 (and erc-server-users (gethash down erc-server-users))))
457 (funcall erc-button--fallback-user-function
458 down word bounds)))
459 (data (list word))) 465 (data (list word)))
460 (when (or (not (functionp form)) 466 (when (or (not (functionp form))
461 (and-let* ((user) 467 (and-let* ((user)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 07ba32d1cca..ec4fae548c7 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -5262,14 +5262,15 @@ Assume buffer is narrowed to the confines of an inserted message."
5262 (next-single-property-change (point-min) 'erc-speaker)))) 5262 (next-single-property-change (point-min) 'erc-speaker))))
5263 (cons beg (next-single-property-change beg 'erc-speaker))))) 5263 (cons beg (next-single-property-change beg 'erc-speaker)))))
5264 5264
5265(defvar erc--user-from-nick-function #'erc--examine-nick 5265(defvar erc--cmem-from-nick-function #'erc--cmem-get-existing
5266 "Function to possibly consider unknown user. 5266 "Function maybe returning a \"channel member\" cons from a nick.
5267Must return either nil or a cons of an `erc-server-user' and a 5267Must return either nil or a cons of an `erc-server-user' and an
5268possibly nil `erc-channel-user' for formatting a server user's 5268`erc-channel-user' (see `erc-channel-users') for use in
5269nick. Called in the appropriate buffer with the downcased nick, 5269formatting a user's nick prior to insertion. Called in the
5270the parsed NUH, and the original `erc-response' object.") 5270appropriate target buffer with the downcased nick, the parsed
5271 5271NUH, and the current `erc-response' object.")
5272(defun erc--examine-nick (downcased _nuh _parsed) 5272
5273(defun erc--cmem-get-existing (downcased _nuh _parsed)
5273 (and erc-channel-users (gethash downcased erc-channel-users))) 5274 (and erc-channel-users (gethash downcased erc-channel-users)))
5274 5275
5275(defun erc-format-privmessage (nick msg privp msgp) 5276(defun erc-format-privmessage (nick msg privp msgp)