Browse Source

Make room names case insensitive by default

pull/374/head
Simon Eisenmann 9 years ago
parent
commit
44402c4e8b
  1. 1
      go/channelling/config.go
  2. 6
      go/channelling/room_manager.go
  3. 1
      go/channelling/server/config.go
  4. 3
      server.conf.in

1
go/channelling/config.go

@ -30,6 +30,7 @@ type Config struct { @@ -30,6 +30,7 @@ type Config struct {
ContentSecurityPolicyReportOnly string `json:"-"` // HTML content security policy in report only mode
RoomTypeDefault string `json:"-"` // New rooms default to this type
RoomTypes map[*regexp.Regexp]string `json:"-"` // Map of regular expression -> room type
RoomNameCaseSensitive bool // Wether the room names are case sensitive.
}
func (config *Config) WithModule(m string) bool {

6
go/channelling/room_manager.go

@ -24,6 +24,7 @@ package channelling @@ -24,6 +24,7 @@ package channelling
import (
"fmt"
"log"
"strings"
"sync"
"github.com/nats-io/nats"
@ -63,6 +64,7 @@ type roomManager struct { @@ -63,6 +64,7 @@ type roomManager struct {
roomTypes map[string]string
globalRoomID string
defaultRoomID string
caseSensitive bool
}
type roomTypeMessage struct {
@ -77,6 +79,7 @@ func NewRoomManager(config *Config, encoder OutgoingEncoder) RoomManager { @@ -77,6 +79,7 @@ func NewRoomManager(config *Config, encoder OutgoingEncoder) RoomManager {
OutgoingEncoder: encoder,
roomTable: make(map[string]RoomWorker),
roomTypes: make(map[string]string),
caseSensitive: config.RoomNameCaseSensitive,
}
if config.GlobalRoomID != "" {
rm.globalRoomID = rm.MakeRoomID(config.GlobalRoomID, "")
@ -264,6 +267,9 @@ func (rooms *roomManager) MakeRoomID(roomName, roomType string) string { @@ -264,6 +267,9 @@ func (rooms *roomManager) MakeRoomID(roomName, roomType string) string {
roomType = rooms.getConfiguredRoomType(roomName)
}
if !rooms.caseSensitive {
roomName = strings.ToLower(roomName)
}
return fmt.Sprintf("%s:%s", roomType, roomName)
}

1
go/channelling/server/config.go

@ -144,6 +144,7 @@ func NewConfig(container phoenix.Container, tokens bool) (*channelling.Config, e @@ -144,6 +144,7 @@ func NewConfig(container phoenix.Container, tokens bool) (*channelling.Config, e
ContentSecurityPolicyReportOnly: container.GetStringDefault("app", "contentSecurityPolicyReportOnly", ""),
RoomTypeDefault: defaultRoomType,
RoomTypes: roomTypes,
RoomNameCaseSensitive: container.GetBoolDefault("app", "caseSensitiveRooms", false),
}, nil
}

3
server.conf.in

@ -82,6 +82,9 @@ encryptionSecret = tne-default-encryption-block-key @@ -82,6 +82,9 @@ encryptionSecret = tne-default-encryption-block-key
; all users will join this room if enabled. If it is disabled then a room join
; form will be shown instead.
;defaultRoomEnabled = true
; Whether the room names are case sensitive. If enabled, different casing
; of room names are different rooms. Optional. Defaults to false.
;caseSensitiveRooms = false
; Whether a user account is required to join a room. This only has an effect
; if user accounts are enabled. Optional, defaults to false.
;authorizeRoomJoin = false

Loading…
Cancel
Save