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

View File

@ -276,7 +276,12 @@ func (net *network) attach(ch *Channel) {
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)
})
}