aboutsummaryrefslogtreecommitdiff
path: root/federationapi/routing
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 /federationapi/routing
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 'federationapi/routing')
-rw-r--r--federationapi/routing/join.go7
-rw-r--r--federationapi/routing/leave.go8
2 files changed, 12 insertions, 3 deletions
diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go
index a090dbc8..ce7ad30f 100644
--- a/federationapi/routing/join.go
+++ b/federationapi/routing/join.go
@@ -99,7 +99,7 @@ func MakeJoin(
Roomserver: rsAPI,
}
- senderID, err := rsAPI.QuerySenderIDForUser(httpReq.Context(), roomID, userID)
+ senderIDPtr, err := rsAPI.QuerySenderIDForUser(httpReq.Context(), roomID, userID)
if err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QuerySenderIDForUser failed")
return util.JSONResponse{
@@ -108,8 +108,11 @@ func MakeJoin(
}
}
- if senderID == "" {
+ var senderID spec.SenderID
+ if senderIDPtr == nil {
senderID = spec.SenderID(userID.String())
+ } else {
+ senderID = *senderIDPtr
}
input := gomatrixserverlib.HandleMakeJoinInput{
diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go
index 5c8dd00f..f28c8211 100644
--- a/federationapi/routing/leave.go
+++ b/federationapi/routing/leave.go
@@ -94,11 +94,17 @@ func MakeLeave(
Code: http.StatusInternalServerError,
JSON: spec.InternalServerError{},
}
+ } else if senderID == nil {
+ util.GetLogger(httpReq.Context()).WithField("roomID", roomID).WithField("userID", userID).Error("rsAPI.QuerySenderIDForUser returned nil sender ID")
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
input := gomatrixserverlib.HandleMakeLeaveInput{
UserID: userID,
- SenderID: senderID,
+ SenderID: *senderID,
RoomID: roomID,
RoomVersion: roomVersion,
RequestOrigin: request.Origin(),