~emersion/soju-dev

Forward RPL_TOPICWHOTIME to downstreams v1 SUPERSEDED

Hubert Hirtz: 1
 Forward RPL_TOPICWHOTIME to downstreams

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

[PATCH] Forward RPL_TOPICWHOTIME to downstreams Export this patch

Also update ch.TopicWho and ch.TopicTime when a TOPIC message is
received.

---

I wasn't sure of how to use the eventual @time tag in the TOPIC message,
since it'd need to be parsed back or something, so I left it as a TODO.

Since I'm not sure I understand the mechanism behind the similar
"firstCreationTime" (when handling RPL_CREATIONTIME), I just copied it.

 bridge.go   | 14 +++++++++++---
 upstream.go | 16 ++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/bridge.go b/bridge.go
index e434c49..c029540 100644
--- a/bridge.go
@@ -1,8 +1,10 @@
package soju

import (
	"gopkg.in/irc.v3"
	"strconv"
	"strings"

	"gopkg.in/irc.v3"
)

func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
@@ -11,8 +13,6 @@ func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
	}

	sendTopic(dc, ch)

	// TODO: rpl_topicwhotime
	sendNames(dc, ch)
}

@@ -25,6 +25,14 @@ func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
			Command: irc.RPL_TOPIC,
			Params:  []string{dc.nick, downstreamName, ch.Topic},
		})
		if ch.TopicWho != "" {
			topicTime := strconv.FormatInt(ch.TopicTime.Unix(), 10)
			dc.SendMessage(&irc.Message{
				Prefix:  dc.srv.prefix(),
				Command: rpl_topicwhotime,
				Params:  []string{dc.nick, ch.Name, ch.TopicWho, topicTime},
			})
		}
	} else {
		dc.SendMessage(&irc.Message{
			Prefix:  dc.srv.prefix(),
diff --git a/upstream.go b/upstream.go
index b1b8330..4e1d3f5 100644
--- a/upstream.go
+++ b/upstream.go
@@ -825,6 +825,10 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
			ch.Topic = ""
		}
	case "TOPIC":
		if msg.Prefix == nil {
			return fmt.Errorf("expected a prefix")
		}

		var name string
		if err := parseMessageParams(msg, &name); err != nil {
			return err
@@ -835,6 +839,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
		}
		if len(msg.Params) > 1 {
			ch.Topic = msg.Params[1]
			ch.TopicWho = msg.Prefix.Name
			ch.TopicTime = time.Now() // TODO use msg.Tags["time"]
		} else {
			ch.Topic = ""
		}
@@ -966,12 +972,22 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
		if err != nil {
			return err
		}
		firstTopicWhoTime := ch.TopicWho == ""
		ch.TopicWho = who
		sec, err := strconv.ParseInt(timeStr, 10, 64)
		if err != nil {
			return fmt.Errorf("failed to parse topic time: %v", err)
		}
		ch.TopicTime = time.Unix(sec, 0)
		if firstTopicWhoTime {
			uc.forEachDownstream(func(dc *downstreamConn) {
				dc.SendMessage(&irc.Message{
					Prefix:  dc.srv.prefix(),
					Command: rpl_topicwhotime,
					Params:  []string{dc.nick, ch.Name, who, timeStr},
				})
			})
		}
	case irc.RPL_LIST:
		var channel, clients, topic string
		if err := parseMessageParams(msg, nil, &channel, &clients, &topic); err != nil {
--
2.28.0