Changeset 260 in code for trunk/downstream.go
- Timestamp:
- Apr 16, 2020, 3:19:00 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r259 r260 122 122 } 123 123 124 func isOurNick(net *network, nick string) bool { 125 // TODO: this doesn't account for nick changes 126 if net.conn != nil { 127 return nick == net.conn.nick 128 } 129 // We're not currently connected to the upstream connection, so we don't 130 // know whether this name is our nickname. Best-effort: use the network's 131 // configured nickname and hope it was the one being used when we were 132 // connected. 133 return nick == net.Nick 134 } 135 124 136 // marshalEntity converts an upstream entity name (ie. channel or nick) into a 125 137 // downstream entity name. … … 127 139 // This involves adding a "/<network>" suffix if the entity isn't the current 128 140 // user. 129 func (dc *downstreamConn) marshalEntity( uc *upstreamConn, name string) string {141 func (dc *downstreamConn) marshalEntity(net *network, name string) string { 130 142 if dc.network != nil { 131 if dc.network != uc.network{143 if dc.network != net { 132 144 panic("soju: tried to marshal an entity for another network") 133 145 } 134 146 return name 135 147 } 136 if name == uc.nick{148 if isOurNick(net, name) { 137 149 return dc.nick 138 150 } 139 return name + "/" + uc.network.GetName()140 } 141 142 func (dc *downstreamConn) marshalUserPrefix( uc *upstreamConn, prefix *irc.Prefix) *irc.Prefix {143 if prefix.Name == uc.nick{151 return name + "/" + net.GetName() 152 } 153 154 func (dc *downstreamConn) marshalUserPrefix(net *network, prefix *irc.Prefix) *irc.Prefix { 155 if isOurNick(net, prefix.Name) { 144 156 return dc.prefix() 145 157 } 146 158 if dc.network != nil { 147 if dc.network != uc.network{159 if dc.network != net { 148 160 panic("soju: tried to marshal a user prefix for another network") 149 161 } … … 151 163 } 152 164 return &irc.Prefix{ 153 Name: prefix.Name + "/" + uc.network.GetName(),165 Name: prefix.Name + "/" + net.GetName(), 154 166 User: prefix.User, 155 167 Host: prefix.Host, … … 229 241 func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *irc.Message { 230 242 msg = msg.Copy() 231 msg.Prefix = dc.marshalUserPrefix(uc , msg.Prefix)243 msg.Prefix = dc.marshalUserPrefix(uc.network, msg.Prefix) 232 244 233 245 switch msg.Command { 234 246 case "PRIVMSG", "NOTICE": 235 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])247 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 236 248 case "NICK": 237 249 // Nick change for another user 238 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])250 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 239 251 case "JOIN", "PART": 240 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])252 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 241 253 case "KICK": 242 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])243 msg.Params[1] = dc.marshalEntity(uc , msg.Params[1])254 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 255 msg.Params[1] = dc.marshalEntity(uc.network, msg.Params[1]) 244 256 case "TOPIC": 245 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])257 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 246 258 case "MODE": 247 msg.Params[0] = dc.marshalEntity(uc , msg.Params[0])259 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0]) 248 260 case "QUIT": 249 261 // This space is intentinally left blank … … 663 675 Prefix: dc.prefix(), 664 676 Command: "JOIN", 665 Params: []string{dc.marshalEntity(ch.conn , ch.Name)},677 Params: []string{dc.marshalEntity(ch.conn.network, ch.Name)}, 666 678 }) 667 679 … … 714 726 Prefix: dc.srv.prefix(), 715 727 Command: "BATCH", 716 Params: []string{"+" + batchRef, "chathistory", dc.marshalEntity( uc, target)},728 Params: []string{"+" + batchRef, "chathistory", dc.marshalEntity(net, target)}, 717 729 }) 718 730 }
Note:
See TracChangeset
for help on using the changeset viewer.