soju/bridge.go
delthas 732b581eb2
Add support for multiple user channel memberships
User channel memberships are actually a set of memberships, not a single
value. This introduces memberships, a type representing a set of
memberships, stored as an array of memberships ordered by descending
rank.

This also adds multi-prefix to the permanent downstream and upstream
capabilities, so that we try to get all possible channel memberships.
2020-05-11 12:25:49 +02:00

57 lines
1.3 KiB
Go

package soju
import (
"gopkg.in/irc.v3"
)
func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
if !ch.complete {
panic("Tried to forward a partial channel")
}
sendTopic(dc, ch)
// TODO: rpl_topicwhotime
sendNames(dc, ch)
}
func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
if ch.Topic != "" {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_TOPIC,
Params: []string{dc.nick, downstreamName, ch.Topic},
})
} else {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_NOTOPIC,
Params: []string{dc.nick, downstreamName, "No topic is set"},
})
}
}
func sendNames(dc *downstreamConn, ch *upstreamChannel) {
// TODO: send multiple members in each message
downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
for nick, memberships := range ch.Members {
s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_NAMREPLY,
Params: []string{dc.nick, string(ch.Status), downstreamName, s},
})
}
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFNAMES,
Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
})
}