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,34 +154,32 @@ func SaveReadMarker(
return *resErr return *resErr
} }
if r.FullyRead == "" { if r.FullyRead != "" {
return util.JSONResponse{ data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead})
Code: http.StatusBadRequest, if err != nil {
JSON: jsonerror.BadJSON("Missing m.fully_read mandatory field"), 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}) // Handle the read receipts that may be included in the read marker.
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
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

@ -35,8 +35,9 @@ 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