~emersion/soju-dev

Forward user mode changes in single-upstream mode v1 APPLIED

Gregory Anders: 1
 Forward user mode changes in single-upstream mode

 2 files changed, 34 insertions(+), 5 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/soju-dev/patches/23230/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Forward user mode changes in single-upstream mode Export this patch

---
 downstream.go | 16 ++++++++++++++--
 upstream.go   | 23 ++++++++++++++++++++---
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/downstream.go b/downstream.go
index 8e94095..5ee99ec 100644
--- a/downstream.go
+++ b/downstream.go
@@ -1182,6 +1182,14 @@ func (dc *downstreamConn) welcome() error {
		}
	})

	if uc := dc.upstream(); uc != nil {
		dc.SendMessage(&irc.Message{
			Prefix: dc.srv.prefix(),
			Command: irc.RPL_UMODEIS,
			Params: []string{dc.nick, string(uc.modes)},
		})
	}

	return nil
}

@@ -1601,11 +1609,15 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
					})
				})
			} else {
				// TODO: only do this in multi-upstream mode
				var userMode string
				if dc.upstream() != nil {
					userMode = string(dc.upstream().modes)
				}

				dc.SendMessage(&irc.Message{
					Prefix:  dc.srv.prefix(),
					Command: irc.RPL_UMODEIS,
					Params:  []string{dc.nick, ""}, // TODO
					Params:  []string{dc.nick, userMode},
				})
			}
			return nil
diff --git a/upstream.go b/upstream.go
index 1f42a24..67ccc28 100644
--- a/upstream.go
+++ b/upstream.go
@@ -932,8 +932,18 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
			if name != uc.nick {
				return fmt.Errorf("received MODE message for unknown nick %q", name)
			}
			return uc.modes.Apply(modeStr)
			// TODO: notify downstreams about user mode change?

			if err := uc.modes.Apply(modeStr); err != nil {
				return err
			}

			uc.forEachDownstream(func (dc *downstreamConn) {
				if dc.upstream() == nil {
					return
				}

				dc.SendMessage(msg)
			})
		} else { // channel mode change
			ch, err := uc.getChannel(name)
			if err != nil {
@@ -982,7 +992,14 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
		if err := uc.modes.Apply(modeStr); err != nil {
			return err
		}
		// TODO: send RPL_UMODEIS to downstream connections when applicable

		uc.forEachDownstream(func (dc *downstreamConn) {
			if dc.upstream() == nil {
				return
			}

			dc.SendMessage(msg)
		})
	case irc.RPL_CHANNELMODEIS:
		var channel string
		if err := parseMessageParams(msg, nil, &channel); err != nil {
-- 
2.32.0
Moved the RPL_UMODEIS message right before RPL_NOMOTD in
downstreamConn.welcome(), as instructed by the spec. Also ran go fmt.
With these changes, this LGTM.

Pushed, thanks!