Unverified Commit 9f9ef3bf authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Implemented SHOW FOLDER

parent 29f34289
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+62 −3
Original line number Diff line number Diff line
@@ -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
}

+3 −0
Original line number Diff line number Diff line
@@ -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 = ?;

+32 −0
Original line number Diff line number Diff line
@@ -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 = ?
`