-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
852 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package sqlite | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"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 | ||
|
||
/* Config basically enables long-term memory for the server when it comes to storing settings. Currently, the only | ||
* stored settings is the privacy mode of the room. | ||
*/ | ||
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 { | ||
return roomdb.ModeUnknown, err | ||
} | ||
|
||
// use a type conversion to tell compiler the returned value is a roomdb.PrivacyMode | ||
pm := (roomdb.PrivacyMode)(config.PrivacyMode) | ||
err = pm.IsValid() | ||
if err != nil { | ||
return roomdb.ModeUnknown, err | ||
} | ||
|
||
return pm, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +migrate Up | ||
-- 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 | ||
); | ||
|
||
-- 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 | ||
1 -- community is the default mode unless overridden | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.