source: code/trunk/bridge.go@ 347

Last change on this file since 347 was 346, checked in by hubert, 5 years ago

Send compact channel name lists

This commit resolves sendNames' TODO.

File size: 1.9 KB
RevLine 
[98]1package soju
[32]2
3import (
4 "gopkg.in/irc.v3"
[346]5 "strings"
[32]6)
7
8func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
9 if !ch.complete {
10 panic("Tried to forward a partial channel")
11 }
12
[160]13 sendTopic(dc, ch)
14
15 // TODO: rpl_topicwhotime
16 sendNames(dc, ch)
17}
18
19func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
[260]20 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[69]21
[32]22 if ch.Topic != "" {
[54]23 dc.SendMessage(&irc.Message{
[32]24 Prefix: dc.srv.prefix(),
25 Command: irc.RPL_TOPIC,
[69]26 Params: []string{dc.nick, downstreamName, ch.Topic},
[54]27 })
[32]28 } else {
[54]29 dc.SendMessage(&irc.Message{
[32]30 Prefix: dc.srv.prefix(),
31 Command: irc.RPL_NOTOPIC,
[69]32 Params: []string{dc.nick, downstreamName, "No topic is set"},
[54]33 })
[32]34 }
[140]35}
[32]36
[140]37func sendNames(dc *downstreamConn, ch *upstreamChannel) {
[260]38 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[140]39
[346]40 emptyNameReply := &irc.Message{
41 Prefix: dc.srv.prefix(),
42 Command: irc.RPL_NAMREPLY,
43 Params: []string{dc.nick, string(ch.Status), downstreamName, ""},
44 }
45 maxLength := maxMessageLength - len(emptyNameReply.String())
46
47 var buf strings.Builder
[292]48 for nick, memberships := range ch.Members {
49 s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
[32]50
[346]51 if buf.Len() != 0 && maxLength < buf.Len()+1+len(s) {
52 // There's not enough space for the next space + nick.
53 dc.SendMessage(&irc.Message{
54 Prefix: dc.srv.prefix(),
55 Command: irc.RPL_NAMREPLY,
56 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
57 })
58 buf.Reset()
59 }
60
61 if buf.Len() != 0 {
62 buf.WriteByte(' ')
63 }
64 buf.WriteString(s)
65 }
66
67 if buf.Len() != 0 {
[54]68 dc.SendMessage(&irc.Message{
[32]69 Prefix: dc.srv.prefix(),
70 Command: irc.RPL_NAMREPLY,
[346]71 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
[54]72 })
[32]73 }
74
[54]75 dc.SendMessage(&irc.Message{
[32]76 Prefix: dc.srv.prefix(),
77 Command: irc.RPL_ENDOFNAMES,
[69]78 Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
[54]79 })
[32]80}
Note: See TracBrowser for help on using the repository browser.