2022-07-24 02:40:44 +02:00
|
|
|
package matrix
|
|
|
|
|
2022-07-24 21:50:26 +02:00
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"maunium.net/go/mautrix/id"
|
|
|
|
)
|
2022-07-24 02:40:44 +02:00
|
|
|
|
|
|
|
func makeUserID(userIdentifier, homeserverURL string) (id.UserID, error) {
|
|
|
|
userID := id.UserID(userIdentifier)
|
|
|
|
localpart, _, err := userID.Parse()
|
|
|
|
if err != nil {
|
2022-07-24 21:50:26 +02:00
|
|
|
url, err := url.Parse(homeserverURL)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
userID = id.NewUserID(userIdentifier, url.Host)
|
2022-07-24 02:40:44 +02:00
|
|
|
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
|
|
|
|
}
|