mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
implemented mapping v1
This commit is contained in:
parent
24fa42dcae
commit
b3da7cfc1a
|
|
@ -3,9 +3,11 @@ package routing
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// represents response to an AppService URI to User Id
|
// URIToUIDResponse represents response to an AppService URI to User Id
|
||||||
// (/_matrix/app/r0/user?uri={url_encoded_uri}) request
|
// (/_matrix/app/r0/user?uri={url_encoded_uri}) request
|
||||||
type URIToUIDResponse struct {
|
type URIToUIDResponse struct {
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
|
|
@ -15,9 +17,9 @@ type URIToUIDResponse struct {
|
||||||
// enables users to contact appservice users directly by taking an encoded
|
// enables users to contact appservice users directly by taking an encoded
|
||||||
// URI and turning it into a Matrix ID on the homeserver.
|
// URI and turning it into a Matrix ID on the homeserver.
|
||||||
// https://matrix.org/docs/spec/application_service/unstable.html#user-ids
|
// https://matrix.org/docs/spec/application_service/unstable.html#user-ids
|
||||||
|
// tel://123.1234 -> @tel_//123.1234:matrix.org
|
||||||
|
// mailto:test@matrix.org -> @mailto_test_matrix.org:matrix.org
|
||||||
func URIToUID(req *http.Request, cfg config.Dendrite) util.JSONResponse {
|
func URIToUID(req *http.Request, cfg config.Dendrite) util.JSONResponse {
|
||||||
// TODO: Implement
|
|
||||||
homeserver := cfg.Matrix.ServerName
|
homeserver := cfg.Matrix.ServerName
|
||||||
uri := req.URL.Query().Get("uri")
|
uri := req.URL.Query().Get("uri")
|
||||||
if uri == "" {
|
if uri == "" {
|
||||||
|
|
@ -26,8 +28,25 @@ func URIToUID(req *http.Request, cfg config.Dendrite) util.JSONResponse {
|
||||||
JSON: nil,
|
JSON: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// V1 just replaces the illegal characters (from
|
||||||
|
// https://matrix.org/docs/spec/appendices.html#id12) with _
|
||||||
|
// TODO: Come up with a better way to turn URIs into User IDs
|
||||||
|
w := strings.FieldsFunc(strings.ToLower(uri), func(r rune) bool {
|
||||||
|
if unicode.IsDigit(r) || unicode.IsLetter(r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch r {
|
||||||
|
case '.', '_', '=', '-', '/':
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
// compile user ID and return
|
||||||
|
userID := "@" + strings.Join(w, "_") + ":" + homeserver
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: nil,
|
JSON: URIToUIDResponse{UserID: userID},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue