mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +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
|
@ -283,7 +283,7 @@ func (r *Queryer) QueryMembershipForUser(
|
|||
return err
|
||||
}
|
||||
|
||||
return r.QueryMembershipForSenderID(ctx, *roomID, senderID, response)
|
||||
return r.QueryMembershipForSenderID(ctx, *roomID, *senderID, response)
|
||||
}
|
||||
|
||||
// QueryMembershipAtEvent returns the known memberships at a given event.
|
||||
|
@ -1009,21 +1009,26 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, roomID spec.Ro
|
|||
return verImpl.CheckRestrictedJoin(ctx, r.Cfg.Global.ServerName, &api.JoinRoomQuerier{Roomserver: r}, roomID, senderID)
|
||||
}
|
||||
|
||||
func (r *Queryer) QuerySenderIDForUser(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (spec.SenderID, error) {
|
||||
func (r *Queryer) QuerySenderIDForUser(ctx context.Context, roomID spec.RoomID, userID spec.UserID) (*spec.SenderID, error) {
|
||||
version, err := r.DB.GetRoomVersion(ctx, roomID.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch version {
|
||||
case gomatrixserverlib.RoomVersionPseudoIDs:
|
||||
key, err := r.DB.SelectUserRoomPublicKey(ctx, userID, roomID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
} else if key == nil {
|
||||
return nil, nil
|
||||
} else {
|
||||
senderID := spec.SenderID(spec.Base64Bytes(key).Encode())
|
||||
return &senderID, nil
|
||||
}
|
||||
return spec.SenderID(spec.Base64Bytes(key).Encode()), nil
|
||||
default:
|
||||
return spec.SenderID(userID.String()), nil
|
||||
senderID := spec.SenderID(userID.String())
|
||||
return &senderID, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue