aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2023-06-06 20:55:18 +0000
committerGitHub <noreply@github.com>2023-06-06 20:55:18 +0000
commit7a1fd7f512ce06a472a2051ee63eae4a270eb71a (patch)
tree20128b0d3f7c69dd776aa7b2b9bc3194dda7dd75 /clientapi
parent725ff5567d2a3bc9992b065e72ccabefb595ec1c (diff)
PDU Sender split (#3100)
Initial cut of splitting PDU Sender into SenderID & looking up UserID where required.
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/directory.go30
-rw-r--r--clientapi/routing/redaction.go2
-rw-r--r--clientapi/routing/sendevent.go4
-rw-r--r--clientapi/routing/state.go21
4 files changed, 50 insertions, 7 deletions
diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go
index c786f8cc..0c842e6a 100644
--- a/clientapi/routing/directory.go
+++ b/clientapi/routing/directory.go
@@ -215,9 +215,35 @@ func RemoveLocalAlias(
alias string,
rsAPI roomserverAPI.ClientRoomserverAPI,
) util.JSONResponse {
+ userID, err := spec.NewUserID(device.UserID, true)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{Err: "UserID for device is invalid"},
+ }
+ }
+
+ roomIDReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: alias}
+ roomIDRes := roomserverAPI.GetRoomIDForAliasResponse{}
+ err = rsAPI.GetRoomIDForAlias(req.Context(), &roomIDReq, &roomIDRes)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusNotFound,
+ JSON: spec.NotFound("The alias does not exist."),
+ }
+ }
+
+ deviceSenderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomIDRes.RoomID, *userID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{Err: "Could not find SenderID for this device"},
+ }
+ }
+
queryReq := roomserverAPI.RemoveRoomAliasRequest{
- Alias: alias,
- UserID: device.UserID,
+ Alias: alias,
+ SenderID: deviceSenderID,
}
var queryRes roomserverAPI.RemoveRoomAliasResponse
if err := rsAPI.RemoveRoomAlias(req.Context(), &queryReq, &queryRes); err != nil {
diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go
index 88312642..e94c7748 100644
--- a/clientapi/routing/redaction.go
+++ b/clientapi/routing/redaction.go
@@ -76,7 +76,7 @@ func SendRedaction(
// "Users may redact their own events, and any user with a power level greater than or equal
// to the redact power level of the room may redact events there"
// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
- allowedToRedact := ev.Sender() == device.UserID
+ allowedToRedact := ev.SenderID() == device.UserID // TODO: Should replace device.UserID with device...PerRoomKey
if !allowedToRedact {
plEvent := roomserverAPI.GetStateEvent(req.Context(), rsAPI, roomID, gomatrixserverlib.StateKeyTuple{
EventType: spec.MRoomPowerLevels,
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 1a2e25c9..8b09f399 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -331,7 +331,9 @@ func generateSendEvent(
stateEvents[i] = queryRes.StateEvents[i].PDU
}
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
- if err = gomatrixserverlib.Allowed(e.PDU, &provider); err != nil {
+ if err = gomatrixserverlib.Allowed(e.PDU, &provider, func(roomID, senderID string) (*spec.UserID, error) {
+ return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
+ }); err != nil {
return nil, &util.JSONResponse{
Code: http.StatusForbidden,
JSON: spec.Forbidden(err.Error()), // TODO: Is this error string comprehensible to the client?
diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go
index 319f4eba..13f30899 100644
--- a/clientapi/routing/state.go
+++ b/clientapi/routing/state.go
@@ -140,9 +140,14 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
// use the result of the previous QueryLatestEventsAndState response
// to find the state event, if provided.
for _, ev := range stateRes.StateEvents {
+ sender := spec.UserID{}
+ userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
+ if err == nil && userID != nil {
+ sender = *userID
+ }
stateEvents = append(
stateEvents,
- synctypes.ToClientEvent(ev, synctypes.FormatAll),
+ synctypes.ToClientEvent(ev, synctypes.FormatAll, sender),
)
}
} else {
@@ -162,9 +167,14 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
}
}
for _, ev := range stateAfterRes.StateEvents {
+ sender := spec.UserID{}
+ userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
+ if err == nil && userID != nil {
+ sender = *userID
+ }
stateEvents = append(
stateEvents,
- synctypes.ToClientEvent(ev, synctypes.FormatAll),
+ synctypes.ToClientEvent(ev, synctypes.FormatAll, sender),
)
}
}
@@ -334,8 +344,13 @@ func OnIncomingStateTypeRequest(
}
}
+ sender := spec.UserID{}
+ userID, err := rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
+ if err == nil && userID != nil {
+ sender = *userID
+ }
stateEvent := stateEventInStateResp{
- ClientEvent: synctypes.ToClientEvent(event, synctypes.FormatAll),
+ ClientEvent: synctypes.ToClientEvent(event, synctypes.FormatAll, sender),
}
var res interface{}