aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-29 10:51:09 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-29 10:51:09 +0100
commit2649e41c85283c680b9e1aa3294868b985aecc22 (patch)
tree67a37cd6044f217e9be5fe217efaf86d040f06bc /util.go
parent38a3f1bdb18159cc4808fa86280da55f0599dcc8 (diff)
downloadeasybridge-2649e41c85283c680b9e1aa3294868b985aecc22.tar.gz
easybridge-2649e41c85283c680b9e1aa3294868b985aecc22.zip
Allow _ezbr_ to be put in suffix of usernames/room aliases instead of prefix
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 {