fedipod-bb 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fedipod-bb",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "FediPod-BB: a forum website whose record lives on a Solid pod.",
5
5
  "license": "MIT",
6
6
  "author": "Jeff Zucker",
package/site/bb.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // https://bb.<site>/<handle>/ the same forum at its own address
11
11
  // #/ #/c/<slug> #/t/<slug>/<tid>
12
12
 
13
- import { reader, placeOf, authorLabel, cacheKey, categoryBase, cleanHtml } from './read.mjs';
13
+ import { reader, placeOf, authorLabel, cacheKey, categoryBase, cleanHtml, sentNotListed } from './read.mjs';
14
14
  import { MastoLogin, hostOfHandle, serverKind, actorOfHandle, returnAddress } from './masto.mjs';
15
15
  import * as pod from './pod.mjs';
16
16
  import { mine as keptByReader } from './mine.mjs';
@@ -467,6 +467,15 @@ async function showSettings() {
467
467
  let index = null;
468
468
  const INDEX_STALE_MS = 60_000;
469
469
  function forgetIndex() { index = null; authors.clear(); }
470
+ // A post just sent from here is listed once its server has delivered it to
471
+ // the forum. Until then the index is read again every few seconds, for half a
472
+ // minute, instead of being kept for a minute without it.
473
+ const SENT_EVERY_MS = 5_000;
474
+ const SENT_WAIT_MS = 30_000;
475
+ let sent = null; // { id, until }
476
+ const waitingOnSent = (idx) => sentNotListed(sent, idx?.latest);
477
+ const indexHolds = (idx, want) => !!idx && idx.limit >= want
478
+ && Date.now() - idx.at < (waitingOnSent(idx) ? SENT_EVERY_MS : INDEX_STALE_MS);
470
479
 
471
480
  // Who wrote it, and the digest a topic link carries. Both are asked once per
472
481
  // ROW, and the same people and the same posts come round again every time the
@@ -486,7 +495,7 @@ function digestOnce(id) {
486
495
  }
487
496
 
488
497
  async function readIndex(want) {
489
- if (index && index.limit >= want && Date.now() - index.at < INDEX_STALE_MS) return index;
498
+ if (indexHolds(index, want)) return index;
490
499
  const latest = await read.latest(base, { limit: want });
491
500
  const site = new Set(await read.featured(base));
492
501
  const pinned = new Map();
@@ -543,14 +552,15 @@ async function showForum() {
543
552
  // Only say "Loading" when something is actually going to be waited for. The
544
553
  // reader changing category has everything already; blanking the page for
545
554
  // them was the whole of the delay they could see.
546
- const willFetch = !(index && index.limit >= want && Date.now() - index.at < INDEX_STALE_MS);
547
- if (willFetch) {
555
+ const willFetch = !indexHolds(index, want);
556
+ if (willFetch && !waitingOnSent(index)) {
548
557
  $('mods-acts').innerHTML = acts();
549
558
  $('main').innerHTML = head() + '<p class="dim">Loading…</p>';
550
559
  say('Loading the latest posts');
551
560
  }
552
561
  const idx = await readIndex(want);
553
562
  if (mineView !== view) return;
563
+ if (waitingOnSent(idx)) setTimeout(() => { if (mineView === view) showForum(); }, SENT_EVERY_MS);
554
564
  showMods(idx);
555
565
  const latest = idx.latest;
556
566
  const looking = finding.trim().toLowerCase();
@@ -1589,6 +1599,7 @@ $('reply-send').addEventListener('click', async () => {
1589
1599
  $('reply-text').value = '';
1590
1600
  $('topic-title').value = '';
1591
1601
  $('reply-dlg').close();
1602
+ if (!editing && (made?.uri || made?.url)) sent = { id: made.uri || made.url, until: Date.now() + SENT_WAIT_MS };
1592
1603
  forgetIndex();
1593
1604
  freshRead = true;
1594
1605
  try { await route(); } finally { freshRead = false; }
package/site/read.mjs CHANGED
@@ -10,6 +10,12 @@ const MAX_PAGES = 50;
10
10
 
11
11
  export const categoryBase = (actorId) => String(actorId).replace(/ap\/actor$/u, '');
12
12
 
13
+ // A post this page just sent, not yet in what the forum lists: its server
14
+ // delivers it to the forum seconds after the page sent it.
15
+ export function sentNotListed(sent, latest, now = Date.now()) {
16
+ return !!sent?.id && now < sent.until && !(latest || []).some(p => p.id === sent.id);
17
+ }
18
+
13
19
  // A post's text, one copy: a server that sends it once per language hands
14
20
  // over a list, read as its first.
15
21
  export function textOf(v) {