Set defaults if no preset. Use switch instead of if

This commit is contained in:
Andrew Morgan 2018-06-14 11:15:27 +01:00
parent 7d246f906a
commit f1e1e39499

View file

@ -87,15 +87,12 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
} }
} }
} }
if r.Preset != "" { switch r.Preset {
switch r.Preset { case presetPrivateChat, presetTrustedPrivateChat, presetPublicChat, "":
case presetPrivateChat, presetTrustedPrivateChat, presetPublicChat: default:
break return &util.JSONResponse{
default: Code: http.StatusBadRequest,
return &util.JSONResponse{ JSON: jsonerror.BadJSON("preset must be any of 'private_chat', 'trusted_private_chat', 'public_chat'"),
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("preset must be any of 'private_chat', 'trusted_private_chat', 'public_chat'"),
}
} }
} }
@ -172,7 +169,7 @@ func createRoom(req *http.Request, device *authtypes.Device,
var joinRules, historyVisibility string var joinRules, historyVisibility string
switch r.Preset { switch r.Preset {
case presetPrivateChat: case presetPrivateChat, "":
joinRules = joinRuleInvite joinRules = joinRuleInvite
historyVisibility = historyVisibilityShared historyVisibility = historyVisibilityShared
case presetTrustedPrivateChat: case presetTrustedPrivateChat: