Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Mar 31, 2021
1 parent 0b0b567 commit dc37554
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func initFlags() {

flag.BoolVar(&flagPrintVersion, "version", false, "print version number and build date")

/* cblgh: TODO change this to use a db.Config.SetPrivacyMode function; guessing database is not loaded yet tho.
* maybe we remove this flag entirely / replace with a small cli tool? idk*/
/* cblgh: TODO change this to use a db.Config.SetPrivacyMode function; guessing database is not loaded yet tho.
* maybe we remove this flag entirely / replace with a small cli tool? idk*/
flag.Func("mode", "the privacy mode (values: open, community, restricted) determining room access controls", func(val string) error {
privacyMode := roomdb.ParsePrivacyMode(val)
err := privacyMode.IsValid()
Expand Down
39 changes: 21 additions & 18 deletions roomdb/sqlite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,39 @@ import (
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models"
)

// 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.AliasesService = (*Aliases)(nil)

// the database will only ever store one row, which contains all the room settings
const configRowID = 0

type Config struct {
db *sql.DB
db *sql.DB
}

/* cblgh:
* okay so i guess what we want to do here is basically enable some long-term memory for the server when it comes to the set privacy mode.
*/
* okay so i guess what we want to do here is basically enable some long-term memory for the server when it comes to the set privacy mode.
*/

// 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 {
return roomdb.ModeUnknown, err
}

fmt.Println("config value", config.PrivacyMode)
// use a type assertion to tell compiler the returned value is a roomdb.PrivacyMode
pm := (roomdb.PrivacyMode)(config.PrivacyMode)
fmt.Println("asserted pm value", pm)
err = pm.IsValid()
if err != nil {
return roomdb.ModeUnknown, err
}

return pm, nil
config, err := models.FindConfig(ctx, c.db, configRowID)
if err != nil {
return roomdb.ModeUnknown, err
}

fmt.Println("config value", config.PrivacyMode)
// use a type assertion to tell compiler the returned value is a roomdb.PrivacyMode
pm := (roomdb.PrivacyMode)(config.PrivacyMode)
fmt.Println("asserted pm value", pm)
err = pm.IsValid()
if err != nil {
return roomdb.ModeUnknown, err
}

return pm, nil
}
4 changes: 2 additions & 2 deletions roomdb/sqlite/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Database struct {
Members Members
Aliases Aliases
Invites Invites
Config Config
Config Config

DeniedKeys DeniedKeys

Expand Down Expand Up @@ -103,7 +103,7 @@ func Open(r repo.Interface) (*Database, error) {

Aliases: Aliases{db},
AuthFallback: AuthFallback{db},
Config: Config{db},
Config: Config{db},
DeniedKeys: DeniedKeys{db},
Invites: Invites{db: db, members: ml},
Notices: Notices{db},
Expand Down
10 changes: 5 additions & 5 deletions web/handlers/admin/invites.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ func (h invitesHandler) create(w http.ResponseWriter, req *http.Request) (interf
if err != nil {
return nil, err
}
/* We want to check:
* 1. the room's privacy mode
* 2. the role of the member trying to create the invite
* and deny unallowed requests (e.g. member creating invite in ModeRestricted)
*/
/* We want to check:
* 1. the room's privacy mode
* 2. the role of the member trying to create the invite
* and deny unallowed requests (e.g. member creating invite in ModeRestricted)
*/
switch pm {
case roomdb.ModeOpen:
case roomdb.ModeCommunity:
Expand Down

0 comments on commit dc37554

Please sign in to comment.