mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-09-07 22:06:19 +00:00
Add createRoom handler
This commit is contained in:
parent
32a1556de1
commit
3c61d0344f
@ -8,6 +8,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/signaller-matrix/signaller/internal/models"
|
||||
@ -542,6 +544,37 @@ func publicRoomsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
sendJsonResponse(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom
|
||||
func createRoomHandler(w http.ResponseWriter, r *http.Request) {
|
||||
token := getTokenFromResponse(r)
|
||||
if token == "" {
|
||||
errorResponse(w, models.M_FORBIDDEN, http.StatusForbidden, "")
|
||||
return
|
||||
}
|
||||
|
||||
user := currServer.Backend.GetUserByToken(token)
|
||||
if user == nil {
|
||||
errorResponse(w, models.M_UNKNOWN_TOKEN, http.StatusBadRequest, "")
|
||||
return
|
||||
}
|
||||
|
||||
var request createroom.Request
|
||||
err := getRequest(r, &request)
|
||||
if err != nil {
|
||||
errorResponse(w, models.M_BAD_JSON, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
room, apiErr := user.CreateRoom(request)
|
||||
if err != nil {
|
||||
errorResponse(w, apiErr, http.StatusBadRequest, apiErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response := createroom.Response{RoomID: room.ID()}
|
||||
sendJsonResponse(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-directory-room-roomalias
|
||||
// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-directory-room-roomalias
|
||||
// https://matrix.org/docs/spec/client_server/latest#delete-matrix-client-r0-directory-room-roomalias
|
||||
|
@ -1,6 +1,6 @@
|
||||
package createroom
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom
|
||||
type Reply struct {
|
||||
type Response struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}
|
@ -36,6 +36,7 @@ func NewServer(port int) (*Server, error) {
|
||||
router.HandleFunc("/_matrix/client/r0/sync", SyncHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/capabilities", CapabilitiesHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/devices", DevicesHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/createRoom", createRoomHandler).Methods(http.MethodPost)
|
||||
router.HandleFunc("/_matrix/client/r0/directory/list/room/{roomID}", listRoomHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/rooms/{roomId}/leave", leaveRoomHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/register/available", registerAvailableHandler)
|
||||
|
Loading…
Reference in New Issue
Block a user