From 9376c8885ce0d4fb37116c93e06740e92142c532 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 8 Mar 2022 22:32:45 +0100 Subject: [PATCH] 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. --- downstream.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/downstream.go b/downstream.go index dea242a..0a2852f 100644 --- a/downstream.go +++ b/downstream.go @@ -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}, }) } })