gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/lib/usedin.hl

1.8 KB

  1. // lib/usedin.hl — "USED IN" (ident#26): the apps an identity is connected to, for its page (components/identity.hl,
  2. // `/identity/<id>`). CONCEPT.md "Per-app page": each row is a connection (identity + app) — `created` is when the identity
  3. // registered in the app (the first login), `lastLogin` the last time the app exchanged a one-time code for it (lib/apps.hl
  4. // exchange, one write per login). Each row links to the per-app page `/inbox/<connection id>` (notification switches).
  5. // Read only; no table of its own.
  6. import { now } from 'hl:time'
  7. import { countOf, str } from './util.hl'
  8. import { identityRecord, identityRows } from './identities.hl'
  9. import { appsTable, connectionsTable } from './apps.hl'
  10. import { appName } from './notify.hl'
  11. import { newestFirst } from './notify-helpers.hl'
  12. import { usedLine } from './usedin-helpers.hl'
  13. // { identity: { id, label, shortId, avatar, hasAvatar }, rows: [{ id, href, app, line }] , hasRows, noRows } for the
  14. // account's identity `identityId`, or null when it is not the account's. Rows: most recently registered first.
  15. static usedIn = (accountId, identityId) => {
  16. r = identityRecord(identityId)
  17. if (r == null || r.account != accountId) { return null }
  18. let me = null
  19. for (row of identityRows(accountId)) { if ('' + row.id == '' + identityId) { me = row } }
  20. if (me == null) { return null }
  21. t = now()
  22. let rows = []
  23. all = connectionsTable.find(null, null)
  24. mine = []
  25. if (countOf(all) > 0) { for (c of all) { if (c.identity == identityId) { mine.push(c) } } }
  26. if (mine.length > 0) {
  27. for (c of newestFirst(mine)) {
  28. if (appsTable.fetch(c.app) == null) { continue }
  29. rows.push({ id = c.id href = '/inbox/' + c.id app = appName(c.app) line = usedLine(c.created, c.lastLogin, t) })
  30. }
  31. }
  32. return { identity = me rows = rows hasRows = rows.length > 0 noRows = rows.length == 0 }
  33. }

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre