Extract host part from homeserver url

This commit is contained in:
Luca 2022-07-24 21:50:26 +02:00
parent 03e1e564f6
commit ff6a07e592
1 changed files with 11 additions and 2 deletions

View File

@ -1,12 +1,21 @@
package matrix package matrix
import "maunium.net/go/mautrix/id" import (
"net/url"
"maunium.net/go/mautrix/id"
)
func makeUserID(userIdentifier, homeserverURL string) (id.UserID, error) { func makeUserID(userIdentifier, homeserverURL string) (id.UserID, error) {
userID := id.UserID(userIdentifier) userID := id.UserID(userIdentifier)
localpart, _, err := userID.Parse() localpart, _, err := userID.Parse()
if err != nil { if err != nil {
userID = id.NewUserID(userIdentifier, homeserverURL) url, err := url.Parse(homeserverURL)
if err != nil {
return "", err
}
userID = id.NewUserID(userIdentifier, url.Host)
if _, _, err := userID.ParseAndValidate(); err != nil { if _, _, err := userID.ParseAndValidate(); err != nil {
return "", err return "", err
} }