mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +00:00
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>`
This commit is contained in:
parent
af13fa1c75
commit
c7193e24d0
23 changed files with 129 additions and 65 deletions
|
@ -40,8 +40,9 @@ func (f *fedRoomserverAPI) QueryUserIDForSender(ctx context.Context, roomID spec
|
|||
return spec.NewUserID(string(senderID), true)
|
||||
}
|
||||
|
||||
func (f *fedRoomserverAPI) QuerySenderIDForUser(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (spec.SenderID, error) {
|
||||
return spec.SenderID(userID.String()), nil
|
||||
func (f *fedRoomserverAPI) QuerySenderIDForUser(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (*spec.SenderID, error) {
|
||||
senderID := spec.SenderID(userID.String())
|
||||
return &senderID, nil
|
||||
}
|
||||
|
||||
// PerformJoin will call this function
|
||||
|
|
|
@ -481,8 +481,10 @@ func (r *FederationInternalAPI) PerformLeave(
|
|||
senderID, err := r.rsAPI.QuerySenderIDForUser(ctx, *roomID, *userID)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if senderID == nil {
|
||||
return fmt.Errorf("sender ID not found for %s in %s", *userID, *roomID)
|
||||
}
|
||||
senderIDString := string(senderID)
|
||||
senderIDString := string(*senderID)
|
||||
respMakeLeave.LeaveEvent.Type = spec.MRoomMember
|
||||
respMakeLeave.LeaveEvent.SenderID = senderIDString
|
||||
respMakeLeave.LeaveEvent.StateKey = &senderIDString
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue