From 323227ceade1d69b66a5aebf713ba6431e840b32 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 11 Oct 2022 11:42:57 +0100 Subject: [PATCH] Implement behaviours for `m.read.private` receipts --- clientapi/routing/receipt.go | 8 +++++--- federationapi/consumers/receipts.go | 8 ++++++++ syncapi/streams/stream_receipt.go | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clientapi/routing/receipt.go b/clientapi/routing/receipt.go index 0f9b1b4ff..b70d85a17 100644 --- a/clientapi/routing/receipt.go +++ b/clientapi/routing/receipt.go @@ -37,9 +37,11 @@ func SetReceipt(req *http.Request, syncProducer *producers.SyncAPIProducer, devi "timestamp": timestamp, }).Debug("Setting receipt") - // currently only m.read is accepted - if receiptType != "m.read" { - return util.MessageResponse(400, fmt.Sprintf("receipt type must be m.read not '%s'", receiptType)) + switch receiptType { + case "m.read": + case "m.read.private": + default: + return util.MessageResponse(400, fmt.Sprintf("receipt type '%s' not known", receiptType)) } if err := syncProducer.SendReceipt(req.Context(), device.UserID, roomID, eventID, receiptType, timestamp); err != nil { diff --git a/federationapi/consumers/receipts.go b/federationapi/consumers/receipts.go index 366cb264e..268ca626e 100644 --- a/federationapi/consumers/receipts.go +++ b/federationapi/consumers/receipts.go @@ -81,6 +81,14 @@ func (t *OutputReceiptConsumer) onMessage(ctx context.Context, msgs []*nats.Msg) Type: msg.Header.Get("type"), } + switch receipt.Type { + case "m.read": + // These are allowed to be sent over federation + case "m.read.private": + // These must not be sent over federation + return true + } + // only send receipt events which originated from us _, receiptServerName, err := gomatrixserverlib.SplitID('@', receipt.UserID) if err != nil { diff --git a/syncapi/streams/stream_receipt.go b/syncapi/streams/stream_receipt.go index bba911022..977815078 100644 --- a/syncapi/streams/stream_receipt.go +++ b/syncapi/streams/stream_receipt.go @@ -67,6 +67,10 @@ func (p *ReceiptStreamProvider) IncrementalSync( if _, ok := req.IgnoredUsers.List[receipt.UserID]; ok { continue } + // Don't send private read receipts to other users + if receipt.Type == "m.read.private" && req.Device.UserID != receipt.UserID { + continue + } receiptsByRoom[receipt.RoomID] = append(receiptsByRoom[receipt.RoomID], receipt) }