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
}
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,

View file

@ -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))
}

View file

@ -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
}

View file

@ -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