diff --git a/docs/commons-files-desk.md b/docs/commons-files-desk.md index fa7242d2..d9152065 100644 --- a/docs/commons-files-desk.md +++ b/docs/commons-files-desk.md @@ -118,9 +118,9 @@ Under A the paused service is not built, and most of its list disappears: ## Cuts under A -Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. **Not built: the Commons entry row** (item 1 below, found by `#commons:gamecult.org` or the carried `media.commons` id through `lookupMediaRoom`, behind a dark `filesDesk.enabled` flag; neither the row nor the flag exists in the code). It waits on Eureka's Commons room. +Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. The Commons entry row is built (item 1): `useCommons` in `MediaRow.tsx` finds the room by the alias `#commons:` (provisioning records no id for it), through `lookupZoneRoom` (the one lookup `lookupMediaRoom` also uses); `EstateNavigator` shows it above the tiers as a Commons link when joined, a join row when invited or not joined, and nothing when the room is absent, the lookup failed or is out. It is gated on the existing `fileZoneShare.enabled`, not a new `filesDesk.enabled` flag. The album view and ShareSet work there because provisioning creates the Commons with the `org.gamecult.file_zone` create type. Members can share only once the room's power levels let them post: provisioning gives the poster level to the Minds alone. -1. **Commons entry**: a Commons row in the navigator (like `MediaRow`, found by alias or carried id), opening the room's album view. Flagged, no new data layer. +1. **Commons entry**: a Commons row in the navigator (like `MediaRow`, found by alias), opening the room's album view. Flagged, no new data layer. 2. **Pagination** of albums and files in `useAlbums` (done, PR #148). 3. **Folders by title path** and the album list grouped by it. 4. **Versions**: read `org.gamecult.publish.replaces`, show the latest of a chain with the earlier versions folded under it (done, PR #149). diff --git a/src/app/features/estate/EstateNavigator.tsx b/src/app/features/estate/EstateNavigator.tsx index b560e08c..746b45b9 100644 --- a/src/app/features/estate/EstateNavigator.tsx +++ b/src/app/features/estate/EstateNavigator.tsx @@ -37,7 +37,7 @@ import { searchModalAtom } from '../../state/searchModal'; import { getCanonicalAliasOrRoomId } from '../../utils/matrix'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { MINDS } from '../../components/message/pose/poses'; -import { MediaLink, MediaNote, useMindMedia } from './MediaRow'; +import { MediaLink, MediaNote, useCommons, useMindMedia } from './MediaRow'; import { MediaRow as MediaRowState } from './mediaRoom'; import { useSelectedRoom } from '../../hooks/router/useSelectedRoom'; import { useCallEmbed } from '../../hooks/useCallEmbed'; @@ -194,6 +194,15 @@ function MindMedia({ media }: { media: MediaRowState }) { return ; } +/** The shared Commons room above the tiers: a link when joined, a join row otherwise, nothing when there is none. */ +function CommonsEntry() { + const mx = useMatrixClient(); + const room = useCommons(); + if (!room) return null; + if (room.state === 'joined') return ; + return ; +} + function GroupSection({ tierId, group }: { tierId: string; group: EstateGroup }) { const media = useMindMedia(group.mind, group.rooms); const hasMedia = MINDS.includes(group.mind); @@ -345,6 +354,7 @@ function EstateTiers({ rootId }: { rootId: string }) { return ( <> + {tiers.map((tier) => ( ))} diff --git a/src/app/features/estate/MediaRow.test.tsx b/src/app/features/estate/MediaRow.test.tsx index 6b590158..88f7e89e 100644 --- a/src/app/features/estate/MediaRow.test.tsx +++ b/src/app/features/estate/MediaRow.test.tsx @@ -26,4 +26,14 @@ describe('Media row', () => { expect(text(html)).toBe('Media'); expect(html).toContain('href="/home/%23void-files%3Agamecult.org/"'); }); + + it('the Commons link reads "Commons" and opens the room', () => { + const html = renderToStaticMarkup( + + + + ); + expect(text(html)).toBe('Commons'); + expect(html).toContain('href="/home/%23commons%3Agamecult.org/"'); + }); }); diff --git a/src/app/features/estate/MediaRow.tsx b/src/app/features/estate/MediaRow.tsx index 6277f09c..7d64497a 100644 --- a/src/app/features/estate/MediaRow.tsx +++ b/src/app/features/estate/MediaRow.tsx @@ -15,7 +15,10 @@ import { useEstateRootId } from './useEstate'; import { STEWARDSHIPS_KEY, MediaRow as MediaRowState, + commonsAlias, + commonsRow, lookupMediaRoom, + lookupZoneRoom, mediaRoomIdFromStewardships, mediaRow, typedMediaRoom, @@ -44,7 +47,7 @@ export function MediaNote({ note, title }: { note: string; title?: string }) { } /** The joined Media row: opens the room, which shows its album view. */ -export function MediaLink({ to }: { to: string }) { +export function MediaLink({ to, label = 'Media' }: { to: string; label?: string }) { return ( @@ -52,7 +55,7 @@ export function MediaLink({ to }: { to: string }) { {mediaIcon} - Media + {label} @@ -105,3 +108,23 @@ export const useMindMedia = (mind: string, rooms: readonly EstateRoom[]): MediaR if (typed) return { kind: 'room', room: { ...typed, name: 'Media' } }; return mediaRow(lookup.data, membership); }; + +/** The shared Commons room as the navigator sees it right now: undefined means no row. Dark unless fileZoneShare.enabled. */ +export const useCommons = (): EstateRoom | undefined => { + const mx = useMatrixClient(); + const joined = useAtomValue(allRoomsAtom); + const invited = useAtomValue(allInvitesAtom); + const enabled = !!useClientConfig().fileZoneShare?.enabled; + const server = mx.getDomain() ?? ''; + // Provisioning records no id for the Commons (only per-Mind zones under @rooms.file_zones): the alias is the one way in. + const lookup = useQuery({ + queryKey: ['commons-room', server], + queryFn: () => lookupZoneRoom(mx, commonsAlias(server), server), + staleTime: 60_000, + enabled, + }); + const membership = new Map(); + invited.forEach((id) => membership.set(id, 'invite')); + joined.forEach((id) => membership.set(id, 'join')); + return commonsRow(enabled, lookup.data, membership); +}; diff --git a/src/app/features/estate/mediaRoom.test.ts b/src/app/features/estate/mediaRoom.test.ts index 934caaae..45e912e0 100644 --- a/src/app/features/estate/mediaRoom.test.ts +++ b/src/app/features/estate/mediaRoom.test.ts @@ -1,9 +1,13 @@ import { describe, expect, it } from 'vitest'; import { + commonsAlias, + commonsRow, lookupMediaRoom, + lookupZoneRoom, mediaAlias, mediaRoomIdFromStewardships, mediaRow, + MediaLookup, typedMediaRoom, } from './mediaRoom'; @@ -132,3 +136,51 @@ describe('the Media row of a Mind', () => { expect(typedMediaRoom(rooms, () => false)).toBeUndefined(); }); }); + +describe('the Commons row', () => { + const none = new Map(); + + it('is found by the alias #commons:', async () => { + const { mx, asked } = clientFor(async () => ({ room_id: '!c:gamecult.org' })); + const lookup = await lookupZoneRoom(mx, commonsAlias('gamecult.org'), 'gamecult.org'); + expect(asked).toEqual(['#commons:gamecult.org']); + expect(commonsRow(true, lookup, new Map([['!c:gamecult.org', 'join']]))).toMatchObject({ + roomId: '!c:gamecult.org', + name: 'Commons', + state: 'joined', + }); + }); + + it('shows no row when the room is absent, the lookup failed or is still out', async () => { + const missing = await lookupZoneRoom( + clientFor(async () => { + throw notFound; + }).mx, + commonsAlias('gamecult.org'), + 'gamecult.org' + ); + const failed = await lookupZoneRoom( + clientFor(async () => { + throw new Error('down'); + }).mx, + commonsAlias('gamecult.org'), + 'gamecult.org' + ); + expect(commonsRow(true, missing, none)).toBeUndefined(); + expect(commonsRow(true, failed, none)).toBeUndefined(); + expect(commonsRow(true, undefined, none)).toBeUndefined(); + }); + + it('shows no row with the flag off, even for a found room', () => { + const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] }; + expect(commonsRow(false, found, new Map([['!c:gamecult.org', 'join']]))).toBeUndefined(); + }); + + it('offers a join to a viewer who has not joined, and an accept to an invited one', () => { + const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] }; + expect(commonsRow(true, found, none)?.state).toBe('joinable'); + expect(commonsRow(true, found, new Map([['!c:gamecult.org', 'invite']]))?.state).toBe( + 'invited' + ); + }); +}); diff --git a/src/app/features/estate/mediaRoom.ts b/src/app/features/estate/mediaRoom.ts index 5d1503b6..2e60fe3a 100644 --- a/src/app/features/estate/mediaRoom.ts +++ b/src/app/features/estate/mediaRoom.ts @@ -13,6 +13,9 @@ export const ROOMS_KEY = '@rooms'; export const mediaAlias = (mind: string, server: string): string => `#${mind}-files:${server}`; +/** The shared Commons room's alias (gamecult-ops synapse-accounts-hand-managed.py COMMONS_ALIAS). */ +export const commonsAlias = (server: string): string => `#commons:${server}`; + /** * The room id the stewardships state names for a Mind's media room, under `@rooms.file_zones[]`. * The state's mind-to-repos lists are not read here. @@ -46,16 +49,16 @@ export type MediaLookup = | { found: true; roomId: string; via: string[] } | { found: false; reason: 'unset' | 'error'; message?: string }; -/** Resolve a Mind's media room: a carried id if there is one, else the alias. A 404 means it is not set up. */ -export const lookupMediaRoom = async ( +/** Resolve a file-zone room (a Mind's media room, or Commons): a carried id if there is one, else the alias. A 404 means it is not set up. */ +export const lookupZoneRoom = async ( mx: MediaClient, - mind: string, + alias: string, server: string, carriedId?: string ): Promise => { if (carriedId) return { found: true, roomId: carriedId, via: [server] }; try { - const r = await mx.getRoomIdForAlias(mediaAlias(mind, server)); + const r = await mx.getRoomIdForAlias(alias); return { found: true, roomId: r.room_id, via: r.servers?.length ? r.servers : [server] }; } catch (e) { const err = e as { @@ -75,6 +78,14 @@ export const lookupMediaRoom = async ( } }; +/** Resolve a Mind's media room. */ +export const lookupMediaRoom = ( + mx: MediaClient, + mind: string, + server: string, + carriedId?: string +): Promise => lookupZoneRoom(mx, mediaAlias(mind, server), server, carriedId); + export type MediaRow = | { kind: 'checking' } | { kind: 'unset' } @@ -86,7 +97,8 @@ const MEMBERSHIP_STATE = { join: 'joined', invite: 'invited', none: 'joinable' } /** What the Media row shows: the lookup result joined to the user's own membership. */ export const mediaRow = ( lookup: MediaLookup | undefined, - membership: ReadonlyMap + membership: ReadonlyMap, + name = 'Media' ): MediaRow => { if (!lookup) return { kind: 'checking' }; if (!lookup.found) { @@ -99,7 +111,7 @@ export const mediaRow = ( kind: 'room', room: { roomId: lookup.roomId, - name: 'Media', + name, state: MEMBERSHIP_STATE[m ?? 'none'], via: lookup.via, parentId: null, @@ -107,3 +119,18 @@ export const mediaRow = ( }, }; }; + +/** + * The Commons row: the shared room, or nothing. Off with the share flag; not set up, still looking and a failed lookup + * show no row (the room is shared furniture, not a per-Mind promise like Media). A found room is joined, invited or + * joinable, as for Media. + */ +export const commonsRow = ( + enabled: boolean, + lookup: MediaLookup | undefined, + membership: ReadonlyMap +): EstateRoom | undefined => { + if (!enabled) return undefined; + const row = mediaRow(lookup, membership, 'Commons'); + return row.kind === 'room' ? row.room : undefined; +};