package index
// RejectedAt maps each branch whose newest landing was REJECTED to the
// date of the reply that rejected it. A branch absent from the map has
// no landing, or its newest one is open or accepted.
//
// It answers "has anyone spoken for this branch's current work?": work
// that was proposed and turned down has been answered, until someone
// adds to it.
func (ix *Index) RejectedAt() (map[string]string, error) {
rows, err := ix.db.Query(`
SELECT l.branch, l.state, COALESCE(p.date, l.updated)
FROM landing l
LEFT JOIN forum_post p ON p.hash = l.settled_by
ORDER BY l.opened`)
if err != nil {
return nil, err
}
defer rows.Close()
out := map[string]string{}
for rows.Next() {
var branch, state, at string
if err := rows.Scan(&branch, &state, &at); err != nil {
return nil, err
}
// Ordered by opening, so the newest landing on a branch has the
// last word.
if state == "rejected" {
out[branch] = at
} else {
delete(out, branch)
}
}
return out, rows.Err()
}