mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-26 15:08:28 +00:00
Implement room creation content (#754)
Fixes #660. Signed-off-by: Alex Chen minecnly@gmail.com
This commit is contained in:
parent
b729a10366
commit
604685c503
3 changed files with 47 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +176,17 @@ func createRoom(
|
||||||
JSON: jsonerror.InvalidArgumentValue(err.Error()),
|
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
|
// TODO: Create room alias association
|
||||||
// Make sure this doesn't fall into an application service's namespace though!
|
// 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.
|
// 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?
|
// TODO: Synapse has txn/token ID on each event. Do we need to do this here?
|
||||||
eventsToMake := []fledglingEvent{
|
eventsToMake := []fledglingEvent{
|
||||||
{"m.room.create", "", common.CreateContent{Creator: userID}},
|
{"m.room.create", "", r.CreationContent},
|
||||||
{"m.room.member", userID, membershipContent},
|
{"m.room.member", userID, membershipContent},
|
||||||
{"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)},
|
{"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)},
|
||||||
// TODO: m.room.canonical_alias
|
// TODO: m.room.canonical_alias
|
||||||
|
|
|
@ -16,8 +16,16 @@ package common
|
||||||
|
|
||||||
// CreateContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-create
|
// CreateContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-create
|
||||||
type CreateContent struct {
|
type CreateContent struct {
|
||||||
Creator string `json:"creator"`
|
Creator string `json:"creator"`
|
||||||
Federate *bool `json:"m.federate,omitempty"`
|
Federate *bool `json:"m.federate,omitempty"`
|
||||||
|
RoomVersion string `json:"room_version,omitempty"`
|
||||||
|
Predecessor PreviousRoom `json:"predecessor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreviousRoom is the "Previous Room" structure defined at https://matrix.org/docs/spec/client_server/r0.5.0#m-room-create
|
||||||
|
type PreviousRoom struct {
|
||||||
|
RoomID string `json:"room_id"`
|
||||||
|
EventID string `json:"event_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemberContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-member
|
// MemberContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-member
|
||||||
|
|
3
testfile
3
testfile
|
@ -151,3 +151,6 @@ Inbound federation of state requires event_id as a mandatory paramater
|
||||||
Inbound federation of state_ids requires event_id as a mandatory paramater
|
Inbound federation of state_ids requires event_id as a mandatory paramater
|
||||||
POST /register returns the same device_id as that in the request
|
POST /register returns the same device_id as that in the request
|
||||||
POST /login returns the same device_id as that in the request
|
POST /login returns the same device_id as that in the request
|
||||||
|
POST /createRoom with creation content
|
||||||
|
User can create and send/receive messages in a room with version 1
|
||||||
|
POST /createRoom ignores attempts to set the room version via creation_content
|
||||||
|
|
Loading…
Reference in a new issue