mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 22:02:46 +00:00
[pseudoIDs] More pseudo ID fixes - Part 2 (#3181)
Fixes include: - Translating state keys that contain user IDs to their respective room keys for both querying and sending state events - **NOTE**: there may be design discussion needed on what should happen when sender keys cannot be found for users - A simple fix for kicking guests from rooms properly - Logic for boundary history visibilities was slightly off (I'm surprised this only manifested in pseudo ID room versions) Signed-off-by: `Sam Wedgwood <sam@wedgwood.dev>`
This commit is contained in:
parent
a721294e2b
commit
9b5be6b9c5
11 changed files with 865 additions and 36 deletions
|
@ -16,6 +16,8 @@
|
|||
package synctypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
)
|
||||
|
@ -118,3 +120,31 @@ func ToClientEventDefault(userIDQuery spec.UserIDForSender, event gomatrixserver
|
|||
}
|
||||
return ToClientEvent(event, FormatAll, sender, sk)
|
||||
}
|
||||
|
||||
// If provided state key is a user ID (state keys beginning with @ are reserved for this purpose)
|
||||
// fetch it's associated sender ID and use that instead. Otherwise returns the same state key back.
|
||||
//
|
||||
// # This function either returns the state key that should be used, or an error
|
||||
//
|
||||
// TODO: handle failure cases better (e.g. no sender ID)
|
||||
func FromClientStateKey(roomID spec.RoomID, stateKey string, senderIDQuery spec.SenderIDForUser) (*string, error) {
|
||||
if len(stateKey) >= 1 && stateKey[0] == '@' {
|
||||
parsedStateKey, err := spec.NewUserID(stateKey, true)
|
||||
if err != nil {
|
||||
// If invalid user ID, then there is no associated state event.
|
||||
return nil, fmt.Errorf("Provided state key begins with @ but is not a valid user ID: %s", err.Error())
|
||||
}
|
||||
senderID, err := senderIDQuery(roomID, *parsedStateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to query sender ID: %s", err.Error())
|
||||
}
|
||||
if senderID == nil {
|
||||
// If no sender ID, then there is no associated state event.
|
||||
return nil, fmt.Errorf("No associated sender ID found.")
|
||||
}
|
||||
newStateKey := string(*senderID)
|
||||
return &newStateKey, nil
|
||||
} else {
|
||||
return &stateKey, nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue