~emersion/public-inbox

soju: Join all channels with a single JOIN message v2 APPLIED

Eyal Sawady: 1
 Join all channels with a single JOIN message

 1 files changed, 12 insertions(+), 8 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/10809/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH soju v2] Join all channels with a single JOIN message Export this patch

---
 upstream.go | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/upstream.go b/upstream.go
index efedbea..c7a8aea 100644
--- a/upstream.go
+++ b/upstream.go
@@ -519,16 +519,20 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
			dc.updateSupportedCaps()
		})

		// TODO: split this into multiple messages if need be
		names := []string{}
		keys := []string{}
		for _, ch := range uc.network.channels {
			params := []string{ch.Name}
			if ch.Key != "" {
				params = append(params, ch.Key)
			}
			uc.SendMessage(&irc.Message{
				Command: "JOIN",
				Params:  params,
			})
			names = append(names, ch.Name)
			keys = append(keys, ch.Key)
		}
		uc.SendMessage(&irc.Message{
			Command: "JOIN",
			Params: []string{
				strings.Join(names, ","),
				strings.Join(keys, ","),
			},
		})
	case irc.RPL_MYINFO:
		if err := parseMessageParams(msg, nil, &uc.serverName, nil, &uc.availableUserModes, nil); err != nil {
			return err
-- 
2.26.2
Thanks for your updated patch! Applied with a minor style cleanup (see below).
Actually, delthas pointed out an issue with this patch: this isn't
strictly RFC-compliant when joining some channels without a key. The
RFC says we should put the channels with a key first like so:

    JOIN #foo,&bar fubar            ; join channel #foo using key "fubar"
                                    and &bar using no key.

This would only matter if a server errors out when we provide an empty
key to join a channel without a key.