This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/treepath/summary.go
2026-02-26 21:19:55 +00:00

39 lines
926 B
Go

package treepath
import "encoding/json"
// IsSummaryMessage checks if a PathMessage has summary metadata
// (metadata.type == "summary").
func IsSummaryMessage(m *PathMessage) bool {
if m.Metadata == nil {
return false
}
meta := ParseMetadata(m)
return meta["type"] == "summary"
}
// ParseMetadata unmarshals the JSONB metadata on a PathMessage.
// Returns an empty map on any error.
func ParseMetadata(m *PathMessage) map[string]interface{} {
if m.Metadata == nil {
return map[string]interface{}{}
}
var meta map[string]interface{}
if err := json.Unmarshal(*m.Metadata, &meta); err != nil {
return map[string]interface{}{}
}
return meta
}
// FindSummaryBoundary returns the index of the most recent summary node
// in a path, or -1 if no summary exists.
func FindSummaryBoundary(path []PathMessage) int {
idx := -1
for i := range path {
if IsSummaryMessage(&path[i]) {
idx = i
}
}
return idx
}