tickets
All repositories: gitoria
8.6 KB
// lib/events.hl — THE HISTORY OF A TICKET: an append-only event per change. Statics only, the server realm.// eventsTable pk @id index @ticket APPEND ONLY: { ticket (ticket @id), seq// (1, 2, … per ticket), kind, author, user?, text, from, to, created, oldId? }// kind = 'created' | 'comment' | 'state' | 'edit' | 'link' | 'assign'// 'assign' (ticket #20): { assignee (users @id, '' = unassigned), previous (users @id, '') }// 'link' (ticket #4, mission 017): { linkKind ('parent' | 'blockedBy'), action// ('set' | 'removed'), other, otherProject, otherNumber, previous?, previousProject?,// previousNumber? } — on the CHILD / the BLOCKED ticket (the one whose relation changed).// 'edit' (ticket #8, mission 014): { oldSubject, oldSummary, subject, summary } —// the values before AND after; the ticket record then carries the new ones.// `user` (users @id, users.hl) since ticket #7: the event's author is that// user's CURRENT display name; `author` keeps the name at writing time.// 'comment' (mission 016): the event keeps the FIRST text; edits, a deletion and likes are kept by// lib/comments.hl, and the rows here show the comment as it is now (commentStateOf). Its files// (tickets#27): lib/attachments.hl (the row's `attachments`).// tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.import { MPackDB } from 'hl:mpackdb'import { storageDir, countOf, localStamp, ticketHref } from './util.hl'import { nameOfUser } from './users.hl'import { projectSlugOf } from './projects.hl'import { slugOf } from './tickets-helpers.hl'import { markdownBlocks } from './markdown.hl'import { commentStateOf, likersOf } from './comments.hl'import { attachmentsOf } from './attachments.hl'static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])// ---- writing -------------------------------------------------------------------------------------// appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)static putEvent = (rec) => { return eventsTable.put(rec) }static eventsError = () => { return eventsTable.lastError() }// one stored event record, or null (the event stream numbers it, lib/stream.hl)static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }// the API row of a stored eventstatic eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }// ---- reading -------------------------------------------------------------------------------------// the history of a ticket (a record), oldest first: by stored time, then seqstatic historyOf = (t) => {out = []all = eventsTable.find('ticket', t.id)if (countOf(all) == 0) { return out }for (e of all) { out.push(eventRowOf(e, t)) }let i = 1while (i < out.length) {let cur = out[i]let j = i - 1while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {out[j + 1] = out[j]j = j - 1}out[j + 1] = curi = i + 1}return out}// a ticket from before the login has no createdBy: the free-text author of its 'created' eventstatic creatorNameOf = (t) => {all = eventsTable.find('ticket', t.id)if (countOf(all) == 0) { return '' }for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }return ''}// ---- the shapes ----------------------------------------------------------------------------------static eventRowOf = (e, t) => {let kind = e.kind// computed BEFORE the literal: inside a literal that has an `id` entry, a called function's// parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)who = e.user != null ? nameOfUser(e.user) : e.authorlet label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))if (kind == 'link') { label = linkLabelOf(e) }let assignedTo = ''let assignedWas = ''if (kind == 'assign') {assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')}row = {id = e.idticket = e.ticketproject = t != null ? projectSlugOf(t) : ''number = t != null ? t.number : 0seq = e.seq != null ? e.seq : 0kind = kindauthor = whouserId = e.user != null ? e.user : ''text = e.text != null ? e.text : ''hasText = e.text != null && e.text != ''from = e.from != null ? e.from : ''to = e.to != null ? e.to : ''toSlug = slugOf(e.to)isState = kind == 'state'isComment = kind == 'comment'isCreated = kind == 'created'label = labelwhen = localStamp(e.created)createdMs = e.created}// ticket #8: only an edit event carries these (the JSON of every other event is unchanged)if (kind == 'edit') {row.isEdit = truerow.oldSubject = e.oldSubject != null ? e.oldSubject : ''row.oldSummary = e.oldSummary != null ? e.oldSummary : ''row.newSubject = e.subject != null ? e.subject : ''row.newSummary = e.summary != null ? e.summary : ''row.subjectChanged = row.oldSubject != row.newSubjectrow.summaryChanged = row.oldSummary != row.newSummary}// ticket #4: only a link event carries theseif (kind == 'link') {row.isLink = truerow.linkKind = e.linkKindrow.linkAction = e.actionrow.otherRef = e.otherProject + ' #' + e.otherNumberrow.otherHref = ticketHref(e.otherProject, e.otherNumber)row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''}// mission 016: a comment as it is NOW (lib/comments.hl). Only a changed comment carries the extra keys: an edited one// `edited`, `editedWhen`, `earlier` ([{ when, text }], the versions before, oldest first) and the newest `text`; a// deleted one `deleted`, `deletedWhen`, no text, the label "commented (deleted …)"; a liked one `likes` (the count).// Every other comment row has exactly the keys it had before.if (kind == 'comment') {cs = commentStateOf(e)if (cs.edited) {row.text = cs.textrow.hasText = cs.text != ''row.edited = truerow.editedWhen = localStamp(cs.editedMs)row.earlier = versionsOf(cs.earlier)}if (cs.deleted) {row.text = ''row.hasText = falserow.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'row.deleted = truerow.deletedWhen = localStamp(cs.deletedMs)}if (cs.likes > 0) { row.likes = cs.likes }// tickets#27: only a comment with files carries `attachments` ([{ id, name, type, size, image, url }]; a deleted one has none)if (!cs.deleted) {files = attachmentsOf(e.id)if (files.length > 0) { row.attachments = files }}}// ticket #20: only an assign event carries theseif (kind == 'assign') {row.isAssign = truerow.assignee = assignedTorow.previousAssignee = assignedWas}return row}static versionsOf = (list) => {out = []for (v of list) { out.push({ when = v.when text = v.text }) }return out}// "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …static linkLabelOf = (e) => {other = e.otherProject + ' #' + e.otherNumberif (e.linkKind == 'parent') {if (e.action == 'removed') { return 'removed the parent ' + other }was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''return 'set the parent to ' + other + was}if (e.action == 'removed') { return 'removed the blocker ' + other }return 'marked it blocked by ' + other}// THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an// edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket// page takes it over live). Only pages and pushes carry these — the JSON API does not.static pageEventOf = (ev) => {out = {}for (k of ev.keys()) { out[k] = ev[k] }out.md = markdownBlocks(ev.text)// mission 016: who likes a comment (users @ids) — the page works out `liked` for the user lookingif (ev.isComment == true) { out.likedBy = likersOf(ev.id) }if (ev.isEdit == true) {out.oldSummaryMd = markdownBlocks(ev.oldSummary)out.summaryMd = markdownBlocks(ev.newSummary)}return out}static pageEventsOf = (evs) => {out = []for (ev of evs) { out.push(pageEventOf(ev)) }return out}
Branches
Latest commits
- ea2e440esecurity audit (ST): JSON body cap, relation rights, login session rotation, __Host- Secure cookie, API security headers, CSP+referrer meta, /connect cap, one-line subjects, tests/security.mjs, reportmre
- 7c8c2282sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- b6277497report MT-mobile, LOGmre
- 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
- 31736a80gate: member-name check fails on the old row layout toomre
- e03ae537gate: the phone checks run on without the Show more button (so old code reports every failed check)mre
- adf7f132gate: 390 px checks for the mobile audit fixes (row number, filters, field widths, Edit, member names, relation taps, paging)mre
- 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
- ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
- f2dc7741gate: the phone toolbar is two even rows (E2)mre
- 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
- d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
- 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre