Take msg ID in sendTargetBacklog

This commit is contained in:
Simon Ser 2021-04-13 17:49:37 +02:00
parent ef902fdc28
commit 65c58adbd9
2 changed files with 24 additions and 27 deletions

View file

@ -986,26 +986,23 @@ func (dc *downstreamConn) welcome() error {
}) })
if firstClient { if firstClient {
net.delivered.ForEachTarget(func(target string) { net.delivered.ForEachTarget(func(target string) {
dc.sendTargetBacklog(net, target) lastDelivered := net.delivered.LoadID(target, dc.clientName)
}) if lastDelivered == "" {
}
// Fast-forward history to last message
net.delivered.ForEachTarget(func(target string) {
ch := net.channels.Value(target)
if ch != nil && ch.Detached {
return return
} }
dc.sendTargetBacklog(net, target, lastDelivered)
// Fast-forward history to last message
targetCM := net.casemap(target) targetCM := net.casemap(target)
lastID, err := dc.user.msgStore.LastMsgID(net, targetCM, time.Now()) lastID, err := dc.user.msgStore.LastMsgID(net, targetCM, time.Now())
if err != nil { if err != nil {
dc.logger.Printf("failed to get last message ID: %v", err) dc.logger.Printf("failed to get last message ID: %v", err)
return return
} }
net.delivered.StoreID(target, dc.clientName, lastID) net.delivered.StoreID(target, dc.clientName, lastID)
}) })
}
}) })
return nil return nil
@ -1025,7 +1022,7 @@ func (dc *downstreamConn) messageSupportsHistory(msg *irc.Message) bool {
return false return false
} }
func (dc *downstreamConn) sendTargetBacklog(net *network, target string) { func (dc *downstreamConn) sendTargetBacklog(net *network, target, msgID string) {
if dc.caps["draft/chathistory"] || dc.user.msgStore == nil { if dc.caps["draft/chathistory"] || dc.user.msgStore == nil {
return return
} }
@ -1033,16 +1030,11 @@ func (dc *downstreamConn) sendTargetBacklog(net *network, target string) {
return return
} }
lastDelivered := net.delivered.LoadID(target, dc.clientName)
if lastDelivered == "" {
return
}
limit := 4000 limit := 4000
targetCM := net.casemap(target) targetCM := net.casemap(target)
history, err := dc.user.msgStore.LoadLatestID(net, targetCM, lastDelivered, limit) history, err := dc.user.msgStore.LoadLatestID(net, targetCM, msgID, 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 backlog for %q: %v", target, err)
return return
} }

View file

@ -276,7 +276,12 @@ func (net *network) attach(ch *Channel) {
forwardChannel(dc, uch) forwardChannel(dc, uch)
} }
dc.sendTargetBacklog(net, ch.Name) lastDelivered := net.delivered.LoadID(ch.Name, dc.clientName)
if lastDelivered == "" {
return
}
dc.sendTargetBacklog(net, ch.Name, lastDelivered)
}) })
} }