aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util.go')
-rw-r--r--util.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/util.go b/util.go
index 5d86b8a..4e23bb1 100644
--- a/util.go
+++ b/util.go
@@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
+ "strings"
"unicode"
log "github.com/sirupsen/logrus"
@@ -58,11 +59,13 @@ func ezbrSystemSendf(user_mx_id string, format string, args ...interface{}) {
// ----
func roomAlias(protocol string, id RoomID) string {
- return fmt.Sprintf("%s_%s__%s", registration.SenderLocalpart, safeStringForId(string(id)), protocol)
+ what := fmt.Sprintf("%s_%s", safeStringForId(string(id)), protocol)
+ return strings.Replace(config.NameFormat, "{}", what, 1)
}
func userMxId(protocol string, id UserID) string {
- return fmt.Sprintf("%s_%s__%s", registration.SenderLocalpart, safeStringForId(string(id)), protocol)
+ what := fmt.Sprintf("%s_%s", safeStringForId(string(id)), protocol)
+ return strings.Replace(config.NameFormat, "{}", what, 1)
}
func safeStringForId(in string) string {
@@ -79,6 +82,28 @@ func safeStringForId(in string) string {
return id2
}
+func isBridgedIdentifier(mxid string) bool {
+ if mxid[0] == '@' || mxid[0] == '#' {
+ return isBridgedIdentifier(mxid[1:])
+ }
+
+ if strings.Contains(mxid, ":") {
+ sp := strings.Split(mxid, ":")
+ return (sp[1] == config.MatrixDomain) && isBridgedIdentifier(sp[0])
+ }
+
+ nameformat_fixed_part := strings.Replace(config.NameFormat, "{}", "", 1)
+ if strings.HasPrefix(config.NameFormat, "{}") {
+ return strings.HasSuffix(mxid, nameformat_fixed_part)
+ } else if strings.HasSuffix(config.NameFormat, "{}") {
+ return strings.HasPrefix(mxid, nameformat_fixed_part)
+ } else {
+ // This is not supported
+ log.Fatal("Invalid name format %s, please put {} at the beginning or at the end", config.NameFormat)
+ return false
+ }
+}
+
// ---- Encoding and encryption of account config
func encryptAccountConfig(config map[string]string, key *[32]byte) string {