[98] | 1 | package soju
|
---|
[32] | 2 |
|
---|
| 3 | import (
|
---|
| 4 | "gopkg.in/irc.v3"
|
---|
| 5 | )
|
---|
| 6 |
|
---|
| 7 | func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
|
---|
| 8 | if !ch.complete {
|
---|
| 9 | panic("Tried to forward a partial channel")
|
---|
| 10 | }
|
---|
| 11 |
|
---|
[160] | 12 | sendTopic(dc, ch)
|
---|
| 13 |
|
---|
| 14 | // TODO: rpl_topicwhotime
|
---|
| 15 | sendNames(dc, ch)
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
|
---|
[260] | 19 | downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
|
---|
[69] | 20 |
|
---|
[32] | 21 | if ch.Topic != "" {
|
---|
[54] | 22 | dc.SendMessage(&irc.Message{
|
---|
[32] | 23 | Prefix: dc.srv.prefix(),
|
---|
| 24 | Command: irc.RPL_TOPIC,
|
---|
[69] | 25 | Params: []string{dc.nick, downstreamName, ch.Topic},
|
---|
[54] | 26 | })
|
---|
[32] | 27 | } else {
|
---|
[54] | 28 | dc.SendMessage(&irc.Message{
|
---|
[32] | 29 | Prefix: dc.srv.prefix(),
|
---|
| 30 | Command: irc.RPL_NOTOPIC,
|
---|
[69] | 31 | Params: []string{dc.nick, downstreamName, "No topic is set"},
|
---|
[54] | 32 | })
|
---|
[32] | 33 | }
|
---|
[140] | 34 | }
|
---|
[32] | 35 |
|
---|
[140] | 36 | func sendNames(dc *downstreamConn, ch *upstreamChannel) {
|
---|
[32] | 37 | // TODO: send multiple members in each message
|
---|
[140] | 38 |
|
---|
[260] | 39 | downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
|
---|
[140] | 40 |
|
---|
[292] | 41 | for nick, memberships := range ch.Members {
|
---|
| 42 | s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
|
---|
[32] | 43 |
|
---|
[54] | 44 | dc.SendMessage(&irc.Message{
|
---|
[32] | 45 | Prefix: dc.srv.prefix(),
|
---|
| 46 | Command: irc.RPL_NAMREPLY,
|
---|
[69] | 47 | Params: []string{dc.nick, string(ch.Status), downstreamName, s},
|
---|
[54] | 48 | })
|
---|
[32] | 49 | }
|
---|
| 50 |
|
---|
[54] | 51 | dc.SendMessage(&irc.Message{
|
---|
[32] | 52 | Prefix: dc.srv.prefix(),
|
---|
| 53 | Command: irc.RPL_ENDOFNAMES,
|
---|
[69] | 54 | Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
|
---|
[54] | 55 | })
|
---|
[32] | 56 | }
|
---|