package web
import "html/template"
// settleEvent is one resolve or reopen, as drawn inside the blocking
// comment it settles.
type settleEvent struct {
Kind, User, Date string
// Unverified says User is the name the reply claims, because the forge
// recorded no account for it.
Unverified bool
// Hidden withholds the reply's words the way a hidden post is.
Hidden bool
HiddenReason string
// Deleted and Removed are the removal notice a deleted reply keeps.
Deleted bool
Removed string
HTML template.HTML
}
// foldSettles moves each resolve and reopen into the blocking comment it
// names, so the thread reads as the comment and what became of it, and
// takes it out of the flat list. A settle whose comment is not on the
// page (hidden from this reader, or aimed at a version the thread no
// longer lists) stays where it is and draws as its own compact row.
func foldSettles(rows []forumPostRow) []forumPostRow {
at := make(map[string]int, len(rows))
for i, r := range rows {
if r.Blocking != "" {
at[r.Hash] = i
}
}
folded := make([]bool, len(rows))
// into maps a folded settle's own hash to its blocker's row, so a
// reply to the settle can point at the comment it now lives in.
into := map[string]int{}
for j, r := range rows {
if i, ok := at[r.Settles]; ok && r.Settle != "" {
rows[i].Events = append(rows[i].Events, settleEvent{Kind: r.Settle, User: r.SettleBy,
Date: r.SettleAt, Unverified: r.SettleUnverified, Hidden: r.Hidden,
HiddenReason: r.HiddenReason, Deleted: r.Deleted, Removed: r.Removed, HTML: r.HTML})
folded[j], into[r.Hash] = true, i
}
}
for j := range rows {
if i, ok := into[rows[j].Parent]; ok {
rows[j].Parent, rows[j].ParentUser = rows[i].Hash, rows[i].User
}
}
out := make([]forumPostRow, 0, len(rows))
for j, r := range rows {
if !folded[j] {
out = append(out, r)
}
}
return out
}