clavarium 0.2.255-beta.1 → 0.2.256-beta.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.255-beta.1",
3
+ "version": "0.2.256-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.255-beta.1",
9
+ "version": "0.2.256-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -14,7 +14,7 @@
14
14
  "clavarium-binder": "0.1.66-next.1",
15
15
  "clavarium-docket": "0.1.2-next.3",
16
16
  "clavarium-parley": "0.17.103-next.1",
17
- "clavarium-tether": "0.1.0-next.79",
17
+ "clavarium-tether": "0.1.0-next.80",
18
18
  "mammoth": "1.13.0",
19
19
  "mermaid": "11.17.2",
20
20
  "node-pty": "^1.1.0",
@@ -800,9 +800,9 @@
800
800
  }
801
801
  },
802
802
  "node_modules/clavarium-tether": {
803
- "version": "0.1.0-next.79",
804
- "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.79.tgz",
805
- "integrity": "sha512-oRbJn6olIySm1RbQLwuBK0tMklv5VIqOCYovRAdzg01BBrn9HyoDALIyOrj9VtNS1I6RsIAoI4GRU3yozNtLWw==",
803
+ "version": "0.1.0-next.80",
804
+ "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.80.tgz",
805
+ "integrity": "sha512-JwUJXoval/T8qETbvuJavf3g+wA5yE6J/SJRKfCOsg7NeKP0ykcmXAi9OSWTChOptC+OM9ctsWWbzQ2vTK4guQ==",
806
806
  "license": "MIT",
807
807
  "bin": {
808
808
  "tether": "bin/cli.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.255-beta.1",
3
+ "version": "0.2.256-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -48,7 +48,7 @@
48
48
  "clavarium-binder": "0.1.66-next.1",
49
49
  "clavarium-docket": "0.1.2-next.3",
50
50
  "clavarium-parley": "0.17.103-next.1",
51
- "clavarium-tether": "0.1.0-next.79",
51
+ "clavarium-tether": "0.1.0-next.80",
52
52
  "mammoth": "1.13.0",
53
53
  "mermaid": "11.17.2",
54
54
  "node-pty": "^1.1.0",
package/server/agenda.mjs CHANGED
@@ -119,7 +119,7 @@ export function eventsOfText(text) {
119
119
 
120
120
  /* THE AGENDA OF A CALENDAR TARGET, read now. `tethers`: Tethers (tethers.mjs). `who`: { id, name }, said in
121
121
  Tether's journal. `wait`: how long the calendar is waited for. */
122
- export async function readAgenda(tethers, { target, from, to } = {}, { who, zone = ZONE, now = Date.now(), wait = READ_MS } = {}) {
122
+ export async function readAgenda(tethers, { target, from, to, calendar } = {}, { who, zone = ZONE, now = Date.now(), wait = READ_MS } = {}) {
123
123
  if (!tethers) throw refused(503, 'unreachable', 'Calendars are not reached from this server.');
124
124
  const t = tethers.store().target(String(target ?? ''));
125
125
  if (!t || t.kind !== 'calendar') throw refused(404, 'gone', 'No such calendar.');
@@ -127,7 +127,9 @@ export async function readAgenda(tethers, { target, from, to } = {}, { who, zone
127
127
  let timer;
128
128
  const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), wait); timer.unref?.(); });
129
129
  let got;
130
- try { got = await Promise.race([tethers.read('calendar.list', { target: t.id, from: startOf(w.from, zone), to: startOf(w.to, zone) }, who), late]); }
130
+ /* Another calendar of the account (one shared with it, 29-11): its id from listCalendars; the main one by default. */
131
+ const cal = typeof calendar === 'string' && calendar.trim() ? calendar.trim().slice(0, 1024) : undefined;
132
+ try { got = await Promise.race([tethers.read('calendar.list', { target: t.id, from: startOf(w.from, zone), to: startOf(w.to, zone), ...(cal ? { calendar: cal } : {}) }, who), late]); }
131
133
  finally { clearTimeout(timer); }
132
134
  if (got === null) throw refused(504, 'late', `${t.title} did not answer in time. Try again.`);
133
135
  if (!got?.ok) throw refused(502, 'unreachable', `${t.title} could not be read: ${line(got?.text, 300) || 'no answer'}.`);
@@ -136,5 +138,25 @@ export async function readAgenda(tethers, { target, from, to } = {}, { who, zone
136
138
  const all = (given ? got.data.events.map(eventOf).filter(Boolean) : eventsOfText(got.text))
137
139
  .sort((a, b) => a.start.localeCompare(b.start));
138
140
  const more = all.length > EVENTS_MAX || got.data?.more === true || /\(Showing the first \d+ events/.test(String(got.text ?? ''));
139
- return { target: t.id, title: t.title, zone, from: w.from, to: w.to, events: all.slice(0, EVENTS_MAX), more, partial: !given };
141
+ return { target: t.id, title: t.title, zone, from: w.from, to: w.to, events: all.slice(0, EVENTS_MAX), more, partial: !given, ...(cal ? { calendar: cal } : {}) };
142
+ }
143
+
144
+ /* THE CALENDARS OF A CALENDAR TARGET'S ACCOUNT (29-11): its main one and those shared with it -- { calendars: [{ id,
145
+ name, main, owner?, write? }] }. A Tether too old to say (no calendar-calendars) answers none: the agenda keeps its
146
+ one calendar, nothing said. */
147
+ export async function listCalendars(tethers, { target } = {}, { who, wait = READ_MS } = {}) {
148
+ if (!tethers) throw refused(503, 'unreachable', 'Calendars are not reached from this server.');
149
+ const t = tethers.store().target(String(target ?? ''));
150
+ if (!t || t.kind !== 'calendar') throw refused(404, 'gone', 'No such calendar.');
151
+ let timer;
152
+ const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), wait); timer.unref?.(); });
153
+ let got;
154
+ try { got = await Promise.race([tethers.read('calendar.calendars', { target: t.id }, who), late]); }
155
+ catch { got = null; }
156
+ finally { clearTimeout(timer); }
157
+ got = got?.ok ? handed(got) : null;
158
+ const list = Array.isArray(got?.data?.calendars) ? got.data.calendars : [];
159
+ const calendars = list.filter((c) => c && typeof c.id === 'string' && c.id).slice(0, 100)
160
+ .map((c) => ({ id: c.id.slice(0, 1024), name: line(c.name, 120) || c.id.slice(0, 120), main: c.main === true, ...(c.owner ? { owner: line(c.owner, 200) } : {}), ...(c.busyOnly ? { busyOnly: true } : {}) }));
161
+ return { target: t.id, calendars };
140
162
  }
package/server/api.mjs CHANGED
@@ -202,7 +202,7 @@ import { readRights, typeOf, nameOf } from './grants.mjs';
202
202
  import { VmUnknown } from './vm.mjs';
203
203
  import { list, download, importFile, page, PAGE_HEADERS, changeRoute, IMAGE_HEADERS, mailFile, mailPage } from './files.mjs';
204
204
  import { mailRoute } from './mailref.mjs';
205
- import { readAgenda } from './agenda.mjs';
205
+ import { readAgenda, listCalendars } from './agenda.mjs';
206
206
  import { consoleJournal } from './sshconsole.mjs';
207
207
  import { readMailList, readMail } from './mailview.mjs';
208
208
  import { readContacts, readContact } from './contactview.mjs';
@@ -814,6 +814,8 @@ export async function handleApi(request, response, conversations, headers, resou
814
814
  /* A calendar's agenda, read now through Tether as the owner's own read (agenda.mjs, 16-11): seen in its asset
815
815
  panel, so the calendar need not stay open elsewhere. A POST, for this site's own pages only (checked above). */
816
816
  if (pathname === '/api/tether/agenda' && tethers) return send(200, await readAgenda(tethers, body ?? {}, { who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' } })), true;
817
+ /* The calendars of its account, to choose which one the agenda shows (29-11). */
818
+ if (pathname === '/api/tether/calendars' && tethers) return send(200, await listCalendars(tethers, body ?? {}, { who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' } })), true;
817
819
  /* A mailbox's latest messages and one as text, an address book's contacts and one, read the same way (16-11:
818
820
  mailview.mjs, contactview.mjs): never marked read, nothing changed. */
819
821
  const peek = { '/api/tether/mail-list': readMailList, '/api/tether/mail-read': readMail, '/api/tether/contacts': readContacts, '/api/tether/contact': readContact }[pathname];
@@ -337,7 +337,7 @@ export const SETTINGS_WORDS_FR = {
337
337
  'set-ag-guests': 'Invités', 'set-ag-notes': 'Invitation', 'set-ag-shown': 'Affiché comme', 'set-ag-show-free': 'Libre', 'set-ag-show-tentative': 'Provisoire',
338
338
  'set-ag-show-away': 'Absent', 'set-ag-show-elsewhere': 'Ailleurs',
339
339
  /* A mailbox's mail, an address book's contacts, in their asset panel (mailview.mjs, contactview.mjs, 16-11). */
340
- 'set-mv-title': 'Courrier', 'set-mv-search': 'Chercher un message', 'set-mv-folder': 'Dossier', 'set-mv-again': 'Relire',
340
+ 'set-mv-title': 'Courrier', 'set-mv-search': 'Chercher un message', 'set-mv-folder': 'Dossier', 'set-ag-cal': 'Agenda', 'set-ag-cal-main': 'principal', 'set-mv-again': 'Relire',
341
341
  'set-mv-failed': 'Boîte illisible pour le moment.', 'set-mv-failed-one': 'Message illisible pour le moment.',
342
342
  'set-mv-none': 'Aucun message', 'set-mv-nothing': 'Rien trouvé', 'set-mv-more': 'Les plus récents seulement',
343
343
  'set-mv-partial': 'Sans non lu ni pièces jointes, pour l\'instant', 'set-mv-unread': 'Non lu', 'set-mv-has-files': 'Pièces jointes',
package/web/app.js CHANGED
@@ -6442,11 +6442,14 @@
6442
6442
  };
6443
6443
  const dayWords = (day) => new Date(`${day}T12:00:00Z`).toLocaleDateString([], { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' });
6444
6444
  const hourOf = (time) => (time && time.length > 10 ? time.slice(11, 16) : '');
6445
+ /* WHICH CALENDAR OF THE ACCOUNT (29-11): target -> a calendar id (its own or one shared with it); none: the main one. */
6446
+ const agendaCal = new Map();
6445
6447
  async function agendaRead(target, from, { fresh = false } = {}) {
6446
- const key = `${target}|${from}`;
6448
+ const calendar = agendaCal.get(target) ?? '';
6449
+ const key = `${target}|${calendar}|${from}`;
6447
6450
  const kept = agendaKept.get(key);
6448
6451
  if (kept && !fresh && (kept.pending || Date.now() - kept.at < AGENDA_KEEP_MS)) return kept.pending ?? kept.answer;
6449
- const pending = post(`${API}/tether/agenda`, { target, from, to: dayAdd(from, AGENDA_DAYS) })
6452
+ const pending = post(`${API}/tether/agenda`, { target, from, to: dayAdd(from, AGENDA_DAYS), ...(calendar ? { calendar } : {}) })
6450
6453
  .then((answer) => { agendaKept.set(key, { at: Date.now(), answer }); return answer; })
6451
6454
  .catch((error) => { agendaKept.delete(key); return { error: error.message || uiSaid('set-ag-failed', 'The calendar could not be read.') }; });
6452
6455
  agendaKept.set(key, { at: Date.now(), pending });
@@ -6860,7 +6863,19 @@
6860
6863
  /* Today: back to this week; already there, read again. */
6861
6864
  const today = btn(uiSaid('set-ag-today', 'Today'), uiSaid('set-ag-today', 'Today'), () => { const was = agendaFrom.has(target.id); agendaFrom.delete(target.id); void agendaFill(holder, target.id, { fresh: !was }); });
6862
6865
  const next = btn('›', uiSaid('set-ag-next', 'Next week'), () => move(7));
6863
- const bar = el('div', 'ag-bar'); bar.append(prev, today, next);
6866
+ /* Which calendar: shown when the account has more than one (its own and those shared with it), as a mailbox's folder. */
6867
+ const pick = el('select', 'mv-folder ag-cal'); pick.hidden = true; pick.setAttribute('aria-label', uiSaid('set-ag-cal', 'Calendar'));
6868
+ pick.addEventListener('change', () => { if (pick.value) agendaCal.set(target.id, pick.value); else agendaCal.delete(target.id); void agendaFill(holder, target.id); });
6869
+ void peekRead(`calendars|${target.id}`, 'calendars', { target: target.id }, '').then((got) => {
6870
+ const cals = got?.calendars ?? [];
6871
+ if (cals.length < 2 || !pick.isConnected) return;
6872
+ for (const c of cals) {
6873
+ const o = el('option', '', c.main ? `${c.name} (${uiSaid('set-ag-cal-main', 'main')})` : `${c.name}${c.owner && c.owner !== 'you' ? ` · ${c.owner}` : ''}`);
6874
+ o.value = c.main ? '' : c.id; pick.append(o);
6875
+ }
6876
+ pick.value = agendaCal.get(target.id) ?? ''; pick.hidden = false;
6877
+ });
6878
+ const bar = el('div', 'ag-bar'); bar.append(pick, prev, today, next);
6864
6879
  queueMicrotask(() => { void agendaFill(holder, target.id); });
6865
6880
  return { title: uiSaid('set-ag-title', 'Agenda'), extra: [bar], body: [holder], cls: 'as-agenda-part' };
6866
6881
  }