Implement /createRoom power_level_content_override (#1761)
* Implement /createRoom power_level_content_override * delint * Skip having to re-marshal PowerLevelContentOverride by making use of `json.RawMessage`main
parent
85aaaf9bb9
commit
f448e8972a
|
@ -48,6 +48,7 @@ type createRoomRequest struct {
|
||||||
RoomAliasName string `json:"room_alias_name"`
|
RoomAliasName string `json:"room_alias_name"`
|
||||||
GuestCanJoin bool `json:"guest_can_join"`
|
GuestCanJoin bool `json:"guest_can_join"`
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
|
PowerLevelContentOverride json.RawMessage `json:"power_level_content_override"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -257,6 +258,18 @@ func createRoom(
|
||||||
|
|
||||||
var builtEvents []*gomatrixserverlib.HeaderedEvent
|
var builtEvents []*gomatrixserverlib.HeaderedEvent
|
||||||
|
|
||||||
|
powerLevelContent := eventutil.InitialPowerLevelsContent(userID)
|
||||||
|
if r.PowerLevelContentOverride != nil {
|
||||||
|
// Merge powerLevelContentOverride fields by unmarshalling it atop the defaults
|
||||||
|
err = json.Unmarshal(r.PowerLevelContentOverride, &powerLevelContent)
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.BadJSON("malformed power_level_content_override"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send events into the room in order of:
|
// send events into the room in order of:
|
||||||
// 1- m.room.create
|
// 1- m.room.create
|
||||||
// 2- room creator join member
|
// 2- room creator join member
|
||||||
|
@ -278,7 +291,7 @@ func createRoom(
|
||||||
eventsToMake := []fledglingEvent{
|
eventsToMake := []fledglingEvent{
|
||||||
{"m.room.create", "", r.CreationContent},
|
{"m.room.create", "", r.CreationContent},
|
||||||
{"m.room.member", userID, membershipContent},
|
{"m.room.member", userID, membershipContent},
|
||||||
{"m.room.power_levels", "", eventutil.InitialPowerLevelsContent(userID)},
|
{"m.room.power_levels", "", powerLevelContent},
|
||||||
{"m.room.join_rules", "", gomatrixserverlib.JoinRuleContent{JoinRule: joinRules}},
|
{"m.room.join_rules", "", gomatrixserverlib.JoinRuleContent{JoinRule: joinRules}},
|
||||||
{"m.room.history_visibility", "", eventutil.HistoryVisibilityContent{HistoryVisibility: historyVisibility}},
|
{"m.room.history_visibility", "", eventutil.HistoryVisibilityContent{HistoryVisibility: historyVisibility}},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue