Fix linter warnings

This commit is contained in:
Crom (Thibaut CHARLES) 2017-12-14 11:07:22 +01:00
parent 139f133605
commit 55ba1da1b3
No known key found for this signature in database
GPG key ID: 45A3D5F880B9E6D0

View file

@ -47,6 +47,25 @@ type createRoomRequest struct {
GuestCanJoin bool `json:"guest_can_join"` GuestCanJoin bool `json:"guest_can_join"`
} }
const (
presetPrivateChat = "private_chat"
presetTrustedPrivateChat = "trusted_private_chat"
presetPublicChat = "public_chat"
)
const (
joinRulePublic = "public"
// joinRuleCanJoin = "can_join"
joinRuleInvite = "invite"
// joinRuleKnock = "knock"
// joinRulePrivate = "private"
)
const (
historyVisibilityShared = "shared"
// historyVisibilityWorldReadable = "world_readable"
// historyVisibilityInvited = "invited"
)
func (r createRoomRequest) Validate() *util.JSONResponse { func (r createRoomRequest) Validate() *util.JSONResponse {
whitespace := "\t\n\x0b\x0c\r " // https://docs.python.org/2/library/string.html#string.whitespace whitespace := "\t\n\x0b\x0c\r " // https://docs.python.org/2/library/string.html#string.whitespace
// https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/handlers/room.py#L81 // https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/handlers/room.py#L81
@ -71,7 +90,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
} }
} }
switch r.Preset { switch r.Preset {
case "private_chat", "trusted_private_chat", "public_chat": case presetPrivateChat, presetTrustedPrivateChat, presetPublicChat:
break break
default: default:
return &util.JSONResponse{ return &util.JSONResponse{
@ -153,16 +172,16 @@ func createRoom(req *http.Request, device *authtypes.Device,
var joinRules, historyVisibility string var joinRules, historyVisibility string
switch r.Preset { switch r.Preset {
case "private_chat": case presetPrivateChat:
joinRules = "invite" joinRules = joinRuleInvite
historyVisibility = "shared" historyVisibility = historyVisibilityShared
case "trusted_private_chat": case presetTrustedPrivateChat:
joinRules = "invite" joinRules = joinRuleInvite
historyVisibility = "shared" historyVisibility = historyVisibilityShared
// TODO If trusted_private_chat, all invitees are given the same power level as the room creator. // TODO If trusted_private_chat, all invitees are given the same power level as the room creator.
case "public_chat": case presetPublicChat:
joinRules = "public" joinRules = joinRulePublic
historyVisibility = "shared" historyVisibility = historyVisibilityShared
} }
var builtEvents []gomatrixserverlib.Event var builtEvents []gomatrixserverlib.Event
@ -196,9 +215,7 @@ func createRoom(req *http.Request, device *authtypes.Device,
if r.GuestCanJoin { if r.GuestCanJoin {
eventsToMake = append(eventsToMake, fledglingEvent{"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}}) eventsToMake = append(eventsToMake, fledglingEvent{"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}})
} }
for _, initStateEv := range r.InitialState { eventsToMake = append(eventsToMake, r.InitialState...)
eventsToMake = append(eventsToMake, initStateEv)
}
if r.Name != "" { if r.Name != "" {
eventsToMake = append(eventsToMake, fledglingEvent{"m.room.name", "", common.NameContent{Name: r.Name}}) eventsToMake = append(eventsToMake, fledglingEvent{"m.room.name", "", common.NameContent{Name: r.Name}})
} }