Introduce downstreamConn.sendTargetBacklog

This commit is contained in:
Simon Ser 2021-02-10 13:48:41 +01:00
parent 7e39f6d663
commit 26473ed60d

View File

@ -979,24 +979,32 @@ func (dc *downstreamConn) messageSupportsHistory(msg *irc.Message) bool {
} }
func (dc *downstreamConn) sendNetworkBacklog(net *network) { func (dc *downstreamConn) sendNetworkBacklog(net *network) {
for target := range net.delivered {
dc.sendTargetBacklog(net, target)
}
}
func (dc *downstreamConn) sendTargetBacklog(net *network, target string) {
if dc.caps["draft/chathistory"] || dc.user.msgStore == nil { if dc.caps["draft/chathistory"] || dc.user.msgStore == nil {
return return
} }
for target, delivered := range net.delivered {
if ch, ok := net.channels[target]; ok && ch.Detached { if ch, ok := net.channels[target]; ok && ch.Detached {
continue return
}
delivered, ok := net.delivered[target]
if !ok {
return
} }
lastDelivered, ok := delivered[dc.clientName] lastDelivered, ok := delivered[dc.clientName]
if !ok { if !ok {
continue return
} }
limit := 4000 limit := 4000
history, err := dc.user.msgStore.LoadLatestID(net, target, lastDelivered, limit) history, err := dc.user.msgStore.LoadLatestID(net, target, lastDelivered, limit)
if err != nil { if err != nil {
dc.logger.Printf("failed to send implicit history for %q: %v", target, err) dc.logger.Printf("failed to send implicit history for %q: %v", target, err)
continue return
} }
batchRef := "history" batchRef := "history"
@ -1027,7 +1035,6 @@ func (dc *downstreamConn) sendNetworkBacklog(net *network) {
}) })
} }
} }
}
func (dc *downstreamConn) runUntilRegistered() error { func (dc *downstreamConn) runUntilRegistered() error {
for !dc.registered { for !dc.registered {