mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-22 10:22:21 +00:00
Add capabilities method
This commit is contained in:
parent
7293b33b6f
commit
33bb853438
@ -15,4 +15,5 @@ Implemented from [Client-Server API](https://matrix.org/docs/spec/client_server/
|
|||||||
- [x] [5.4.3 POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout)
|
- [x] [5.4.3 POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout)
|
||||||
- [x] [5.4.4 POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout-all)
|
- [x] [5.4.4 POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout-all)
|
||||||
- [x] [5.7.1 GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-account-whoami)
|
- [x] [5.7.1 GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-account-whoami)
|
||||||
|
- [x] [6.1 GET /_matrix/client/r0/capabilities](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-capabilities)
|
||||||
- [x] [10.4.1 GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-joined-rooms)
|
- [x] [10.4.1 GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-joined-rooms)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/nxshock/signaller/internal/models/common"
|
"github.com/nxshock/signaller/internal/models/common"
|
||||||
|
|
||||||
"github.com/nxshock/signaller/internal/models"
|
"github.com/nxshock/signaller/internal/models"
|
||||||
|
"github.com/nxshock/signaller/internal/models/capabilities"
|
||||||
"github.com/nxshock/signaller/internal/models/joinedrooms"
|
"github.com/nxshock/signaller/internal/models/joinedrooms"
|
||||||
login "github.com/nxshock/signaller/internal/models/login"
|
login "github.com/nxshock/signaller/internal/models/login"
|
||||||
register "github.com/nxshock/signaller/internal/models/register"
|
register "github.com/nxshock/signaller/internal/models/register"
|
||||||
@ -224,6 +225,30 @@ func SyncHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
sendJsonResponse(w, http.StatusOK, response)
|
sendJsonResponse(w, http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-capabilities
|
||||||
|
func CapabilitiesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
errorResponse(w, models.M_UNKNOWN, http.StatusBadRequest, "wrong method: "+r.Method)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
token := getTokenFromResponse(r)
|
||||||
|
if token == "" {
|
||||||
|
errorResponse(w, models.M_FORBIDDEN, http.StatusForbidden, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
user := currServer.Backend.GetUserByToken(token)
|
||||||
|
if user == nil {
|
||||||
|
errorResponse(w, models.M_UNKNOWN_TOKEN, http.StatusBadRequest, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var response capabilities.Response
|
||||||
|
response.Capabilities = currServer.Capabilities
|
||||||
|
|
||||||
|
sendJsonResponse(w, http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
func sendJsonResponse(w http.ResponseWriter, httpStatus int, data interface{}) error {
|
func sendJsonResponse(w http.ResponseWriter, httpStatus int, data interface{}) error {
|
||||||
b, err := json.Marshal(data)
|
b, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
27
internal/models/capabilities/capabilities.go
Normal file
27
internal/models/capabilities/capabilities.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package capabilities
|
||||||
|
|
||||||
|
// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-capabilities
|
||||||
|
type Response struct {
|
||||||
|
Capabilities Capabilities `json:"capabilities"` // Required. The custom capabilities the server supports, using the Java package naming convention.
|
||||||
|
}
|
||||||
|
|
||||||
|
type Capabilities struct {
|
||||||
|
ChangePassword ChangePasswordCapability `json:"m.change_password"` // Capability to indicate if the user can change their password.
|
||||||
|
RoomVersions RoomVersionsCapability `json:"m.room_versions"` // The room versions the server supports.
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChangePasswordCapability struct {
|
||||||
|
Enabled bool `json:"enabled"` // Required. True if the user can change their password, false otherwise.
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoomVersionsCapability struct {
|
||||||
|
Default string `json:"default"` // Required. The default room version the server is using for new rooms.
|
||||||
|
Available map[string]Stability `json:"available"` // Required. A detailed description of the room versions the server supports.
|
||||||
|
}
|
||||||
|
|
||||||
|
type Stability string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Stable Stability = "stable"
|
||||||
|
Unstable Stability = "unstable"
|
||||||
|
)
|
@ -4,6 +4,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
|
"github.com/nxshock/signaller/internal/models/capabilities"
|
||||||
)
|
)
|
||||||
|
|
||||||
var currServer *Server
|
var currServer *Server
|
||||||
@ -13,6 +15,8 @@ type Server struct {
|
|||||||
router *mux.Router
|
router *mux.Router
|
||||||
|
|
||||||
Address string
|
Address string
|
||||||
|
|
||||||
|
Capabilities capabilities.Capabilities
|
||||||
Backend Backend
|
Backend Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +30,7 @@ func New() *Server {
|
|||||||
router.HandleFunc("/_matrix/client/r0/account/whoami", WhoAmIHandler)
|
router.HandleFunc("/_matrix/client/r0/account/whoami", WhoAmIHandler)
|
||||||
router.HandleFunc("/_matrix/client/r0/joined_rooms", JoinedRoomsHandler)
|
router.HandleFunc("/_matrix/client/r0/joined_rooms", JoinedRoomsHandler)
|
||||||
router.HandleFunc("/_matrix/client/r0/sync", SyncHandler)
|
router.HandleFunc("/_matrix/client/r0/sync", SyncHandler)
|
||||||
|
router.HandleFunc("/_matrix/client/r0/capabilities", CapabilitiesHandler)
|
||||||
router.HandleFunc("/", RootHandler)
|
router.HandleFunc("/", RootHandler)
|
||||||
|
|
||||||
httpServer := new(http.Server)
|
httpServer := new(http.Server)
|
||||||
|
Loading…
Reference in New Issue
Block a user