mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Add support for weird user ID templates when generating registration
Fixes #492
This commit is contained in:
parent
a4f57d175c
commit
b6ec252fcd
1 changed files with 12 additions and 4 deletions
|
@ -19,6 +19,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/appservice"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +37,9 @@ func (config *Config) NewRegistration() (*appservice.Registration, error) {
|
||||||
|
|
||||||
// Workaround for https://github.com/matrix-org/synapse/pull/5758
|
// Workaround for https://github.com/matrix-org/synapse/pull/5758
|
||||||
registration.SenderLocalpart = appservice.RandomString(32)
|
registration.SenderLocalpart = appservice.RandomString(32)
|
||||||
botRegex := regexp.MustCompile(fmt.Sprintf("^@%s:%s$", config.AppService.Bot.Username, config.Homeserver.Domain))
|
botRegex := regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
||||||
|
regexp.QuoteMeta(config.AppService.Bot.Username),
|
||||||
|
regexp.QuoteMeta(config.Homeserver.Domain)))
|
||||||
registration.Namespaces.RegisterUserIDs(botRegex, true)
|
registration.Namespaces.RegisterUserIDs(botRegex, true)
|
||||||
|
|
||||||
return registration, nil
|
return registration, nil
|
||||||
|
@ -63,9 +66,14 @@ func (config *Config) copyToRegistration(registration *appservice.Registration)
|
||||||
registration.SenderLocalpart = config.AppService.Bot.Username
|
registration.SenderLocalpart = config.AppService.Bot.Username
|
||||||
registration.EphemeralEvents = config.AppService.EphemeralEvents
|
registration.EphemeralEvents = config.AppService.EphemeralEvents
|
||||||
|
|
||||||
userIDRegex, err := regexp.Compile(fmt.Sprintf("^@%s:%s$",
|
usernamePlaceholder := appservice.RandomString(16)
|
||||||
config.Bridge.FormatUsername("[0-9]+"),
|
usernameTemplate := fmt.Sprintf("@%s:%s",
|
||||||
config.Homeserver.Domain))
|
config.Bridge.FormatUsername(usernamePlaceholder),
|
||||||
|
config.Homeserver.Domain)
|
||||||
|
usernameTemplate = regexp.QuoteMeta(usernameTemplate)
|
||||||
|
usernameTemplate = strings.Replace(usernameTemplate, usernamePlaceholder, "[0-9]+", 1)
|
||||||
|
usernameTemplate = fmt.Sprintf("^%s$", usernameTemplate)
|
||||||
|
userIDRegex, err := regexp.Compile(usernameTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue