gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9d686bb39d686bb3Tracker: CL1 reviewedmre9d686bb3/lib/follows.hl

4.0 KB

  1. // lib/follows.hl — per-user follow data (tracker.worldapi.org#5): which shows a user follows; since mission 047 also the
  2. // show page's Follow toggle (`setFollowed`).
  3. // storage/mpackdb/follows.db, migrated by tools/migrate.hl (tracker.worldapi.org#2): { show, user, at, oldId }.
  4. // Kept apart from shows.hl (show data) and watches.hl (watch state) so /unwatched, /schedule and /my/shows (tickets #5/#6/#7,
  5. // "reuse, don't copy") can all import the same functions.
  6. import { MPackDB } from 'hl:mpackdb'
  7. import { now } from 'hl:time'
  8. import { randomBytes } from 'hl:crypto'
  9. import { storageDir } from './util.hl'
  10. static followsTable = new MPackDB(file = storageDir + '/follows.db', primaryKey = '@id', indexes = ['!oldId'])
  11. // every follow record of this user ({ show, user, at, … }, `at` = epoch ms) — a linear scan (128 rows
  12. // total across every user, migrated data; cheap once per page load) — no declared index on `user`.
  13. // /my/shows (tracker.worldapi.org#7) needs the whole record for its follow-date order.
  14. static followsOfUser = (&userId) => {
  15. if (userId == null) { return [] }
  16. out = []
  17. for (f of followsTable.iterate(null, null)) { if (f.user == userId && f.show != null) { out.push(f) } }
  18. return out
  19. }
  20. // insertion sort, hand-written (no list sort(), hybriel#1) — newest follow first; `at` is epoch ms (migrated
  21. // `_createdAt`, or now() for a new follow), a missing one counts as the oldest. Rows carry `followedAt`.
  22. // /my/shows and /my/movies (tracker.worldapi.org#7/#13)
  23. static insertByFollowDesc = (&sorted, &row) => {
  24. out = []
  25. let inserted = false
  26. for (x of sorted) {
  27. if (!inserted && row.followedAt >= x.followedAt) { out.push(row) inserted = true }
  28. out.push(x)
  29. }
  30. if (!inserted) { out.push(row) }
  31. return out
  32. }
  33. // the ids of every show this user follows
  34. static followedShowIds = (&userId) => {
  35. out = []
  36. for (f of followsOfUser(userId)) { out.push(f.show) }
  37. return out
  38. }
  39. // every show ANYONE follows, each once, in follow-table order — what the TMDB sync (sync.hl,
  40. // tracker.worldapi.org#9) keeps up to date
  41. static allFollowedShowIds = () => {
  42. seen = {}
  43. out = []
  44. for (f of followsTable.iterate(null, null)) {
  45. if (f.show != null && seen[f.show] != true) { seen[f.show] = true out.push(f.show) }
  46. }
  47. return out
  48. }
  49. // mission 047 (the show page's Follow / Following toggle): does this user follow this show?
  50. static isFollowing = (&userId, &showId) => {
  51. if (userId == null || showId == null) { return false }
  52. for (f of followsOfUser(userId)) { if (f.show == showId) { return true } }
  53. return false
  54. }
  55. // follow (a new record, follow date = now → the top of /my/shows) or unfollow (every record of this user+show is
  56. // deleted). Own 16-hex id + a unique `oldId` marker (the `!oldId` UNIQUE index refuses a second null), never update()
  57. // (hybriel#113) — the same shape as watches.hl `setWatched`.
  58. static setFollowed = (&userId, &showId, &follow) => {
  59. if (userId == null || showId == null) { return false }
  60. mine = []
  61. for (f of followsOfUser(userId)) { if (f.show == showId) { mine.push(f) } }
  62. if (follow) {
  63. if (mine.length > 0) { return true }
  64. id = followsTable.put({ id = randomBytes(8, 'hex') show = showId user = userId at = now() oldId = 'app:' + randomBytes(8, 'hex') })
  65. return id != null
  66. }
  67. let ok = true
  68. for (f of mine) { ok = followsTable.delete(f.id) > 0 && ok }
  69. return ok
  70. }
  71. // the show page's Follow button (components/show.hl face showToggleFollow): following → not, not → following; the new state, or
  72. // null when it could not be saved
  73. static toggleFollowed = (&userId, &showId) => {
  74. follow = isFollowing(userId, showId) == false
  75. return setFollowed(userId, showId, follow) ? follow : null
  76. }
  77. // mission SK (components/show.hl adultHiddenFor is the page's own local copy, see there): an ADULT title (TMDB's flag `adult == true`, mission 054) is for the users who follow it — everyone else gets
  78. // "not found" (pages) or "no such show" (faces). Unknown (`null`) is not hidden here, only in the lists.
  79. static adultHiddenForUser = (&show, &uid) => { return show.adult == true && !(uid != null && isFollowing(uid, show.id)) }

Branches

Latest commits

  • 9d686bb3Tracker: CL1 reviewedmre
  • b8bba562CL1: crash loop report (SIGPIPE confirmed, trap wrapper option)mre
  • 298785f2Tracker: CL1 startedmre
  • 36b22710Tracker: port slot, CL1 briefmre
  • a401190fTracker: GO for the crash loopmre
  • e195d372Tracker: token pathsmre
  • 7f541d11Tracker conductor: CONDUCTOR.md, short STATUS.md, old status + decisions archive to archive/2026-10-31mre
  • 8dd423f7README: login.js stays by caramboleyo's explicit rulemre
  • d8df1493tracker: standby service on port 45018 and a gap-free hand-over in deploy.sh step 4mre
  • 36dd1686ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • ff9b838etracker: the Ended status pill uses the same red as layouts (pill danger); gate updatedmre
  • 40d9719eTP2: LOG line and report for the tracker pillsmre
  • ab3f2ba5tracker: status, genres, TMDB/IMDb/TVDB/TVmaze links and list kinds use the theme's pill; dense season list with the season check centred on its title line; gates for bothmre
  • 521061d6tracker header on phones: signed in, the brand fits whole at 360 and 390 px (tighter gaps and side paddings, slightly smaller brand, narrow screens and signed in only); mobile gate checks itmre
  • 18114a53tracker: franchises gate waits for the signed-out selector instead of the removed Log in buttonmre
  • 08561d73ident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
  • 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
  • 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
  • 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre