More tweaks for m.fully_read and /read_markers

This commit is contained in:
Neil Alexander 2022-10-11 11:52:48 +01:00
parent 323227cead
commit d0005384ff
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 25 additions and 25 deletions

View file

@ -154,13 +154,7 @@ func SaveReadMarker(
return *resErr return *resErr
} }
if r.FullyRead == "" { if r.FullyRead != "" {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("Missing m.fully_read mandatory field"),
}
}
data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead}) data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead})
if err != nil { if err != nil {
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
@ -177,11 +171,15 @@ func SaveReadMarker(
util.GetLogger(req.Context()).WithError(err).Error("userAPI.InputAccountData failed") util.GetLogger(req.Context()).WithError(err).Error("userAPI.InputAccountData failed")
return util.ErrorResponse(err) 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 != "" { if r.Read != "" {
return SetReceipt(req, syncProducer, device, roomID, "m.read", 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{ return util.JSONResponse{
Code: http.StatusOK, Code: http.StatusOK,

View file

@ -40,6 +40,7 @@ func SetReceipt(req *http.Request, syncProducer *producers.SyncAPIProducer, devi
switch receiptType { switch receiptType {
case "m.read": case "m.read":
case "m.read.private": case "m.read.private":
case "m.fully_read":
default: default:
return util.MessageResponse(400, fmt.Sprintf("receipt type '%s' not known", receiptType)) return util.MessageResponse(400, fmt.Sprintf("receipt type '%s' not known", receiptType))
} }

View file

@ -84,7 +84,7 @@ func (t *OutputReceiptConsumer) onMessage(ctx context.Context, msgs []*nats.Msg)
switch receipt.Type { switch receipt.Type {
case "m.read": case "m.read":
// These are allowed to be sent over federation // 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 // These must not be sent over federation
return true return true
} }

View file

@ -37,6 +37,7 @@ type AccountData struct {
type ReadMarkerJSON struct { type ReadMarkerJSON struct {
FullyRead string `json:"m.fully_read"` FullyRead string `json:"m.fully_read"`
Read string `json:"m.read"` Read string `json:"m.read"`
ReadPrivate string `json:"m.read.private"`
} }
// NotificationData contains statistics about notifications, sent from // NotificationData contains statistics about notifications, sent from