1 | package soju
|
---|
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 |
|
---|
12 | sendTopic(dc, ch)
|
---|
13 |
|
---|
14 | // TODO: rpl_topicwhotime
|
---|
15 | sendNames(dc, ch)
|
---|
16 | }
|
---|
17 |
|
---|
18 | func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
|
---|
19 | downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
|
---|
20 |
|
---|
21 | if ch.Topic != "" {
|
---|
22 | dc.SendMessage(&irc.Message{
|
---|
23 | Prefix: dc.srv.prefix(),
|
---|
24 | Command: irc.RPL_TOPIC,
|
---|
25 | Params: []string{dc.nick, downstreamName, ch.Topic},
|
---|
26 | })
|
---|
27 | } else {
|
---|
28 | dc.SendMessage(&irc.Message{
|
---|
29 | Prefix: dc.srv.prefix(),
|
---|
30 | Command: irc.RPL_NOTOPIC,
|
---|
31 | Params: []string{dc.nick, downstreamName, "No topic is set"},
|
---|
32 | })
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | func sendNames(dc *downstreamConn, ch *upstreamChannel) {
|
---|
37 | // TODO: send multiple members in each message
|
---|
38 |
|
---|
39 | downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
|
---|
40 |
|
---|
41 | for nick, membership := range ch.Members {
|
---|
42 | s := membership.String() + dc.marshalEntity(ch.conn.network, nick)
|
---|
43 |
|
---|
44 | dc.SendMessage(&irc.Message{
|
---|
45 | Prefix: dc.srv.prefix(),
|
---|
46 | Command: irc.RPL_NAMREPLY,
|
---|
47 | Params: []string{dc.nick, string(ch.Status), downstreamName, s},
|
---|
48 | })
|
---|
49 | }
|
---|
50 |
|
---|
51 | dc.SendMessage(&irc.Message{
|
---|
52 | Prefix: dc.srv.prefix(),
|
---|
53 | Command: irc.RPL_ENDOFNAMES,
|
---|
54 | Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
|
---|
55 | })
|
---|
56 | }
|
---|