matrix msc3575 support

This commit is contained in:
Amarpreet Minhas 2024-02-11 21:27:05 -05:00
parent 277c713e7e
commit 393d8f1422
2 changed files with 29 additions and 25 deletions

View file

@ -13,6 +13,7 @@ type (
LogLevel string
MatrixIdentityServer string
MatrixWellKnownAddress string
MatrixMsc3575Address string
NostrAddrFee string
}
)
@ -26,6 +27,7 @@ func GetConfig() Config {
LogLevel: getEnv("LOG_LEVEL", "INFO"),
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
MatrixMsc3575Address: getEnv("MATRIX_MSC3575_ADDRESS", ""),
NostrAddrFee: getEnv("NOSTR_ADDR_FEE", "0"),
}
}

View file

@ -21,9 +21,14 @@ type matrixIdentityServer struct {
BaseUrl string `json:"base_url,omitempty"`
}
type msc3575address struct {
Url string `json:"url,omitempty"`
}
type matrixClientWellKnown struct {
HomeServer *matrixBaseUrl `json:"m.homeserver"`
Homeserver *matrixBaseUrl `json:"m.homeserver"`
IdentityServer *matrixIdentityServer `json:"m.identity_server,omitempty"`
Msc3575 *msc3575address `json:"org.matrix.msc3575.proxy,omitempty"`
}
func MatrixServer(w http.ResponseWriter, req *http.Request) {
@ -46,36 +51,33 @@ func MatrixServer(w http.ResponseWriter, req *http.Request) {
func MatrixClient(w http.ResponseWriter, req *http.Request) {
l := logger.Get()
// uses an environment variable for now
m := &matrixClientWellKnown{}
wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
// no matrix config set
if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound)
l.Debug().Str("path", "matrix/client").Msg("matrix well known address unset")
return
}
m.Homeserver = &matrixBaseUrl{
BaseUrl: fmt.Sprintf("https://%s", wellKnownAddr),
}
identityServer := config.GetConfig().MatrixIdentityServer
if identityServer == "" {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
baseUrl := &matrixClientWellKnown{
HomeServer: &matrixBaseUrl{
BaseUrl: fmt.Sprintf("https://%s", wellKnownAddr),
},
}
json.NewEncoder(w).Encode(baseUrl)
} else {
identityServer = fmt.Sprintf("https://%s", identityServer)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
baseUrl := &matrixClientWellKnown{
HomeServer: &matrixBaseUrl{
BaseUrl: fmt.Sprintf("https://%s", wellKnownAddr),
},
IdentityServer: &matrixIdentityServer{
if identityServer != "" {
m.IdentityServer = &matrixIdentityServer{
BaseUrl: identityServer,
},
}
json.NewEncoder(w).Encode(baseUrl)
}
msc3575 := config.GetConfig().MatrixMsc3575Address
if msc3575 != "" {
m.Msc3575 = &msc3575address{
Url: msc3575,
}
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(m)
}