From 3b6e17536544c221b70ffb0e0c234e40013e1cc1 Mon Sep 17 00:00:00 2001 From: delthas Date: Thu, 26 Mar 2020 05:51:47 +0100 Subject: [PATCH] Add upstream RPL_CREATIONTIME support --- downstream.go | 7 +++++++ irc.go | 1 + upstream.go | 41 ++++++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/downstream.go b/downstream.go index a3accbc..fa8f6fb 100644 --- a/downstream.go +++ b/downstream.go @@ -1031,6 +1031,13 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { Command: irc.RPL_CHANNELMODEIS, Params: params, }) + if ch.creationTime != "" { + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: rpl_creationtime, + Params: []string{dc.nick, name, ch.creationTime}, + }) + } } case "TOPIC": var channel string diff --git a/irc.go b/irc.go index 1ea6ed7..77d9fef 100644 --- a/irc.go +++ b/irc.go @@ -11,6 +11,7 @@ const ( rpl_statsping = "246" rpl_localusers = "265" rpl_globalusers = "266" + rpl_creationtime = "329" rpl_topicwhotime = "333" err_invalidcapcmd = "410" ) diff --git a/upstream.go b/upstream.go index c8104a5..d6684d8 100644 --- a/upstream.go +++ b/upstream.go @@ -16,15 +16,16 @@ import ( ) type upstreamChannel struct { - Name string - conn *upstreamConn - Topic string - TopicWho string - TopicTime time.Time - Status channelStatus - modes channelModes - Members map[string]*membership - complete bool + Name string + conn *upstreamConn + Topic string + TopicWho string + TopicTime time.Time + Status channelStatus + modes channelModes + creationTime string + Members map[string]*membership + complete bool } type upstreamConn struct { @@ -763,6 +764,28 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { }) }) } + case rpl_creationtime: + var channel, creationTime string + if err := parseMessageParams(msg, nil, &channel, &creationTime); err != nil { + return err + } + + ch, err := uc.getChannel(channel) + if err != nil { + return err + } + + firstCreationTime := ch.creationTime == "" + ch.creationTime = creationTime + if firstCreationTime { + uc.forEachDownstream(func(dc *downstreamConn) { + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: rpl_creationtime, + Params: []string{dc.nick, channel, creationTime}, + }) + }) + } case rpl_topicwhotime: var name, who, timeStr string if err := parseMessageParams(msg, nil, &name, &who, &timeStr); err != nil {