matrix-pretix/internal/matrix/user_id.go

21 lines
543 B
Go
Raw Normal View History

2022-07-24 02:40:44 +02:00
package matrix
import "maunium.net/go/mautrix/id"
func makeUserID(userIdentifier, homeserverURL string) (id.UserID, error) {
userID := id.UserID(userIdentifier)
localpart, _, err := userID.Parse()
if err != nil {
userID = id.NewUserID(userIdentifier, homeserverURL)
if _, _, err := userID.ParseAndValidate(); err != nil {
return "", err
}
} else if err := id.ValidateUserLocalpart(localpart); err != nil {
return "", err
} else if len(userID) > id.UserIDMaxLength {
return "", id.ErrUserIDTooLong
}
return userID, nil
}