dmitri.shuralyov.com/app/changes

Merge ListComments, ListEvents into ListTimeline.

There's no longer a clean distinction between comments and events.
There are other timeline item types that don't fit into either category
cleanly. Also, underlying implementations for various APIs are very
similar and have overlap. As a result, it makes sense to merge these
two methods into one.
dmitshur committed 7 years ago commit df8759d2e6e37ef297f18e8f8ef1418b3a74d2fa
Showing partial commit. Full Commit
Collapse all
main.go
@@ -300,27 +300,20 @@ func (h *handler) ChangeHandler(w http.ResponseWriter, req *http.Request, change
	}
	state.Change, err = h.is.Get(req.Context(), state.RepoSpec, state.ChangeID)
	if err != nil {
		return err
	}
	cs, err := h.is.ListComments(req.Context(), state.RepoSpec, state.ChangeID, nil)
	ts, err := h.is.ListTimeline(req.Context(), state.RepoSpec, state.ChangeID, nil)
	if err != nil {
		return fmt.Errorf("changes.ListComments: %v", err)
		return fmt.Errorf("changes.ListTimeline: %v", err)
	}
	es, err := h.is.ListEvents(req.Context(), state.RepoSpec, state.ChangeID, nil)
	if err != nil {
		return fmt.Errorf("changes.ListEvents: %v", err)
	}
	var items []timelineItem
	for _, comment := range cs {
		items = append(items, timelineItem{comment})
	}
	for _, event := range es {
		items = append(items, timelineItem{event})
	var timeline []timelineItem
	for _, item := range ts {
		timeline = append(timeline, timelineItem{item})
	}
	sort.Sort(byCreatedAtID(items))
	state.Items = items
	sort.Sort(byCreatedAtID(timeline))
	state.Timeline = timeline
	// Call loadTemplates to set updated reactionsBar, reactableID, etc., template functions.
	t, err := loadTemplates(state.State, h.Options.BodyPre)
	if err != nil {
		return fmt.Errorf("loadTemplates: %v", err)
	}
@@ -498,13 +491,13 @@ type state struct {
	HeadPre, HeadPost template.HTML
	BodyTop           template.HTML

	common.State

	Changes component.Changes
	Change  changes.Change
	Items   []timelineItem
	Changes  component.Changes
	Change   changes.Change
	Timeline []timelineItem
}

func (s state) Tabnav(selected string) template.HTML {
	// Render the tabnav.
	return template.HTML(htmlg.RenderComponentsString(tabnav{