Subject: bug#52010: 28.0.60; ERC now ignores dialed server names in autojoin

From: "J.P." <[email-masked]>
Date: Sun, 21 Nov 2021 03:31:03 -0800

v2: a small tweak to leave a tidier footprint for git-blame.

Also, some slight corrections on the timeline:

  Jan 20, 2003 - Register autojoin function with `erc-after-connect'
                 hook, which passes in `erc-announced-server-name' for
                 function's server param

  Jun 26, 2005 - Add dialed server as fallback when announced name
                 missing

  Sep 16, 2005 - Deprecate `erc-announced-server-name' in favor of
                 `erc-server-announced-name'

  Jan 05, 2017 - Switch from announced to dialed, ignoring server param
                 provided by `erc-after-connect' hook

  Sep 16, 2021 - Switch from dialed to announced, but consider networks

    This patch - Stay the course, but always fall back to dialed (not
                 just when unset)

    Bug #48598 - Prefer unique session identifiers based around and
                 compatible with networks, but fall back on announced,
                 then dialed (for compatibility)

>From e804e5c160b8ee1fa1ad2e1af7bcf3dd694cd14b Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email-masked]>
Date: Sat, 20 Nov 2021 23:53:49 -0800
Subject: NOT A PATCH

F. Jason Park (1):
  Fall back on dialed server names in erc-join

 lisp/erc/erc-join.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Interdiff:
diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el
index 1a6bdedc98..887c40a00c 100644
--- a/lisp/erc/erc-join.el
+++ b/lisp/erc/erc-join.el
@@ -105,9 +105,9 @@ erc-autojoin-domain-only
 This is important for networks that redirect you to other
 servers, presumably in the same domain.
 
-This treatment will only be applied to so-called \"announced names\",
-like zirconium.libera.chat, but not to \"dialed\" hostnames, like
-my.proxy.localdomain or my.vps.example.com."
+This treatment will only be applied to so-called \"announced\" names,
+like zirconium.libera.chat, but not to \"dialed\" names, like
+209.51.188.117 or my.vps.example.net."
   :type 'boolean)
 
 (defvar-local erc--autojoin-timer nil)
@@ -131,7 +131,7 @@ erc-autojoin-server-match
 This should be a key from `erc-autojoin-channels-alist'."
   (or (eq candidate (erc-network))
       (and (stringp candidate)
-           (or (and erc-server-announced-name ; unnecessary after #48598
+           (or (and erc-server-announced-name
                     (string-match-p candidate erc-server-announced-name))
                (string-match-p candidate erc-session-server)))))
 
@@ -188,12 +188,12 @@ erc-autojoin-channels
 (defun erc-autojoin-current-server ()
   "Compute the current server for lookup in `erc-autojoin-channels-alist'.
 Respects `erc-autojoin-domain-only'."
-  (if (and erc-autojoin-domain-only
-           erc-server-announced-name
-           (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$"
-                         erc-server-announced-name))
-      (match-string 1 erc-server-announced-name)
-    erc-session-server))
+  (let ((server erc-server-announced-name))
+    (if (and erc-autojoin-domain-only
+             server
+	     (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
+	(match-string 1 server)
+      erc-session-server)))
 
 (defun erc-autojoin-add (proc parsed)
   "Add the channel being joined to `erc-autojoin-channels-alist'."
-- 
2.31.1

>From e804e5c160b8ee1fa1ad2e1af7bcf3dd694cd14b Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email-masked]>
Date: Wed, 10 Nov 2021 23:42:42 -0800
Subject: [PATCH 1/1] Fall back on dialed server names in erc-join

* lisp/erc/erc-join.el (erc-autojoin-server-match,
erc-autojoin-current-server): as a fallback, always try the original
server argument passed to `erc-open' when matching against members of
`erc-autojoin-channels-alist'.  Similarly, when adding and removing
items, only apply the `erc-autojoin-domain-only' truncation treatment
to "announced" servers.
---
 lisp/erc/erc-join.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el
index 2ed8622b85..887c40a00c 100644
--- a/lisp/erc/erc-join.el
+++ b/lisp/erc/erc-join.el
@@ -103,7 +103,11 @@ erc-autojoin-domain-only
 If non-nil, and a channel on the server a.b.c is joined, then
 only b.c is used as the server for `erc-autojoin-channels-alist'.
 This is important for networks that redirect you to other
-servers, presumably in the same domain."
+servers, presumably in the same domain.
+
+This treatment will only be applied to so-called \"announced\" names,
+like zirconium.libera.chat, but not to \"dialed\" names, like
+209.51.188.117 or my.vps.example.net."
   :type 'boolean)
 
 (defvar-local erc--autojoin-timer nil)
@@ -127,9 +131,9 @@ erc-autojoin-server-match
 This should be a key from `erc-autojoin-channels-alist'."
   (or (eq candidate (erc-network))
       (and (stringp candidate)
-	   (string-match-p candidate
-                           (or erc-server-announced-name
-			       erc-session-server)))))
+           (or (and erc-server-announced-name
+                    (string-match-p candidate erc-server-announced-name))
+               (string-match-p candidate erc-session-server)))))
 
 (defun erc-autojoin-after-ident (_network _nick)
   "Autojoin channels in `erc-autojoin-channels-alist'.
@@ -184,11 +188,12 @@ erc-autojoin-channels
 (defun erc-autojoin-current-server ()
   "Compute the current server for lookup in `erc-autojoin-channels-alist'.
 Respects `erc-autojoin-domain-only'."
-  (let ((server (or erc-server-announced-name erc-session-server)))
+  (let ((server erc-server-announced-name))
     (if (and erc-autojoin-domain-only
+             server
 	     (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
 	(match-string 1 server)
-      server)))
+      erc-session-server)))
 
 (defun erc-autojoin-add (proc parsed)
   "Add the channel being joined to `erc-autojoin-channels-alist'."
-- 
2.31.1