mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
Move redacts to the client API, which should satisfy clients and
federation
This commit is contained in:
parent
ab2c24c742
commit
2738d429be
|
|
@ -34,7 +34,8 @@ import (
|
|||
)
|
||||
|
||||
type redactionContent struct {
|
||||
Reason string `json:"reason"`
|
||||
Reason string `json:"reason"`
|
||||
Redacts string `json:"redacts"`
|
||||
}
|
||||
|
||||
type redactionResponse struct {
|
||||
|
|
@ -151,6 +152,11 @@ func SendRedaction(
|
|||
Type: spec.MRoomRedaction,
|
||||
Redacts: eventID,
|
||||
}
|
||||
|
||||
// Room version 11 expects the "redacts" field on the
|
||||
// content field, so add it here as well
|
||||
r.Redacts = eventID
|
||||
|
||||
err = proto.SetContent(r)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("proto.SetContent failed")
|
||||
|
|
|
|||
|
|
@ -141,18 +141,6 @@ func ToClientEvent(se gomatrixserverlib.PDU, format ClientEventFormat, userIDFor
|
|||
Redacts: se.Redacts(),
|
||||
}
|
||||
|
||||
// RoomVersion V11 moved the "redacts" field to "content", so add it there as well
|
||||
// For compatibility with older clients, we keep the "redacts" top-level field.
|
||||
// TODO: At which point do we remove "redacts" from the top-level?
|
||||
if se.Type() == spec.MRoomRedaction && se.Version() == gomatrixserverlib.RoomVersionV11 && ce.Redacts != "" {
|
||||
v11content, err := sjson.SetBytes(ce.Content, "redacts", ce.Redacts)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warn("failed to set content.redacts")
|
||||
} else {
|
||||
ce.Content = v11content
|
||||
}
|
||||
}
|
||||
|
||||
switch format {
|
||||
case FormatAll:
|
||||
ce.RoomID = se.RoomID().String()
|
||||
|
|
|
|||
|
|
@ -154,50 +154,6 @@ func TestToClientEvent(t *testing.T) { // nolint: gocyclo
|
|||
}
|
||||
}
|
||||
|
||||
// Merely tests that the top-level "redacts" is copied to "content.redacts" and keeps the top-level
|
||||
// one as is
|
||||
func TestToClientEventRedactionV11(t *testing.T) { // nolint: gocyclo
|
||||
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV11).NewEventFromTrustedJSON([]byte(`{
|
||||
"type": "m.room.redaction",
|
||||
"state_key": "",
|
||||
"event_id": "$test",
|
||||
"room_id": "!test:localhost",
|
||||
"sender": "@test:localhost",
|
||||
"content": {
|
||||
"reason": "Hello World"
|
||||
},
|
||||
"origin_server_ts": 123456,
|
||||
"unsigned": {
|
||||
"prev_content": {
|
||||
"name": "Goodbye World"
|
||||
}
|
||||
},
|
||||
"redacts": "$abc"
|
||||
}`), false)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create Event: %s", err)
|
||||
}
|
||||
|
||||
ce, err := ToClientEvent(ev, FormatAll, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return queryUserIDForSender(senderID)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create ClientEvent: %s", err)
|
||||
}
|
||||
|
||||
j, err := json.Marshal(ce)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to Marshal ClientEvent: %s", err)
|
||||
}
|
||||
// Marshal sorts keys in structs by the order they are defined in the struct, which is alphabetical
|
||||
out := `{"content":{"reason":"Hello World","redacts":"$abc"},"event_id":"$test","origin_server_ts":123456,` +
|
||||
`"room_id":"!test:localhost","sender":"@test:localhost","state_key":"","type":"m.room.redaction",` +
|
||||
`"unsigned":{"prev_content":{"name":"Goodbye World"}},"redacts":"$abc"}`
|
||||
if !bytes.Equal([]byte(out), j) {
|
||||
t.Errorf("ClientEvent marshalled to wrong bytes: wanted \n%s, got \n%s", out, string(j))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToClientFormatSync(t *testing.T) {
|
||||
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV1).NewEventFromTrustedJSON([]byte(`{
|
||||
"type": "m.room.name",
|
||||
|
|
|
|||
Loading…
Reference in a new issue