diff --git a/repl/command.go b/repl/command.go index d8292fd673ecd1038621b08ec82dc4f067c20093..e048e30972271e3fa60fa46b074be9f5605f17b6 100644 --- a/repl/command.go +++ b/repl/command.go @@ -1592,6 +1592,7 @@ the SELECT command, information about that folder is shown. Format: SHOW FOLDER [folder-name]`, MaxArgs: 1, + Action: ActionShowFolder, Flags: dclish.Flags{ "/FULL": { Description: ` Control whether all information of the folder is displayed. This diff --git a/repl/show.go b/repl/show.go index 315f39d51a3539354500e39e2148d92c26c79fe3..9448f7899089702de561e8cd21a9eae6211009ae 100644 --- a/repl/show.go +++ b/repl/show.go @@ -7,12 +7,13 @@ import ( "github.com/carlmjohnson/versioninfo" "git.lyda.ie/kevin/bulletin/dclish" + "git.lyda.ie/kevin/bulletin/folders" + "git.lyda.ie/kevin/bulletin/storage" "git.lyda.ie/kevin/bulletin/this" ) // ActionShowFlags handles the `SHOW FLAGS` command. func ActionShowFlags(_ *dclish.Command) error { - // ctx := storage.Context() flagset := false fmt.Printf("For the selected folder %s:\n", this.Folder.Name) if this.Folder.Notify != 0 { @@ -38,8 +39,66 @@ func ActionShowFlags(_ *dclish.Command) error { } // ActionShowFolder handles the `SHOW FOLDER` command. -func ActionShowFolder(_ *dclish.Command) error { - fmt.Println("TODO: implement ActionShowFolder.") +func ActionShowFolder(cmd *dclish.Command) error { + ctx := storage.Context() + + folder := this.Folder + if len(cmd.Args) == 1 { + folder = folders.FindFolder(cmd.Args[0]) + } + if folder.Name == "" { + fmt.Println("ERROR: Specified folder was not found.") + } + owners, err := this.Q.GetOwners(ctx, folder.Name) + if err != nil || len(owners) == 0 { + fmt.Printf("ERROR: This folder seems to lack owners (%s).\n", err) + return nil + } + + full := false + if cmd.Flags["/FULL"].Value == "true" { + // TODO: Check permissions. + full = true + } + fmt.Printf("Settings for %s.\n", folder.Name) + if full { + switch folder.Visibility { + case folders.FolderPublic: + fmt.Println(" Folder is a public folder.") + case folders.FolderSemiPrivate: + fmt.Println(" Folder is a semi-private folder.") + case folders.FolderPrivate: + fmt.Println(" Folder is a private folder.") + } + } + switch folder.Expire { + case -1: + fmt.Println(" Default expiration is permanent.") + case 0: + fmt.Println(" No default expiration set.") + default: + fmt.Printf(" Default expiration is %d days.\n", folder.Expire) + } + if folder.System != 0 { + fmt.Println(" SYSTEM has been set.") + } + // TODO: Review SHOW_FOLDER in bulletin5.for. + if folder.Always != 0 { + fmt.Println(" ALWAYS has been set.") + } + if this.Folder.Notify != 0 { + fmt.Println(" Default is NOTIFY.") + } + if this.Folder.Readnew != 0 { + fmt.Println(" Default is READNEW.") + } + if this.Folder.Brief != 0 { + fmt.Println(" Default is BRIEF.") + } + if this.Folder.Shownew != 0 { + fmt.Println(" Default is SHOWNEW.") + } + return nil } diff --git a/storage/queries/standard.sql b/storage/queries/standard.sql index cdfe2e4afff983b469b3b4e9035a87eff74bcece..a341d18ee791881d75c87e42594b880625ecef6c 100644 --- a/storage/queries/standard.sql +++ b/storage/queries/standard.sql @@ -25,6 +25,9 @@ SELECT * FROM owners; -- name: GetOwner :one SELECT * FROM owners WHERE folder = ? AND login = ?; +-- name: GetOwners :many +SELECT * FROM owners WHERE folder = ?; + -- name: DeleteOwner :exec DELETE FROM owners WHERE folder = ? AND login = ?; diff --git a/storage/standard.sql.go b/storage/standard.sql.go index 5e464f92a2830b038f19f512acbd54a7f5e3c885..ffe19b2d4305b6f8575091f440407e50e9dd67f0 100644 --- a/storage/standard.sql.go +++ b/storage/standard.sql.go @@ -343,6 +343,38 @@ func (q *Queries) GetOwner(ctx context.Context, arg GetOwnerParams) (Owner, erro return i, err } +const getOwners = `-- name: GetOwners :many +SELECT folder, login, create_at, update_at FROM owners WHERE folder = ? +` + +func (q *Queries) GetOwners(ctx context.Context, folder string) ([]Owner, error) { + rows, err := q.db.QueryContext(ctx, getOwners, folder) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Owner + for rows.Next() { + var i Owner + if err := rows.Scan( + &i.Folder, + &i.Login, + &i.CreateAt, + &i.UpdateAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getSeen = `-- name: GetSeen :one SELECT login, folder, msgid FROM seen WHERE folder = ? AND login = ? AND msgid = ? `