bridgev2/provisionutil: allow mxids as participants in CreateGroup

This commit is contained in:
Tulir Asokan 2025-10-21 16:59:18 +03:00
commit 36edccf61a
2 changed files with 8 additions and 2 deletions

View file

@ -817,7 +817,8 @@ type GroupFieldCapability struct {
type GroupCreateParams struct {
Type string `json:"type,omitempty"`
Username string `json:"username,omitempty"`
Username string `json:"username,omitempty"`
// Clients may also provide MXIDs here, but provisionutil will normalize them, so bridges only need to handle network IDs
Participants []networkid.UserID `json:"participants,omitempty"`
Parent *networkid.PortalKey `json:"parent,omitempty"`

View file

@ -38,7 +38,12 @@ func CreateGroup(ctx context.Context, login *bridgev2.UserLogin, params *bridgev
return nil, bridgev2.RespError(mautrix.MInvalidParam.WithMessage("Must have at least %d members", typeSpec.Participants.MinLength))
}
userIDValidatingNetwork, uidValOK := login.Bridge.Network.(bridgev2.IdentifierValidatingNetwork)
for _, participant := range params.Participants {
for i, participant := range params.Participants {
parsedParticipant, ok := login.Bridge.Matrix.ParseGhostMXID(id.UserID(participant))
if ok {
participant = parsedParticipant
params.Participants[i] = participant
}
if uidValOK && !userIDValidatingNetwork.ValidateUserID(participant) {
return nil, bridgev2.RespError(mautrix.MInvalidParam.WithMessage("User ID %q is not valid on this network", participant))
}