1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Allow updating of /IGNORE timeouts in ERC

* lisp/erc/erc.el (erc--read-time-period, erc--decode-time-period):
Move body of former, now a superficial wrapper, to latter, a new
function.
(erc--format-time-period): New function.
(erc--get-ignore-timer-args): New function.
(erc--find-ignore-timer): New function to search through `timer-list'
to find matching ignore timer.
(erc-cmd-IGNORE): Refactor and redo doc string.  Add new optional
`timespec' parameter, primarily to aid in testing.  Update an existing
timer instead of always creating one, and display time remaining in
"ignore list" output.  Pass server buffer instead of current buffer to
timer callbacks because `erc--unignore-user' displays its messages in
the `active' buffer, not necessarily the issuing one.  Note that doing
this does discard potentially useful information, so if ever reverting,
we can change the `cl-find' :test in `erc--find-ignore-timer' to
something that compares the `erc-server-process' of both buffers.
;;
;; Something like:
;;
;; (defun erc--ignore-timers-equal-p (a b)
;;   (and (equal (car a) (car b))
;;        (eq (buffer-local-value 'erc-server-process (cadr a))
;;            (buffer-local-value 'erc-server-process (cadr b)))))
;;
(erc-cmd-UNIGNORE): Pass `erc-ignore-list' member matching `user'
parameter to `erc--unignore-user' instead of original, raw parameter,
along with the server buffer.
(erc--unignore-user): Cancel existing timer and don't bother switching
to server buffer since we're already there.
(erc-message-english-ignore-list): New variable.
* test/lisp/erc/erc-scenarios-ignore.el: New file.
* test/lisp/erc/erc-tests.el (erc--read-time-period): New test.
(erc-cmd-UNIGNORE): New test.  (Bug#70127)
This commit is contained in:
F. Jason Park 2024-04-01 15:27:47 -07:00
parent c1266d355a
commit e0df2841fb
3 changed files with 176 additions and 23 deletions

View file

@ -0,0 +1,79 @@
;;; erc-scenarios-ignore.el --- /IGNORE scenarios ERC -*- lexical-binding: t -*-
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; TODO add test covering the same ignored speaker in two different
;; channels on the same server: they should be ignored in both.
;;; Code:
(require 'ert-x)
(eval-and-compile
(let ((load-path (cons (ert-resource-directory) load-path)))
(require 'erc-scenarios-common)))
(ert-deftest erc-scenarios-ignore/basic ()
:tags '(:expensive-test)
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "base/assoc/multi-net")
(erc-server-flood-penalty 0.1)
(dumb-server-foonet (erc-d-run "localhost" t 'foonet))
(dumb-server-barnet (erc-d-run "localhost" t 'barnet))
(erc-autojoin-channels-alist '((foonet "#chan") (barnet "#chan")))
(port-foonet (process-contact dumb-server-foonet :service))
(port-barnet (process-contact dumb-server-barnet :service))
(expect (erc-d-t-make-expecter)))
(ert-info ("Connect to two networks")
(with-current-buffer (erc :server "127.0.0.1"
:port port-barnet
:nick "tester"
:password "changeme"
:full-name "tester"))
(with-current-buffer (erc :server "127.0.0.1"
:port port-foonet
:nick "tester"
:password "changeme"
:full-name "tester")
(funcall expect 10 "debug mode")))
(with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan@foonet"))
(funcall expect 10 "<bob> tester, welcome!")
(funcall expect 10 "<alice> tester, welcome!")
(erc-scenarios-common-say "/ignore alice 1m")
(erc-scenarios-common-say "/ignore mike 1h")
(funcall expect 10 "ignoring alice for 1m0s")
(funcall expect 10 "<bob> alice: Signior Iachimo")
(erc-scenarios-common-say "/ignore")
(funcall expect 10 "alice 59s")
(funcall expect 10 "mike 59m59s")
(funcall expect -0.1 "<alice>")
(funcall expect 10 "<bob> alice: The ground is bloody")
(erc-scenarios-common-say "/unignore alice")
(funcall expect 10 "<alice>"))
;; No <mike> messages were ignored on network barnet.
(with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan@barnet"))
(funcall expect 10 "<mike> tester, welcome!")
(funcall expect 10 "<joe> tester, welcome!")
(funcall expect 10 "<mike> joe: Whipp'd")
(funcall expect 10 "<mike> joe: Double"))))
;;; erc-scenarios-ignore.el ends here

View file

@ -50,6 +50,34 @@
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
(should (equal (erc--read-time-period "foo: ") 86400))))
(ert-deftest erc--format-time-period ()
(should (equal (erc--format-time-period 59) "59s"))
(should (equal (erc--format-time-period 59.9) "59s"))
(should (equal (erc--format-time-period 60) "1m0s"))
(should (equal (erc--format-time-period 119) "1m59s"))
(should (equal (erc--format-time-period 119.9) "1m59s"))
(should (equal (erc--format-time-period 120.9) "2m0s"))
(should (equal (erc--format-time-period 3599.9) "59m59s"))
(should (equal (erc--format-time-period 3600) "1h0m0s")))
;; This asserts that the first pattern on file matching a supplied
;; `user' parameter will be removed after confirmation.
(ert-deftest erc-cmd-UNIGNORE ()
;; XXX these functions mutate `erc-ignore-list' via `delete'.
(should (local-variable-if-set-p 'erc-ignore-list))
(erc-tests-common-make-server-buf)
(setq erc-ignore-list (list ".")) ; match anything
(ert-simulate-keys (list ?\r)
(erc-cmd-IGNORE "abc"))
(should (equal erc-ignore-list (list "abc" ".")))
(cl-letf (((symbol-function 'y-or-n-p) #'always))
(erc-cmd-UNIGNORE "abcdef")
(should (equal erc-ignore-list (list ".")))
(erc-cmd-UNIGNORE "foo"))
(should-not erc-ignore-list))
(ert-deftest erc-with-all-buffers-of-server ()
(let (proc-exnet
proc-onet