implement review suggestions

This commit is contained in:
cblgh 2021-04-06 11:29:00 +02:00
parent 75c60dbb16
commit 09eff17712
4 changed files with 8 additions and 9 deletions

View File

@ -2,7 +2,9 @@
-- the configuration settings for this room, currently only privacy modes
CREATE TABLE config (
id integer NOT NULL PRIMARY KEY,
privacyMode integer NOT NULL -- open, community, restricted
privacyMode integer NOT NULL, -- open, community, restricted
CHECK (id == 0) -- should only ever store one row
);
-- the config table will only ever contain one row: the rooms current settings
@ -12,3 +14,6 @@ INSERT INTO config (id, privacyMode) VALUES (
0, -- the constant id we will query
1 -- community is the default mode unless overridden
);
-- +migrate Down
DROP TABLE config;

View File

@ -12,9 +12,6 @@ import (
"github.com/volatiletech/sqlboiler/v4/boil"
)
// cblgh: ask cryptix about the details of the syntax of the "compiler assertion" below
// why two parens? this does not look like a typical type assertion? e.g. <var>.(type)
// hm-maybe this is a type conversion, forcing "nil" to be a *Aliases?
var _ roomdb.RoomConfig = (*Config)(nil)
// the database will only ever store one row, which contains all the room settings
@ -27,8 +24,6 @@ type Config struct {
db *sql.DB
}
// cblgh questions:
// * is storing the entire config in a single row really ugly? ._.
func (c Config) GetPrivacyMode(ctx context.Context) (roomdb.PrivacyMode, error) {
config, err := models.FindConfig(ctx, c.db, configRowID)
if err != nil {
@ -46,7 +41,6 @@ func (c Config) GetPrivacyMode(ctx context.Context) (roomdb.PrivacyMode, error)
}
func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error {
fmt.Println("setting privacy mode!!")
// make sure the privacy mode is an ok value
err := pm.IsValid()
if err != nil {

View File

@ -70,7 +70,7 @@ type Server struct {
authWithSSB roomdb.AuthWithSSBService
authWithSSBBridge *signinwithssb.SignalBridge
Config roomdb.RoomConfig
Config roomdb.RoomConfig
}
func (s Server) Whoami() refs.FeedRef {

View File

@ -44,7 +44,7 @@ var HTMLTemplates = []string{
// Databases is an option struct that encapsualtes the required database services
type Databases struct {
Aliases roomdb.AliasesService
Config roomdb.RoomConfig // cblgh: kind of confusing that we have two identically named structs, in different http handler contexts?
Config roomdb.RoomConfig
DeniedKeys roomdb.DeniedKeysService
Invites roomdb.InvitesService
Notices roomdb.NoticesService