aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-05-02 15:03:16 +0100
committerGitHub <noreply@github.com>2023-05-02 15:03:16 +0100
commitf5b3144dc33ddcb2ab161323d422cab257d04b4c (patch)
tree07d3b03944d2529d96c29674a96c3e76a76ae3b9 /clientapi/routing
parent696cbb70b8cc8d663f7bb7c7a5f25cd57ea6803e (diff)
Use PDU not *Event in HeaderedEvent (#3073)
Requires https://github.com/matrix-org/gomatrixserverlib/pull/376 This has numerous upsides: - Less type casting to `*Event` is required. - Making Dendrite work with `PDU` interfaces means we can swap out Event impls more easily. - Tests which represent weird event shapes are easier to write. Part of a series of refactors on GMSL.
Diffstat (limited to 'clientapi/routing')
-rw-r--r--clientapi/routing/aliases.go6
-rw-r--r--clientapi/routing/createroom.go6
-rw-r--r--clientapi/routing/directory.go2
-rw-r--r--clientapi/routing/sendevent.go12
-rw-r--r--clientapi/routing/server_notices.go2
5 files changed, 15 insertions, 13 deletions
diff --git a/clientapi/routing/aliases.go b/clientapi/routing/aliases.go
index 90621daf..5c2df79d 100644
--- a/clientapi/routing/aliases.go
+++ b/clientapi/routing/aliases.go
@@ -15,6 +15,7 @@
package routing
import (
+ "encoding/json"
"fmt"
"net/http"
@@ -48,11 +49,12 @@ func GetAliases(
visibility := gomatrixserverlib.HistoryVisibilityInvited
if historyVisEvent, ok := stateRes.StateEvents[stateTuple]; ok {
var err error
- visibility, err = historyVisEvent.HistoryVisibility()
- if err != nil {
+ var content gomatrixserverlib.HistoryVisibilityContent
+ if err = json.Unmarshal(historyVisEvent.Content(), &content); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("historyVisEvent.HistoryVisibility failed")
return util.ErrorResponse(fmt.Errorf("historyVisEvent.HistoryVisibility: %w", err))
}
+ visibility = content.HistoryVisibility
}
if visibility != spec.WorldReadable {
queryReq := api.QueryMembershipForUserRequest{
diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go
index 518daece..a64a735f 100644
--- a/clientapi/routing/createroom.go
+++ b/clientapi/routing/createroom.go
@@ -466,7 +466,7 @@ func createRoom(
}
// Add the event to the list of auth events
- builtEvents = append(builtEvents, &types.HeaderedEvent{Event: ev})
+ builtEvents = append(builtEvents, &types.HeaderedEvent{PDU: ev})
err = authEvents.AddEvent(ev)
if err != nil {
util.GetLogger(ctx).WithError(err).Error("authEvents.AddEvent failed")
@@ -536,7 +536,7 @@ func createRoom(
case spec.MRoomMember:
fallthrough
case spec.MRoomJoinRules:
- ev := event.Event
+ ev := event.PDU
globalStrippedState = append(
globalStrippedState,
fclient.NewInviteV2StrippedState(ev),
@@ -558,7 +558,7 @@ func createRoom(
}
inviteStrippedState := append(
globalStrippedState,
- fclient.NewInviteV2StrippedState(inviteEvent.Event),
+ fclient.NewInviteV2StrippedState(inviteEvent.PDU),
)
// Send the invite event to the roomserver.
event := inviteEvent
diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go
index a8bf019b..11ae5739 100644
--- a/clientapi/routing/directory.go
+++ b/clientapi/routing/directory.go
@@ -291,7 +291,7 @@ func SetVisibility(
}
// NOTSPEC: Check if the user's power is greater than power required to change m.room.canonical_alias event
- power, _ := gomatrixserverlib.NewPowerLevelContentFromEvent(queryEventsRes.StateEvents[0].Event)
+ power, _ := gomatrixserverlib.NewPowerLevelContentFromEvent(queryEventsRes.StateEvents[0].PDU)
if power.UserLevel(dev.UserID) < power.EventLevel(spec.MRoomCanonicalAlias, true) {
return util.JSONResponse{
Code: http.StatusForbidden,
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 0d01367d..2d22d801 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -185,7 +185,7 @@ func SendEvent(
req.Context(), rsAPI,
api.KindNew,
[]*types.HeaderedEvent{
- &types.HeaderedEvent{Event: e},
+ &types.HeaderedEvent{PDU: e},
},
device.UserDomain(),
domain,
@@ -259,7 +259,7 @@ func generateSendEvent(
cfg *config.ClientAPI,
rsAPI api.ClientRoomserverAPI,
evTime time.Time,
-) (*gomatrixserverlib.Event, *util.JSONResponse) {
+) (gomatrixserverlib.PDU, *util.JSONResponse) {
// parse the incoming http request
userID := device.UserID
@@ -313,12 +313,12 @@ func generateSendEvent(
}
// check to see if this user can perform this operation
- stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
+ stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
for i := range queryRes.StateEvents {
- stateEvents[i] = queryRes.StateEvents[i].Event
+ stateEvents[i] = queryRes.StateEvents[i].PDU
}
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
- if err = gomatrixserverlib.Allowed(e.Event, &provider); err != nil {
+ if err = gomatrixserverlib.Allowed(e.PDU, &provider); err != nil {
return nil, &util.JSONResponse{
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden(err.Error()), // TODO: Is this error string comprehensible to the client?
@@ -343,5 +343,5 @@ func generateSendEvent(
}
}
- return e.Event, nil
+ return e.PDU, nil
}
diff --git a/clientapi/routing/server_notices.go b/clientapi/routing/server_notices.go
index c556ed26..a9967adf 100644
--- a/clientapi/routing/server_notices.go
+++ b/clientapi/routing/server_notices.go
@@ -228,7 +228,7 @@ func SendServerNotice(
ctx, rsAPI,
api.KindNew,
[]*types.HeaderedEvent{
- &types.HeaderedEvent{Event: e},
+ &types.HeaderedEvent{PDU: e},
},
device.UserDomain(),
cfgClient.Matrix.ServerName,