downstream: Enable handling READ when upstream is disconnected

Previously, when we sent READ for an upstream which was disconnected,
we would fail with an error. This is because we called unmarshalEntity,
which checked that the upstream was in the connected status.

But we don't need to be connected to update the READ timestamp, this is
a purely offline (wrt the upstream) operation.

This simply switches the call from unmarshalEntity to
unmarshalEntityNetwork to fix the issue.
This commit is contained in:
delthas 2022-03-08 22:32:45 +01:00 committed by Simon Ser
parent fdf9727600
commit 9376c8885c

View File

@ -2812,13 +2812,13 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
return nil
}
uc, entity, err := dc.unmarshalEntity(target)
network, entity, err := dc.unmarshalEntityNetwork(target)
if err != nil {
return err
}
entityCM := uc.network.casemap(entity)
entityCM := network.casemap(entity)
r, err := dc.srv.db.GetReadReceipt(ctx, uc.network.ID, entityCM)
r, err := dc.srv.db.GetReadReceipt(ctx, network.ID, entityCM)
if err != nil {
dc.logger.Printf("failed to get the read receipt for %q: %v", entity, err)
return ircError{&irc.Message{
@ -2855,7 +2855,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
}
if r.Timestamp.Before(timestamp) {
r.Timestamp = timestamp
if err := dc.srv.db.StoreReadReceipt(ctx, uc.network.ID, r); err != nil {
if err := dc.srv.db.StoreReadReceipt(ctx, network.ID, r); err != nil {
dc.logger.Printf("failed to store receipt for %q: %v", entity, err)
return ircError{&irc.Message{
Command: "FAIL",
@ -2870,12 +2870,12 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
if !r.Timestamp.IsZero() {
timestampStr = fmt.Sprintf("timestamp=%s", formatServerTime(r.Timestamp))
}
uc.forEachDownstream(func(d *downstreamConn) {
network.forEachDownstream(func(d *downstreamConn) {
if broadcast || dc.id == d.id {
d.SendMessage(&irc.Message{
Prefix: d.prefix(),
Command: "READ",
Params: []string{d.marshalEntity(uc.network, entity), timestampStr},
Params: []string{d.marshalEntity(network, entity), timestampStr},
})
}
})