aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/sendevent.go
diff options
context:
space:
mode:
authorSam Wedgwood <28223854+swedgwood@users.noreply.github.com>2023-08-02 11:12:14 +0100
committerGitHub <noreply@github.com>2023-08-02 11:12:14 +0100
commitc7193e24d06a549b2e4a3bfca2d6e0f6c62d5f80 (patch)
tree19a1284c9d66385618f2f28b1308bb0934744a38 /clientapi/routing/sendevent.go
parentaf13fa1c7554fbed802d51421163f81b5b3fbe0d (diff)
Use `*spec.SenderID` for `QuerySenderIDForUser` (#3164)
There are cases where a dendrite instance is unaware of a pseudo ID for a user, the user is not a member of that room. To represent this case, we currently use the 'zero' value, which is often not checked and so causes errors later down the line. To make this case more explict, and to be consistent with `QueryUserIDForSender`, this PR changes this to use a pointer (and `nil` to mean no sender ID). Signed-off-by: `Sam Wedgwood <sam@wedgwood.dev>`
Diffstat (limited to 'clientapi/routing/sendevent.go')
-rw-r--r--clientapi/routing/sendevent.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 41a3793a..17200171 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -251,8 +251,10 @@ func updatePowerLevels(req *http.Request, r map[string]interface{}, roomID strin
senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *uID)
if err != nil {
return err
+ } else if senderID == nil {
+ return fmt.Errorf("sender ID not found for %s in %s", uID, *validRoomID)
}
- userMap[string(senderID)] = level
+ userMap[string(*senderID)] = level
delete(userMap, user)
}
r["users"] = userMap
@@ -314,7 +316,7 @@ func generateSendEvent(
}
}
senderID, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *fullUserID)
- if err != nil {
+ if err != nil || senderID == nil {
return nil, &util.JSONResponse{
Code: http.StatusNotFound,
JSON: spec.NotFound("Unable to find senderID for user"),
@@ -323,7 +325,7 @@ func generateSendEvent(
// create the new event and set all the fields we can
proto := gomatrixserverlib.ProtoEvent{
- SenderID: string(senderID),
+ SenderID: string(*senderID),
RoomID: roomID,
Type: eventType,
StateKey: stateKey,