Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language picker #143

Merged
merged 18 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,995 changes: 3,983 additions & 12 deletions muxrpc/test/nodejs/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion muxrpc/test/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ssb-keys": "^8.1.0",
"ssb-replicate": "^1.3.2",
"ssb-room": "^1.3.0",
"ssb-room-client": "^0.4.0",
"ssb-room-client": "^0.10.0",
"tap-spec": "^5.0.0",
"tape": "^5.2.2"
}
Expand Down
2 changes: 2 additions & 0 deletions roomdb/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
type RoomConfig interface {
GetPrivacyMode(context.Context) (PrivacyMode, error)
SetPrivacyMode(context.Context, PrivacyMode) error
GetDefaultLanguage(context.Context) (string, error)
SetDefaultLanguage(context.Context, string) error
}

// AuthFallbackService allows password authentication which might be helpful for scenarios
Expand Down
155 changes: 155 additions & 0 deletions roomdb/mockdb/roomconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions roomdb/sqlite/migrations/03-config.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
-- +migrate Up
-- the configuration settings for this room, currently only privacy modes
-- the configuration settings for this room, currently privacy mode settings and the default translation for the room
CREATE TABLE config (
id integer NOT NULL PRIMARY KEY,
privacyMode integer NOT NULL, -- open, community, restricted
defaultLanguage TEXT NOT NULL, -- a language tag, e.g. en, sv, de
use_subdomain_for_aliases boolean NOT NULL, -- flag to toggle using subdomains (rather than alias routes) for aliases

CHECK (id == 0) -- should only ever store one row
);

-- the config table will only ever contain one row: the rooms current settings
-- we update that row whenever the config changes.
-- to have something to update, we insert the first and only row at id 0
INSERT INTO config (id, privacyMode) VALUES (
0, -- the constant id we will query
2 -- community is the default mode unless overridden
INSERT INTO config (id, privacyMode, defaultLanguage, use_subdomain_for_aliases) VALUES (
0, -- the constant id we will query
2, -- community is the default mode unless overridden
"en", -- english is the default language for all installs
1 -- use subdomain for aliases
);

-- +migrate Down
Expand Down
43 changes: 31 additions & 12 deletions roomdb/sqlite/models/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions roomdb/sqlite/models/invites.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 42 additions & 1 deletion roomdb/sqlite/roomconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error
return err
}

// cblgh: a walkthrough of this step (again, now that i have some actual context) would be real good :)
err = transact(c.db, func(tx *sql.Tx) error {
// get the settings row
config, err := models.FindConfig(ctx, tx, configRowID)
Expand Down Expand Up @@ -68,3 +67,45 @@ func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error

return nil // alles gut!!
}

func (c Config) GetDefaultLanguage(ctx context.Context) (string, error) {
config, err := models.FindConfig(ctx, c.db, configRowID)
if err != nil {
return "", err
}

return config.DefaultLanguage, nil
}

func (c Config) SetDefaultLanguage(ctx context.Context, langTag string) error {
if len(langTag) == 0 {
return fmt.Errorf("language tag cannot be empty")
}

err := transact(c.db, func(tx *sql.Tx) error {
// get the settings row
config, err := models.FindConfig(ctx, tx, configRowID)
if err != nil {
return err
}

// set the new language tag
config.DefaultLanguage = langTag
// issue update stmt
rowsAffected, err := config.Update(ctx, tx, boil.Infer())
if err != nil {
return err
}
if rowsAffected == 0 {
return fmt.Errorf("setting default language should have update the settings row, instead 0 rows were updated")
}

return nil
})

if err != nil {
return err
}

return nil // alles gut!!
}
Loading