From d0005384ff581d36e6f01ed3dfe3e9871c727a8c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 11 Oct 2022 11:52:48 +0100 Subject: [PATCH] More tweaks for `m.fully_read` and `/read_markers` --- clientapi/routing/account_data.go | 42 ++++++++++++++--------------- clientapi/routing/receipt.go | 1 + federationapi/consumers/receipts.go | 2 +- internal/eventutil/types.go | 5 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/clientapi/routing/account_data.go b/clientapi/routing/account_data.go index b28f0bb1f..1642f6f95 100644 --- a/clientapi/routing/account_data.go +++ b/clientapi/routing/account_data.go @@ -154,34 +154,32 @@ func SaveReadMarker( return *resErr } - if r.FullyRead == "" { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.BadJSON("Missing m.fully_read mandatory field"), + if r.FullyRead != "" { + data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead}) + if err != nil { + return jsonerror.InternalServerError() + } + + dataReq := api.InputAccountDataRequest{ + UserID: device.UserID, + DataType: "m.fully_read", + RoomID: roomID, + AccountData: data, + } + dataRes := api.InputAccountDataResponse{} + if err := userAPI.InputAccountData(req.Context(), &dataReq, &dataRes); err != nil { + util.GetLogger(req.Context()).WithError(err).Error("userAPI.InputAccountData failed") + return util.ErrorResponse(err) } } - data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead}) - if err != nil { - return jsonerror.InternalServerError() - } - - dataReq := api.InputAccountDataRequest{ - UserID: device.UserID, - DataType: "m.fully_read", - RoomID: roomID, - AccountData: data, - } - dataRes := api.InputAccountDataResponse{} - if err := userAPI.InputAccountData(req.Context(), &dataReq, &dataRes); err != nil { - util.GetLogger(req.Context()).WithError(err).Error("userAPI.InputAccountData failed") - return util.ErrorResponse(err) - } - - // Handle the read receipt that may be included in the read marker + // Handle the read receipts that may be included in the read marker. if r.Read != "" { return SetReceipt(req, syncProducer, device, roomID, "m.read", r.Read) } + if r.ReadPrivate != "" { + return SetReceipt(req, syncProducer, device, roomID, "m.read.private", r.ReadPrivate) + } return util.JSONResponse{ Code: http.StatusOK, diff --git a/clientapi/routing/receipt.go b/clientapi/routing/receipt.go index b70d85a17..54351a7e6 100644 --- a/clientapi/routing/receipt.go +++ b/clientapi/routing/receipt.go @@ -40,6 +40,7 @@ func SetReceipt(req *http.Request, syncProducer *producers.SyncAPIProducer, devi switch receiptType { case "m.read": case "m.read.private": + case "m.fully_read": default: return util.MessageResponse(400, fmt.Sprintf("receipt type '%s' not known", receiptType)) } diff --git a/federationapi/consumers/receipts.go b/federationapi/consumers/receipts.go index 268ca626e..75827cb68 100644 --- a/federationapi/consumers/receipts.go +++ b/federationapi/consumers/receipts.go @@ -84,7 +84,7 @@ func (t *OutputReceiptConsumer) onMessage(ctx context.Context, msgs []*nats.Msg) switch receipt.Type { case "m.read": // These are allowed to be sent over federation - case "m.read.private": + case "m.read.private", "m.fully_read": // These must not be sent over federation return true } diff --git a/internal/eventutil/types.go b/internal/eventutil/types.go index afc62d8c2..18175d6a0 100644 --- a/internal/eventutil/types.go +++ b/internal/eventutil/types.go @@ -35,8 +35,9 @@ type AccountData struct { } type ReadMarkerJSON struct { - FullyRead string `json:"m.fully_read"` - Read string `json:"m.read"` + FullyRead string `json:"m.fully_read"` + Read string `json:"m.read"` + ReadPrivate string `json:"m.read.private"` } // NotificationData contains statistics about notifications, sent from