Files
webmail/lib/jmap/principal-cache.ts
lucletoffeandClaude Opus 5.5 8cf6783cdb feat(calendar): say whom a calendar is shared with
The sidebar showed the same people icon for any calendar with a share,
labelled "Share calendar", and the settings badge only gave a count, so
there was no way to tell from either who could see the calendar. A share
granted to a service account read like a share with other people.

Both now carry a hint listing the recipients ("Shared with
bot@example.com (Booking robot)"), resolved from the principals the
server lists. Until every recipient is known the hint falls back to the
count. Principals are fetched only when a calendar on screen is shared.

The per-client principal cache of the attendee availability check moves
to lib/jmap/principal-cache.ts so both use it. It no longer keeps an
empty or failed answer: the next caller asks again instead of seeing
no principals for the rest of the session.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-15 22:19:53 +02:00

26 lines
914 B
TypeScript

import type { IJMAPClient } from '@/lib/jmap/client-interface';
import type { Principal } from '@/lib/jmap/types';
const principalCache = new WeakMap<IJMAPClient, Promise<Principal[]>>();
/**
* The principals the server lists, fetched once per client: they rarely change
* during a session, and the directory can take several requests to page
* through. An empty answer (failed fetch, client not signed in yet) is not
* kept, so the next caller asks again.
*/
export function cachedPrincipals(client: IJMAPClient): Promise<Principal[]> {
let cached = principalCache.get(client);
if (!cached) {
cached = Promise.resolve()
.then(() => client.getPrincipals())
.catch(() => [] as Principal[])
.then((principals) => {
if (principals.length === 0) principalCache.delete(client);
return principals;
});
principalCache.set(client, cached);
}
return cached;
}