Loading repl/mail_actions.go +9 −23 Original line number Diff line number Diff line Loading @@ -82,15 +82,11 @@ func ActionMailRead(cmd *dclish.Command) error { } else { // Find first unread. nextID, err := this.Q.NextMailID(ctx, this.User.Login, int64(0)) if err != nil || nextID == nil { fmt.Println("No mail messages.") return nil } mailID, _ = nextID.(int64) if mailID == 0 { if err != nil || nextID == 0 { fmt.Println("No mail messages.") return nil } mailID = nextID } mail, err := this.Q.ReadMail(ctx, mailID, this.User.Login) Loading Loading @@ -206,22 +202,17 @@ func ActionMailReply(_ *dclish.Command) error { func ActionMailNext(_ *dclish.Command) error { ctx := storage.Context() nextID, err := this.Q.NextMailID(ctx, this.User.Login, currentMailID) if err != nil || nextID == nil { fmt.Println("No next mail message.") return nil } id, ok := nextID.(int64) if !ok || id == 0 { if err != nil || nextID == 0 { fmt.Println("No next mail message.") return nil } mail, err := this.Q.ReadMail(ctx, id, this.User.Login) mail, err := this.Q.ReadMail(ctx, nextID, this.User.Login) if err != nil { return err } _ = this.Q.MarkMailRead(ctx, id, this.User.Login) // #nosec G104 currentMailID = id _ = this.Q.MarkMailRead(ctx, nextID, this.User.Login) // #nosec G104 currentMailID = nextID pager.Pager(formatMail(mail)) return nil } Loading @@ -230,21 +221,16 @@ func ActionMailNext(_ *dclish.Command) error { func ActionMailBack(_ *dclish.Command) error { ctx := storage.Context() prevID, err := this.Q.PrevMailID(ctx, this.User.Login, currentMailID) if err != nil || prevID == nil { fmt.Println("No previous mail message.") return nil } id, ok := prevID.(int64) if !ok || id == 0 { if err != nil || prevID == 0 { fmt.Println("No previous mail message.") return nil } mail, err := this.Q.ReadMail(ctx, id, this.User.Login) mail, err := this.Q.ReadMail(ctx, prevID, this.User.Login) if err != nil { return err } currentMailID = id currentMailID = prevID pager.Pager(formatMail(mail)) return nil } Loading storage/mail.sql.go +12 −12 Original line number Diff line number Diff line Loading @@ -150,31 +150,31 @@ func (q *Queries) MarkMailRead(ctx context.Context, iD int64, toLogin string) er } const nextMailID = `-- name: NextMailID :one SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ? SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ? ` // NextMailID gets the next mail id after the given id for a user. // // SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ? func (q *Queries) NextMailID(ctx context.Context, toLogin string, iD int64) (interface{}, error) { // SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ? func (q *Queries) NextMailID(ctx context.Context, toLogin string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, nextMailID, toLogin, iD) var min interface{} err := row.Scan(&min) return min, err var column_1 int64 err := row.Scan(&column_1) return column_1, err } const prevMailID = `-- name: PrevMailID :one SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ? SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ? ` // PrevMailID gets the previous mail id before the given id for a user. // // SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ? func (q *Queries) PrevMailID(ctx context.Context, toLogin string, iD int64) (interface{}, error) { // SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ? func (q *Queries) PrevMailID(ctx context.Context, toLogin string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, prevMailID, toLogin, iD) var max interface{} err := row.Scan(&max) return max, err var column_1 int64 err := row.Scan(&column_1) return column_1, err } const readMail = `-- name: ReadMail :one Loading storage/messages.sql.go +4 −4 Original line number Diff line number Diff line Loading @@ -254,13 +254,13 @@ func (q *Queries) GetLastReadByUser(ctx context.Context, folder string, author s } const lastMsgidIgnoringSeen = `-- name: LastMsgidIgnoringSeen :one SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1 SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 ` // LastMsgidIgnoringSeen last message id in a folder without factoring in // if the message has been seen. // // SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1 // SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 func (q *Queries) LastMsgidIgnoringSeen(ctx context.Context, folder string) (int64, error) { row := q.db.QueryRowContext(ctx, lastMsgidIgnoringSeen, folder) var column_1 int64 Loading Loading @@ -479,13 +479,13 @@ func (q *Queries) NextMsgid(ctx context.Context, folder string, iD int64, login } const nextMsgidIgnoringSeen = `-- name: NextMsgidIgnoringSeen :one SELECT CAST(MIN(id) AS INT) FROM messages AS m SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 AND m.id > ?2 ` // NextMsgidIgnoringSeen gets the next message id. // // SELECT CAST(MIN(id) AS INT) FROM messages AS m // SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m // WHERE m.folder = ?1 AND m.id > ?2 func (q *Queries) NextMsgidIgnoringSeen(ctx context.Context, folder string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, nextMsgidIgnoringSeen, folder, iD) Loading storage/queries/mail.sql +2 −2 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ SELECT COUNT(*) FROM mail WHERE to_login = ? AND read = 0; -- NextMailID gets the next mail id after the given id for a user. -- name: NextMailID :one SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ?; SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ?; -- PrevMailID gets the previous mail id before the given id for a user. -- name: PrevMailID :one SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ?; SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ?; storage/queries/messages.sql +2 −2 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m -- NextMsgidIgnoringSeen gets the next message id. -- name: NextMsgidIgnoringSeen :one SELECT CAST(MIN(id) AS INT) FROM messages AS m SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 AND m.id > ?2; -- PrevMsgid get the previous message id. Loading @@ -77,7 +77,7 @@ DELETE FROM messages WHERE folder = ?; -- LastMsgidIgnoringSeen last message id in a folder without factoring in -- if the message has been seen. -- name: LastMsgidIgnoringSeen :one SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1; SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1; -- GetLastRead gets the last message read by a login in a folder. -- name: GetLastRead :many Loading Loading
repl/mail_actions.go +9 −23 Original line number Diff line number Diff line Loading @@ -82,15 +82,11 @@ func ActionMailRead(cmd *dclish.Command) error { } else { // Find first unread. nextID, err := this.Q.NextMailID(ctx, this.User.Login, int64(0)) if err != nil || nextID == nil { fmt.Println("No mail messages.") return nil } mailID, _ = nextID.(int64) if mailID == 0 { if err != nil || nextID == 0 { fmt.Println("No mail messages.") return nil } mailID = nextID } mail, err := this.Q.ReadMail(ctx, mailID, this.User.Login) Loading Loading @@ -206,22 +202,17 @@ func ActionMailReply(_ *dclish.Command) error { func ActionMailNext(_ *dclish.Command) error { ctx := storage.Context() nextID, err := this.Q.NextMailID(ctx, this.User.Login, currentMailID) if err != nil || nextID == nil { fmt.Println("No next mail message.") return nil } id, ok := nextID.(int64) if !ok || id == 0 { if err != nil || nextID == 0 { fmt.Println("No next mail message.") return nil } mail, err := this.Q.ReadMail(ctx, id, this.User.Login) mail, err := this.Q.ReadMail(ctx, nextID, this.User.Login) if err != nil { return err } _ = this.Q.MarkMailRead(ctx, id, this.User.Login) // #nosec G104 currentMailID = id _ = this.Q.MarkMailRead(ctx, nextID, this.User.Login) // #nosec G104 currentMailID = nextID pager.Pager(formatMail(mail)) return nil } Loading @@ -230,21 +221,16 @@ func ActionMailNext(_ *dclish.Command) error { func ActionMailBack(_ *dclish.Command) error { ctx := storage.Context() prevID, err := this.Q.PrevMailID(ctx, this.User.Login, currentMailID) if err != nil || prevID == nil { fmt.Println("No previous mail message.") return nil } id, ok := prevID.(int64) if !ok || id == 0 { if err != nil || prevID == 0 { fmt.Println("No previous mail message.") return nil } mail, err := this.Q.ReadMail(ctx, id, this.User.Login) mail, err := this.Q.ReadMail(ctx, prevID, this.User.Login) if err != nil { return err } currentMailID = id currentMailID = prevID pager.Pager(formatMail(mail)) return nil } Loading
storage/mail.sql.go +12 −12 Original line number Diff line number Diff line Loading @@ -150,31 +150,31 @@ func (q *Queries) MarkMailRead(ctx context.Context, iD int64, toLogin string) er } const nextMailID = `-- name: NextMailID :one SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ? SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ? ` // NextMailID gets the next mail id after the given id for a user. // // SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ? func (q *Queries) NextMailID(ctx context.Context, toLogin string, iD int64) (interface{}, error) { // SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ? func (q *Queries) NextMailID(ctx context.Context, toLogin string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, nextMailID, toLogin, iD) var min interface{} err := row.Scan(&min) return min, err var column_1 int64 err := row.Scan(&column_1) return column_1, err } const prevMailID = `-- name: PrevMailID :one SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ? SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ? ` // PrevMailID gets the previous mail id before the given id for a user. // // SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ? func (q *Queries) PrevMailID(ctx context.Context, toLogin string, iD int64) (interface{}, error) { // SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ? func (q *Queries) PrevMailID(ctx context.Context, toLogin string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, prevMailID, toLogin, iD) var max interface{} err := row.Scan(&max) return max, err var column_1 int64 err := row.Scan(&column_1) return column_1, err } const readMail = `-- name: ReadMail :one Loading
storage/messages.sql.go +4 −4 Original line number Diff line number Diff line Loading @@ -254,13 +254,13 @@ func (q *Queries) GetLastReadByUser(ctx context.Context, folder string, author s } const lastMsgidIgnoringSeen = `-- name: LastMsgidIgnoringSeen :one SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1 SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 ` // LastMsgidIgnoringSeen last message id in a folder without factoring in // if the message has been seen. // // SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1 // SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 func (q *Queries) LastMsgidIgnoringSeen(ctx context.Context, folder string) (int64, error) { row := q.db.QueryRowContext(ctx, lastMsgidIgnoringSeen, folder) var column_1 int64 Loading Loading @@ -479,13 +479,13 @@ func (q *Queries) NextMsgid(ctx context.Context, folder string, iD int64, login } const nextMsgidIgnoringSeen = `-- name: NextMsgidIgnoringSeen :one SELECT CAST(MIN(id) AS INT) FROM messages AS m SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 AND m.id > ?2 ` // NextMsgidIgnoringSeen gets the next message id. // // SELECT CAST(MIN(id) AS INT) FROM messages AS m // SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m // WHERE m.folder = ?1 AND m.id > ?2 func (q *Queries) NextMsgidIgnoringSeen(ctx context.Context, folder string, iD int64) (int64, error) { row := q.db.QueryRowContext(ctx, nextMsgidIgnoringSeen, folder, iD) Loading
storage/queries/mail.sql +2 −2 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ SELECT COUNT(*) FROM mail WHERE to_login = ? AND read = 0; -- NextMailID gets the next mail id after the given id for a user. -- name: NextMailID :one SELECT MIN(id) FROM mail WHERE to_login = ? AND id > ?; SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM mail WHERE to_login = ? AND id > ?; -- PrevMailID gets the previous mail id before the given id for a user. -- name: PrevMailID :one SELECT MAX(id) FROM mail WHERE to_login = ? AND id < ?; SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM mail WHERE to_login = ? AND id < ?;
storage/queries/messages.sql +2 −2 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m -- NextMsgidIgnoringSeen gets the next message id. -- name: NextMsgidIgnoringSeen :one SELECT CAST(MIN(id) AS INT) FROM messages AS m SELECT CAST(COALESCE(MIN(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1 AND m.id > ?2; -- PrevMsgid get the previous message id. Loading @@ -77,7 +77,7 @@ DELETE FROM messages WHERE folder = ?; -- LastMsgidIgnoringSeen last message id in a folder without factoring in -- if the message has been seen. -- name: LastMsgidIgnoringSeen :one SELECT CAST(MAX(id) AS INT) FROM messages AS m WHERE m.folder = ?1; SELECT CAST(COALESCE(MAX(id), 0) AS INT) FROM messages AS m WHERE m.folder = ?1; -- GetLastRead gets the last message read by a login in a folder. -- name: GetLastRead :many Loading