Use clientName to decide whether or not history should be sent

Closes: https://todo.sr.ht/~emersion/soju/31
This commit is contained in:
Simon Ser 2020-03-28 17:36:09 +01:00
parent 6ff26e6640
commit b1fd943ad6
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -687,7 +687,14 @@ func (dc *downstreamConn) welcome() error {
return err return err
} }
firstDownstream := len(dc.user.downstreamConns) == 0 // Only send history if we're the first connected client with that name and
// network
sendHistory := true
dc.user.forEachDownstream(func(conn *downstreamConn) {
if dc.clientName == conn.clientName && dc.network == conn.network {
sendHistory = false
}
})
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
@ -731,9 +738,7 @@ func (dc *downstreamConn) welcome() error {
}) })
dc.forEachNetwork(func(net *network) { dc.forEachNetwork(func(net *network) {
// TODO: need to take dc.network into account when deciding whether or dc.runNetwork(net, sendHistory)
// not to load history
dc.runNetwork(net, firstDownstream)
}) })
return nil return nil
@ -748,12 +753,10 @@ func (dc *downstreamConn) runNetwork(net *network, loadHistory bool) {
panic("network not suitable for downstream connection") panic("network not suitable for downstream connection")
} }
historyName := dc.rawUsername
var seqPtr *uint64 var seqPtr *uint64
if loadHistory { if loadHistory {
net.lock.Lock() net.lock.Lock()
seq, ok := net.history[historyName] seq, ok := net.history[dc.clientName]
net.lock.Unlock() net.lock.Unlock()
if ok { if ok {
seqPtr = &seq seqPtr = &seq
@ -780,10 +783,12 @@ func (dc *downstreamConn) runNetwork(net *network, loadHistory bool) {
} }
} }
// TODO: close the consumer from the user goroutine, so we don't need
// that net.history lock
seq := consumer.Close() seq := consumer.Close()
net.lock.Lock() net.lock.Lock()
net.history[historyName] = seq net.history[dc.clientName] = seq
net.lock.Unlock() net.lock.Unlock()
}() }()
} }