package api
// NotifyImportEnded tells the person who asked for an import how it
// ended. A copy of a large upstream runs for minutes or an hour, and
// its progress page is the only other place the outcome shows: whoever
// closed that tab learned nothing, and a failed import has no
// repository page to find (its store is removed when it stops).
//
// It rides the landing family, as a red trunk does: work the person
// asked for that now wants their attention, with the push and the
// inbox row that family already carries, and no fifth family in the
// preference matrix.
//
// A failure names no "repo" in its payload: there is no repository to
// read, so the delivery-time read check would drop the notice for the
// very person it is for. It links the progress page, which keeps the
// reason and offers Start again. The key is the name and the start, so
// a second attempt under the same name is its own news.
func (d Deps) NotifyImportEnded(name, to, started, why string) {
if !personTo(to) {
return
}
payload := map[string]any{"repoName": name, "from": "import", "surface": "import"}
if why == "" {
payload["repo"] = name
payload["summary"] = "Import of " + name + " finished"
payload["link"] = d.link("/r/" + name)
} else {
payload["summary"] = "Import of " + name + " failed: " + clipNote(why, 160)
payload["link"] = d.link("/new/progress/" + name)
}
d.fireNotify(NotifyEvent{
Workflow: "quarry-landing", To: to, Payload: payload,
TxnID: "import:" + name + ":" + started + ":" + to,
})
}