aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/createroom.go
diff options
context:
space:
mode:
Diffstat (limited to 'clientapi/routing/createroom.go')
-rw-r--r--clientapi/routing/createroom.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go
index 220ba6ae..8c5ee975 100644
--- a/clientapi/routing/createroom.go
+++ b/clientapi/routing/createroom.go
@@ -15,6 +15,7 @@
package routing
import (
+ "encoding/json"
"fmt"
"net/http"
"strings"
@@ -97,6 +98,27 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
}
}
+ // Validate creation_content fields defined in the spec by marshalling the
+ // creation_content map into bytes and then unmarshalling the bytes into
+ // common.CreateContent.
+
+ creationContentBytes, err := json.Marshal(r.CreationContent)
+ if err != nil {
+ return &util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: jsonerror.BadJSON("malformed creation_content"),
+ }
+ }
+
+ var CreationContent common.CreateContent
+ err = json.Unmarshal(creationContentBytes, &CreationContent)
+ if err != nil {
+ return &util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: jsonerror.BadJSON("malformed creation_content"),
+ }
+ }
+
return nil
}
@@ -154,7 +176,17 @@ func createRoom(
JSON: jsonerror.InvalidArgumentValue(err.Error()),
}
}
- // TODO: visibility/presets/raw initial state/creation content
+
+ // Clobber keys: creator, room_version
+
+ if r.CreationContent == nil {
+ r.CreationContent = make(map[string]interface{}, 2)
+ }
+
+ r.CreationContent["creator"] = userID
+ r.CreationContent["room_version"] = "1" // TODO: We set this to 1 before we support Room versioning
+
+ // TODO: visibility/presets/raw initial state
// TODO: Create room alias association
// Make sure this doesn't fall into an application service's namespace though!
@@ -214,7 +246,7 @@ func createRoom(
// harder to reason about, hence sticking to a strict static ordering.
// TODO: Synapse has txn/token ID on each event. Do we need to do this here?
eventsToMake := []fledglingEvent{
- {"m.room.create", "", common.CreateContent{Creator: userID}},
+ {"m.room.create", "", r.CreationContent},
{"m.room.member", userID, membershipContent},
{"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)},
// TODO: m.room.canonical_alias